1library(pystr) 2context("pystr_translate") 3 4test_that("it translates numbers", { 5 map = pystr_maketrans("123", "abc") 6 expect_equal(pystr_translate("1 2 3 456", map), "a b c 456") 7}) 8 9test_that("it translates chars", { 10 map = pystr_maketrans("abc", "123") 11 expect_equal(pystr_translate("abc456", map), "123456") 12}) 13 14test_that("different things can be mapped to the same char", { 15 map = pystr_maketrans("abcd", "rrrr") 16 expect_equal(pystr_translate("abcdefg", map), "rrrrefg") 17}) 18 19test_that("it works with a character vector", { 20 map = pystr_maketrans("abc", "123") 21 expect_equal(pystr_translate(c("abc456", "abcdefg"), map), c("123456", "123defg")) 22}) 23