Debian Codegraph @

tests/testthat/test-collate.R

raw
1 test_that("with_collate works and resets collate", {
2 current <- Sys.getlocale("LC_COLLATE")
3 new <- "C"
4 with_collate(
5 new,
6 {
7 expect_equal(new, Sys.getlocale("LC_COLLATE"))
8 }
9 )
10 expect_equal(current, Sys.getlocale("LC_COLLATE"))
11 })
12
13 test_that("with_collate() and with_locale() set LC_COLLATE envvar (#179)", {
14 en_US <- en_locale_or_skip()
15
16 output <- callr::r(
17 env = c(LC_COLLATE = "C"),
18 args = list(en_US = en_US),
19 function(en_US) {
20 out <- withr::with_collate(en_US, sort(c("A", "a")))
21 stopifnot(identical(Sys.getenv("LC_COLLATE"), "C"))
22 out
23 }
24 )
25 expect_equal(output, c("a", "A"))
26
27 output <- callr::r(
28 env = c(LC_COLLATE = "C"),
29 args = list(en_US = en_US),
30 function(en_US) {
31 out <- withr::with_locale(c(LC_COLLATE = en_US), sort(c("A", "a")))
32 stopifnot(identical(Sys.getenv("LC_COLLATE"), "C"))
33 out
34 }
35 )
36 expect_equal(output, c("a", "A"))
37 })