tests/testthat/test-validate_survey.R

test_that("validate_survey accepts valid arguments", {
  expect_true(
    validate_survey(
      object = data.frame(x = 1:3),
      id = "s1",
      filename = "s1.rds",
      doi = "10.1234/example"
    )
  )
})


test_that("validate_survey accepts tibble objects", {
  expect_true(
    validate_survey(
      object = tibble::tibble(x = 1:3),
      id = "s1",
      filename = "s1.rds",
      doi = NULL
    )
  )
})


test_that("validate_survey accepts NULL metadata", {
  expect_true(
    validate_survey(
      object = data.frame(x = 1:3),
      id = NULL,
      filename = NULL,
      doi = NULL
    )
  )
})


test_that("validate_survey accepts empty data frames", {
  expect_true(
    validate_survey(
      object = data.frame(),
      id = "s1",
      filename = NULL,
      doi = NULL
    )
  )
})


test_that("validate_survey rejects non-data-frame objects", {
  expect_error(
    validate_survey(
      object = 1:3,
      id = "s1",
      filename = NULL,
      doi = NULL
    ),
    "must be a data.frame like object",
    fixed = TRUE
  )
})


test_that("validate_survey rejects invalid identifiers", {
  for (id in list(1, character(), c("s1", "s2"))) {
    expect_error(
      validate_survey(
        object = data.frame(),
        id = id,
        filename = NULL,
        doi = NULL
      ),
      "The 'id' must be a character of length 1L",
      fixed = TRUE
    )
  }
})


test_that("validate_survey rejects invalid filenames", {
  for (filename in list(1, character(), c("a", "b"))) {
    expect_error(
      validate_survey(
        object = data.frame(),
        id = "s1",
        filename = filename,
        doi = NULL
      ),
      "The 'filename' must be a character of length 1L",
      fixed = TRUE
    )
  }
})


test_that("validate_survey rejects invalid DOI values", {
  for (doi in list(1, character(), c("a", "b"))) {
    expect_error(
      validate_survey(
        object = data.frame(),
        id = "s1",
        filename = NULL,
        doi = doi
      ),
      "The 'doi' must be a character of length 1L",
      fixed = TRUE
    )
  }
})

Try the retroharmonize package in your browser

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

retroharmonize documentation built on Nov. 29, 2026, 5:06 p.m.