tests/testthat/test-getByType.r

##------------------------------------------------------------------------------
context("getByType/list")
##------------------------------------------------------------------------------

test_that("getByType/list/value = 1", {
  
  input <- list(
    x1 = list(x11 = list(x111 = 1, x112 = 1), x12 = list(x121 = 1, x122 = 1)),
    x2 = list(x21 = "x21"),
    x3 = list("x31"),
    x4 = "x4",
    x5 = list(1:3),
    list(list(1, 2), list(3, 4)),
    list(1:3),
    "char 1",
    "char 2",
    letters[1:3],
    c(1,3,5),
    TRUE,
    new.env(),
    data.frame(x = 1:3, y = 1:3)
  )

  expect_is(res <- getByType(input, value = 1), "list")
  expect_is(res <- getByType(input, value = 1, resolve = TRUE), "list")
  
})

test_that("getByType/list/value = 2", {
  
  input <- list(
    x1 = list(x11 = list(x111 = 1, x112 = 1), x12 = list(x121 = 1, x122 = 1)),
    x2 = list(x21 = "x21"),
    x3 = list("x31"),
    x4 = "x4",
    x5 = list(1:3),
    list(list(1, 2), list(3, 4)),
    list(1:3),
    "char 1",
    "char 2",
    letters[1:3],
    c(1,3,5),
    TRUE,
    new.env(),
    data.frame(x = 1:3, y = 1:3)
  )
  expect_is(res <- getByType(input, value = 2), "list")
  expect_is(res <- getByType(input, value = 2, resolve = TRUE), "list")
  
})

test_that("getByType/list/value = 3", {
  
  input <- list(
    x1 = list(x11 = list(x111 = 1, x112 = 1), x12 = list(x121 = 1, x122 = 1)),
    x2 = list(x21 = "x21"),
    x3 = list("x31"),
    x4 = "x4",
    x5 = list(1:3),
    list(list(1, 2), list(3, 4)),
    list(1:3),
    "char 1",
    "char 2",
    letters[1:3],
    c(1,3,5),
    TRUE,
    new.env(),
    data.frame(x = 1:3, y = 1:3)
  )
  
  expect_is(res <- getByType(input, value = 3), "list")
  expect_is(res <- getByType(input, value = 3, resolve = TRUE), "list")
  
})
rappster/listr documentation built on May 26, 2019, 11:21 p.m.