Skip to content

Commit

Permalink
Skip encoding conversion fallback tests on newer macOS
Browse files Browse the repository at this point in the history
Where

```
iconv("幸福", from = "UTF-8", to = "ISO8859-1", sub = "Unicode")
```

returns "??" instead of "<U+5E78><U+798F>"
  • Loading branch information
lionel- committed Oct 26, 2023
1 parent 7625d1e commit e22849a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/testthat/helper-locale.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,20 @@ encodings <- function(bytes = FALSE) {
out
}

# On some plaftorms iconv doesn't create unicode markers when encoding
# fails. Instead it transliterates to "?" characters.
skip_if_no_utf8_marker <- function() {
skip <- tryCatch(
expr = {
out <- iconv("幸福", from = "UTF-8", to = "ISO8859-1")
!is_string(out) || !grepl("<", out)
},
error = function(...) {
TRUE
}
)

if (skip) {
skip("No UTF-8 marker with this version of libiconv.")
}
}
1 change: 1 addition & 0 deletions tests/testthat/test-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test_that("type_of() returns correct type", {
})

test_that("Unicode escapes are converted to UTF8 characters in env_names()", {
skip_if_no_utf8_marker()
local_lifecycle_silence()

with_non_utf8_locale({
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-encoding.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test_that("can roundtrip symbols in non-UTF8 locale", {
skip_if_no_utf8_marker()
with_non_utf8_locale({
expect_identical(
as_string(sym(get_alien_lang_string())),
Expand All @@ -15,6 +16,7 @@ test_that("Unicode escapes are always converted to UTF8 characters on roundtrip"
})

test_that("Unicode escapes are always converted to UTF8 characters with env_names()", {
skip_if_no_utf8_marker()
with_non_utf8_locale({
env <- child_env(empty_env())
env_bind(env, !! get_alien_lang_string() := NULL)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-env-binding.R
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ test_that("env_poke() doesn't warn when unrepresentable characters are serialise

expect_no_warning(env_poke(e, nm, NA))

skip_if_no_utf8_marker()
nms <- env_names(e)
expect_equal(Encoding(nms), "UTF-8")
})
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-nse-defuse.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ test_that("can capture missing argument", {
})

test_that("serialised unicode in `:=` LHS is unserialised", {
skip_if_no_utf8_marker()
nms <- with_latin1_locale({
exprs <- exprs("\u5e78" := 10)
names(exprs)
Expand Down

0 comments on commit e22849a

Please sign in to comment.