tests/testthat/test-utils.R

test_that("encoding helpers convert strings to UTF-8", {
  a <- iconv("EspaƱa", to = "latin1")

  expect_identical(Encoding(a), "latin1")

  b <- clean_str(a)

  expect_identical(Encoding(b), "UTF-8")
})

test_that("clean_str removes empty and malformed values", {
  expect_identical(clean_str(c("a", "b")), c("a b"))

  expect_null(clean_str(NA))
  expect_null(clean_str(NULL))
  expect_null(clean_str(""))
  expect_null(clean_str(character(0)))
  expect_null(clean_str(integer(0)))
  expect_null(clean_str(logical(0)))
  expect_null(clean_str(list()))
})

test_that("repository helpers select CRAN-compatible repositories", {
  # Use some other repos
  repos <- c("https://ropensci.r-universe.dev", "https://cloud.r-project.org")

  final <- detect_repos(repos)
  expect_identical(final, c(CRAN = "https://cloud.r-project.org/"))

  # With posit package manager
  repos <- c(
    CRAN = "https://packagemanager.posit.co/cran/latest",
    RPSM = "https://packagemanager.rstudio.com/",
    ANOTHER = "https://packagemanager.rspm.com/"
  )
  final <- detect_repos(repos)
  expect_identical(final, c(CRAN = "https://cloud.r-project.org/"))
})

Try the cffr package in your browser

Any scripts or data that you put into this service are public.

cffr documentation built on Aug. 24, 2026, 5:11 p.m.