-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Helpers read_lines and write_lines do the right thing * readLines() and writeLines() through errors to prevent accidental re-use in the future * Warn if package encoding is not utf-8 Fixes #564. Fixes #592
- Loading branch information
Showing
18 changed files
with
91 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
readLines <- function(...) stop("Use read_lines!") | ||
writeLines <- function(...) stop("Use write_lines!") | ||
|
||
read_lines <- function(path, n = -1L) { | ||
con <- file(path, open = "r", encoding = "utf-8") | ||
on.exit(close(con)) | ||
|
||
base::readLines(con, n = n, warn = FALSE) | ||
} | ||
|
||
write_lines <- function(text, path) { | ||
con <- file(path, open = "w", encoding = "utf-8") | ||
on.exit(close(con)) | ||
|
||
base::writeLines(text, con) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
context("nonASCII") | ||
|
||
test_that("can generate nonASCII document", { | ||
test_pkg <- temp_copy_pkg(test_path('testNonASCII')) | ||
on.exit(unlink(test_pkg, recursive = TRUE), add = TRUE) | ||
|
||
expect_output(roxygenise(test_pkg, roclets = "rd"), "printChineseMsg[.]Rd") | ||
|
||
rd_path <- file.path(test_pkg, "man", "printChineseMsg.Rd") | ||
expect_true(file.exists(rd_path)) | ||
rd <- read_lines(rd_path) | ||
|
||
expect_true(any(grepl("\u6211\u7231\u4e2d\u6587", rd))) | ||
expect_true(any(grepl("\u4e2d\u6587\u6ce8\u91ca", rd))) | ||
|
||
# Shouldn't change again | ||
expect_output(roxygenise(test_pkg, roclets = "rd"), NA) | ||
}) | ||
|
||
|
||
test_that("unicode escapes are ok", { | ||
test_pkg <- temp_copy_pkg(test_path('testUtf8Escape')) | ||
on.exit(unlink(test_pkg, recursive = TRUE), add = TRUE) | ||
|
||
expect_output(roxygenise(test_pkg, roclets = "rd"), "a[.]Rd") | ||
|
||
rd_path <- file.path(test_pkg, "man", "a.Rd") | ||
expect_true(file.exists(rd_path)) | ||
rd <- read_lines(rd_path) | ||
|
||
expect_true(any(grepl("7\u00b0C", rd))) | ||
|
||
# Shouldn't change again | ||
expect_output(roxygenise(test_pkg, roclets = "rd"), NA) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
# This script is intended to be saved in GB2312 to test if non UTF-8 encoding is | ||
# supported. | ||
|
||
#' 中文注释 | ||
#' 中文注释 | ||
#' | ||
#' @note 我爱中文。 | ||
#' @note 我爱中文。 | ||
printChineseMsg <- function() { | ||
message("我是GB2312的中文字符。") | ||
message("我是UTF8的中文字符。") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Package: testUtf8Escape | ||
Title: Check that utf8 escapes are round tripped ok | ||
License: GPL-2 | ||
Description: | ||
Author: Hadley <hadley@rstudio.com> | ||
Maintainer: Hadley <hadley@rstudio.com> | ||
Encoding: UTF-8 | ||
Version: 0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#' Title | ||
#' | ||
#' @param b Some label | ||
a <- function(b = '7°C') 1 |