1test_that("can detect presence vs absence names", { 2 expect_identical(has_name(list("foo", "bar")), c(FALSE, FALSE)) 3 expect_identical(has_name(list(a = "foo", "bar")), c(TRUE, FALSE)) 4 5 expect_identical(has_name({ 6 x <- list("foo", "bar"); names(x)[1] <- "a"; x 7 }), c(TRUE, FALSE)) 8 expect_identical(has_name({ 9 x <- list("foo", "bar"); names(x)[1] <- "a"; names(x)[2] <- ""; x 10 }), c(TRUE, FALSE)) 11 12 expect_identical(has_name({ 13 x <- list("foo", "bar"); names(x)[1] <- ""; x 14 }), c(FALSE, FALSE)) 15 expect_identical(has_name({ 16 x <- list("foo", "bar"); names(x)[1] <- ""; names(x)[2] <- ""; x 17 }), c(FALSE, FALSE)) 18 19}) 20 21test_that("named NULL is dropped", { 22 23 tcs <- list( 24 list(list(), list()), 25 list(list(a = 1), list(a = 1)), 26 list(list(NULL), list(NULL)), 27 list(list(a = NULL), list()), 28 list(list(NULL, a = NULL, 1), list(NULL, 1)), 29 list(list(a = NULL, b = 1, 5), list(b = 1, 5)) 30 ) 31 32 for (tc in tcs) { 33 expect_identical( 34 drop_named_nulls(tc[[1]]), 35 tc[[2]], 36 info = tc 37 ) 38 } 39}) 40 41test_that("named NA is error", { 42 43 goodtcs <- list( 44 list(), 45 list(NA), 46 list(NA, NA_integer_, a = 1) 47 ) 48 49 badtcs <- list( 50 list(b = NULL, a = NA), 51 list(a = NA_integer_), 52 list(NA, c = NA_real_) 53 ) 54 55 for (tc in goodtcs) { 56 expect_silent(check_named_nas(tc)) 57 } 58 59 for (tc in badtcs) { 60 expect_error(check_named_nas(tc)) 61 } 62}) 63