Skip to content

Commit

Permalink
ensure write UTF-8 rd files
Browse files Browse the repository at this point in the history
  • Loading branch information
shrektan committed Dec 1, 2016
1 parent 8937f4b commit 5f66da4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ write_if_different <- function(path, contents, check = TRUE) {
FALSE
} else {
cat(sprintf('Writing %s\n', name))
writeLines(contents, path)
con <- file(path, encoding = "UTF-8")
on.exit(close(con), add = TRUE)
writeLines(contents, con)
TRUE
}
}
Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/test-nonASCII.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ test_that("can generate nonASCII document", {
expect_true(file.exists(file.path(test_pkg, "man", "printChineseMsg.Rd")))

cnChar <- readLines(file.path(test_pkg, "man", "printChineseMsg.Rd"), encoding = "UTF-8")
expect_true(any(grepl("我爱中文", cnChar)) && any(grepl("中文注释", cnChar)))

# Because the parse in testthat::test don't specify encoding to UTF-8 as well,
# we have to use `stringi::stri_escape_unicode` to avoid errors.
expect_true(
any(grepl("\u6211\u7231\u4e2d\u6587", cnChar)) &&
any(grepl(enc2utf8("\u4e2d\u6587\u6ce8\u91ca"), cnChar))
)
})

0 comments on commit 5f66da4

Please sign in to comment.