1test_that("can detect path from RStudio project file", {
2  create_local_package()
3  use_rstudio("posix")
4  expect_equal(proj_line_ending(), "\n")
5
6  file_delete(proj_path(paste(paste0(project_name(), ".Rproj"))))
7  use_rstudio("windows")
8  expect_equal(proj_line_ending(), "\r\n")
9})
10
11test_that("can detect path from DESCRIPTION or .R file", {
12  create_local_project()
13
14  write_utf8(proj_path("DESCRIPTION"), c("x", "y", "z"), line_ending = "\r\n")
15  expect_equal(proj_line_ending(), "\r\n")
16  file_delete(proj_path("DESCRIPTION"))
17
18  dir_create(proj_path("R"))
19  write_utf8(proj_path("R/test.R"), c("x", "y", "z"), line_ending = "\r\n")
20  expect_equal(proj_line_ending(), "\r\n")
21})
22
23test_that("falls back to platform specific encoding", {
24  create_local_project()
25  expect_equal(proj_line_ending(), platform_line_ending())
26})
27
28test_that("correctly detect line encoding", {
29  path <- file_temp()
30
31  con <- file(path, open = "wb")
32  writeLines(c("a", "b", "c"), con, sep = "\n")
33  close(con)
34  expect_equal(detect_line_ending(path), "\n")
35
36  con <- file(path, open = "wb")
37  writeLines(c("a", "b", "c"), con, sep = "\r\n")
38  close(con)
39  expect_equal(detect_line_ending(path), "\r\n")
40})
41