Skip to content

Commit

Permalink
Ensure we can parse empty input (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley authored Jul 15, 2024
1 parent 23f6656 commit 99102f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/parse_all.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ parse_all.character <- function(x, filename = NULL, allow_error = FALSE) {
res <- res[order(res$line), c("src", "expr")]

# Restore newlines stripped while converting to vector of lines
res$src <- paste0(res$src, "\n")
if (length(res$src)) {
res$src <- paste0(res$src, "\n")
} else {
res$src <- character()
}

res$expr <- lapply(res$expr, removeSource)

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-parse_all.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
test_that("can parse empty input", {
expect_equal(parse_all(character())$src, character())
})

test_that("can parse even if no expressions", {
expect_equal(parse_all("")$src, "\n")
expect_equal(parse_all("#")$src, "#\n")
Expand Down

0 comments on commit 99102f8

Please sign in to comment.