tests/testthat/test-check_crucial_names.R

test_that("check_crucial_names with expected names returns `x` invisibly", {
  x <- c(a = 1)
  expect_silent(out <- check_crucial_names(x, "a"))
  expect_identical(x, out)

  x <- data.frame(a = 1)
  expect_silent(out <- check_crucial_names(x, "a"))
  expect_identical(x, out)
})

test_that("check_crucial_names with expected names returns `x` invisibly", {
  x <- c(a = 1)
  expect_error(check_crucial_names(x, "b"), "must have all expected names")

  x <- data.frame(a = 1)
  expect_error(check_crucial_names(x, "b"), "must have all expected names")
})

test_that("check_crucial_names w/ duplicated expected informs unique", {
  expect_error(
    check_crucial_names(c(x = 1), expected_names = c("x", "z", "a")),
    "missing.*a.*z"
  )
})
2DegreesInvesting/r2dii.utils documentation built on Jan. 16, 2020, 11:21 p.m.