test_that("match_arg() works as expected", {
test <- function(hello = c("choice1", "choice2"), assert = FALSE) {
res <- match_arg(hello, assert = assert)
return(res)
}
expect_null(test())
expect_null(test(NULL))
expect_equal(test("choice2"), "choice2")
expect_equal(test("invalid"), "invalid")
expect_error(test("invalid", assert = TRUE))
expect_error(test("choice1", assert = TRUE), NA)
})
test_that("when() works", {
1 %>%
when(TRUE, . + 1) %>%
expect_equal(2)
1 %>%
when(FALSE, . + 1) %>%
expect_equal(1)
})
test_that("add_class() works", {
list() %>%
add_class("a") %>%
class() %>%
expect_equal(c("a", "list"))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.