tests/testthat/test-chk-null.R

test_that("vld_null", {
  expect_true(vld_null(NULL))
  expect_false(vld_null(1))
})

test_that("chk_null", {
  expect_identical(chk_null(NULL), NULL)
  expect_invisible(chk_null(NULL))

  expect_chk_error(chk_null(1), "^`1` must be NULL[.]$")
  expect_chk_error(chk_null(1, x_name = "NULL"), "^NULL must be NULL[.]$")
})

test_that("vld_not_null", {
  expect_true(vld_not_null(1))
  expect_false(vld_not_null(NULL))
})

test_that("chk_not_null", {
  expect_identical(chk_not_null(1), 1)
  expect_invisible(chk_not_null(1))

  expect_chk_error(chk_not_null(NULL), "^`NULL` must not be NULL[.]$")
  expect_chk_error(chk_not_null(NULL, x_name = "not NULL"), "^Not NULL must not be NULL[.]$")
})

Try the chk package in your browser

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

chk documentation built on Oct. 6, 2023, 9:06 a.m.