-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/newline check #58
Conversation
Coverage Report
|
This fails on the Windows test, which I assume should be resolved before merging. |
@cjyetman Now that I'm looking at these tests again, I think the file creation is failing on Windows (depends on echo, printf, etc.) Trying some different ideas now. |
tests were failing on windows, due to a lack of POSIX utilities
@cjyetman Note that there is a (small) logical change in commit I believe this is acceptable behavior, since both unix-ish and Windows end their line endings in |
last test run failed on macOS |
Co-authored-by: CJ Yetman <cyetman@rmi.org>
Since you're making big changes to writeChar("A,B\n1,2", "no_newline.txt", eos = NULL)
writeChar("A,B\n1,2\n", "newline.txt", eos = NULL)
writeChar("A,B\r1,2\r", "return.txt", eos = NULL)
writeChar("A,B\r\n1,2\r\n", "return_newline.txt", eos = NULL)
readChar("no_newline.txt", 10)
#> [1] "A,B\n1,2"
readChar("newline.txt", 10)
#> [1] "A,B\n1,2\n"
readChar("return.txt", 10)
#> [1] "A,B\r1,2\r"
readChar("return_newline.txt", 10)
#> [1] "A,B\r\n1,2\r\n"
readBin("no_newline.txt", what = "raw", n = 10)
#> [1] 41 2c 42 0a 31 2c 32
readBin("newline.txt", what = "raw", n = 10)
#> [1] 41 2c 42 0a 31 2c 32 0a
readBin("return.txt", what = "raw", n = 10)
#> [1] 41 2c 42 0d 31 2c 32 0d
readBin("return_newline.txt", what = "raw", n = 10)
#> [1] 41 2c 42 0d 0a 31 2c 32 0d 0a
pacta.portfolio.import:::has_newline_at_end("no_newline.txt")
#> [1] FALSE
pacta.portfolio.import:::has_newline_at_end("newline.txt")
#> [1] TRUE
pacta.portfolio.import:::has_newline_at_end("return.txt")
#> [1] TRUE
pacta.portfolio.import:::has_newline_at_end("return_newline.txt")
#> [1] TRUE using that strategy, you can easily build tests like... test_that("has_newline_at_end identifies no trailing newline or return", {
no_newline <- withr::local_tempfile()
writeChar("A,B\n1,2", no_newline, eos = NULL)
expect_true(tail(readBin(no_newline, what = "raw", n = 10), n = 1) == charToRaw("2"))
expect_false(has_newline_at_end(no_newline))
})
#> Test passed 🎉
test_that("has_newline_at_end identifies trailing newline", {
newline <- withr::local_tempfile()
writeChar("A,B\n1,2\n", newline, eos = NULL)
expect_true(tail(readBin(newline, what = "raw", n = 10), n = 1) == charToRaw("\n"))
expect_true(has_newline_at_end(newline))
})
#> Test passed 🥇 |
move tests to the has_newline_at_end file, and remove redundant tests.
change a conditional that had been pinned to FALSE to check for unix platforms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
reflows checking for newline at end of file.
On unix-ish (Linux + MacOS), uses
tail -c1
to grab the last byte of the file, and thenwc -l
to count newlines in that string (of 1 byte).Maintains previous (pure R) logic for windows systems.