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 2, 2016
1 parent 8937f4b commit 000b831
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion R/utils.R
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
5 changes: 4 additions & 1 deletion tests/testthat/test-nonASCII.R
Expand Up @@ -8,6 +8,9 @@ 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,
# so we have to use unicode escapes.
expect_true(any(grepl("\u6211\u7231\u4e2d\u6587", cnChar)))
expect_true(any(grepl("\u4e2d\u6587\u6ce8\u91ca", cnChar)))
})

0 comments on commit 000b831

Please sign in to comment.