Debian Codegraph @

tests/testthat/test-base64.R

raw
1
2 test_that("some sample strings can be base64-encoded", {
3
4 expect_equal(renv_base64_encode("renv"), "cmVudg==")
5
6 original <- rawToChar(as.raw(1:255))
7 encoded <- renv_base64_encode(original)
8 decoded <- renv_base64_decode(encoded)
9 expect_equal(original, decoded)
10
11 })
12
13 test_that("some random base64 strings can be round-tripped", {
14
15 set.seed(123)
16 bytes <- 1:255
17
18 text <- replicate(1000, {
19 n <- sample(128L, 1L)
20 rawToChar(as.raw(sample(bytes, n, replace = TRUE)))
21 })
22
23 encoded <- lapply(text, renv_base64_encode)
24 decoded <- lapply(encoded, renv_base64_decode)
25
26 expect_true(all(text == decoded))
27
28 })