tests/testthat/test_populateutil.R

test_that("Structure", {
  foo <- Structure(a = 1, b = 2)
  expect_equal(tag_get(foo, "type"), "structure")
  expect_equal(foo, list(a = 1, b = 2), ignore_attr = TRUE)

  expect_error(Structure(1, 2, 3))
})

test_that("List", {
  foo <- List()
  expect_equal(tag_get(foo, "type"), "list")

  bar <- List(1, 2)
  expect_equal(bar, list(1, 2), ignore_attr = TRUE)

  expect_error(List(a = 1, b = 2))
})

test_that("Map", {
  foo <- Map()
  expect_equal(tag_get(foo, "type"), "map")

  bar <- Map(list(Name = "foo", Value = 1), list(Name = "bar", Value = 2))
  expect_equal(bar, list(list(Name = "foo", Value = 1), list(Name = "bar", Value = 2)), ignore_attr = TRUE)

  expect_error(Map(a = 1, b = 2))
})

test_that("Scalar", {
  foo <- Scalar()
  expect_equal(tag_get(foo, "type"), "scalar")

  bar <- Scalar("foo")
  expect_equal(bar, "foo", ignore_attr = TRUE)

  expect_error(Scalar(c(1, 2)))
  expect_error(Scalar(list()))
  expect_error(Scalar(list(1)))
})

Try the paws.common package in your browser

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

paws.common documentation built on Nov. 12, 2023, 1:08 a.m.