File: test-line-ending.R

package info (click to toggle)
r-cran-usethis 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,228 kB
  • sloc: sh: 26; makefile: 17; cpp: 6; ansic: 3
file content (40 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
test_that("can detect path from RStudio project file", {
  create_local_package()
  use_rstudio("posix")
  expect_equal(proj_line_ending(), "\n")

  file_delete(proj_path(paste(paste0(project_name(), ".Rproj"))))
  use_rstudio("windows")
  expect_equal(proj_line_ending(), "\r\n")
})

test_that("can detect path from DESCRIPTION or .R file", {
  create_local_project()

  write_utf8(proj_path("DESCRIPTION"), c("x", "y", "z"), line_ending = "\r\n")
  expect_equal(proj_line_ending(), "\r\n")
  file_delete(proj_path("DESCRIPTION"))

  dir_create(proj_path("R"))
  write_utf8(proj_path("R/test.R"), c("x", "y", "z"), line_ending = "\r\n")
  expect_equal(proj_line_ending(), "\r\n")
})

test_that("falls back to platform specific encoding", {
  create_local_project()
  expect_equal(proj_line_ending(), platform_line_ending())
})

test_that("correctly detect line encoding", {
  path <- file_temp()

  con <- file(path, open = "wb")
  writeLines(c("a", "b", "c"), con, sep = "\n")
  close(con)
  expect_equal(detect_line_ending(path), "\n")

  con <- file(path, open = "wb")
  writeLines(c("a", "b", "c"), con, sep = "\r\n")
  close(con)
  expect_equal(detect_line_ending(path), "\r\n")
})