tests/testthat/test-pivot.R

test_that("basic sanity checks for spec occur", {
  expect_snapshot({
    (expect_error(check_pivot_spec(1)))
    (expect_error(check_pivot_spec(mtcars)))
  })
})

test_that("`.name` column must be a character vector", {
  df <- tibble(.name = 1:2, .value = c("a", "b"))
  expect_snapshot((expect_error(check_pivot_spec(df))))
})

test_that("`.value` column must be a character vector", {
  df <- tibble(.name = c("x", "y"), .value = 1:2)
  expect_snapshot((expect_error(check_pivot_spec(df))))
})

test_that("`.name` column must be unique", {
  df <- tibble(.name = c("x", "x"), .value = c("a", "b"))
  expect_snapshot((expect_error(check_pivot_spec(df))))
})

Try the tidyr package in your browser

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

tidyr documentation built on Feb. 16, 2023, 7:40 p.m.