tests/testthat/test-zzz.R

test_that(".onLoad() returns null invisibly", {
    expect_null(transltr:::.onLoad(.Library, "transltr"))
    expect_invisible(transltr:::.onLoad(.Library, "transltr"))
})

test_that(".onLoad() sets options", {
    # Options are removed and restored afterwards.
    withr::local_options(transltr.path    = NULL)
    withr::local_options(transltr.verbose = NULL)
    transltr:::.onLoad(.Library, "transltr")

    expect_identical(
        getOption("transltr.path"),
        file.path("inst", "transltr", "_translator.yml"))
    expect_true(getOption("transltr.verbose"))
})

test_that(".onLoad() does not set options if they are already defined", {
    withr::local_options(transltr.path    = "_translator.yml")
    withr::local_options(transltr.verbose = FALSE)
    transltr:::.onLoad(.Library, "transltr")

    expect_identical(getOption("transltr.path"), "_translator.yml")
    expect_false(getOption("transltr.verbose"))
})

Try the transltr package in your browser

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

transltr documentation built on April 3, 2025, 9:33 p.m.