| 1 |
test_that("can temporarily change language", { |
| 2 |
# Skipped on CRAN because R's translations change over time, which |
| 3 |
# breaks the exact error message matches below |
| 4 |
skip_on_cran() |
| 5 |
skip_if_not(has_nls()) |
| 6 |
|
| 7 |
# `with_language()` doesn't work when locale is set to C. At the |
| 8 |
# same time it's perilous to try and set the locale in a |
| 9 |
# cross-platform way, so just skip these tests in that case. |
| 10 |
# See https://github.com/r-lib/withr/issues/236 |
| 11 |
skip_if_c_locale() |
| 12 |
|
| 13 |
expect_error(with_language("en", mean[[1]]), "not subsettable") |
| 14 |
expect_error(with_language("fr", mean[[1]]), "non indi\u00e7able") |
| 15 |
# R-devel changed the Spanish translation from "no es subconjunto" to |
| 16 |
# "no se puede seleccionar elementos", so match either form |
| 17 |
expect_error(with_language("es", mean[[1]]), "no es subconjunto|no se puede seleccionar") |
| 18 |
|
| 19 |
# Is correctly reset (#213) |
| 20 |
expect_error(mean[[1]], "not subsettable") |
| 21 |
}) |
| 22 |
|
| 23 |
test_that("can use use either _ or -", { |
| 24 |
skip_on_cran() |
| 25 |
skip_if_not(has_nls()) |
| 26 |
skip_if_c_locale() |
| 27 |
|
| 28 |
expect_error(with_language("pt_BR", mean[[1]]), "não possível dividir") |
| 29 |
expect_error(with_language("pt-BR", mean[[1]]), "não possível dividir") |
| 30 |
}) |
| 31 |
|
| 32 |
test_that("can temporarily change language after triggering error", { |
| 33 |
skip_on_cran() |
| 34 |
skip_if_not(has_nls()) |
| 35 |
skip_if_c_locale() |
| 36 |
|
| 37 |
local_language("fr") |
| 38 |
try(mean[[1]], silent = TRUE) # trigger possible caching |
| 39 |
|
| 40 |
expect_error(with_language("es", mean[[1]]), "no es subconjunto|no se puede seleccionar") |
| 41 |
}) |
| 42 |
|
| 43 |
test_that("warns if LC_ALL=C", { |
| 44 |
skip_if_not(has_nls()) |
| 45 |
|
| 46 |
local_envvar(LC_ALL = "C") |
| 47 |
expect_warning(with_language("en", "x"), "has no effect") |
| 48 |
}) |
| 49 |
|
| 50 |
test_that("checks input", { |
| 51 |
expect_snapshot_error(with_language(1, "x")) |
| 52 |
}) |