1test_that("names() dispatches on environment", { 2 env <- child_env(NULL, foo = "foo", bar = "bar") 3 expect_identical(sort(names(env)), c("bar", "foo")) 4}) 5 6test_that("lazy objects are converted to tidy quotes", { 7 env <- child_env(current_env()) 8 9 lazy <- structure(list(expr = quote(foo(bar)), env = env), class = "lazy") 10 expect_identical(compat_lazy(lazy), new_quosure(quote(foo(bar)), env)) 11 12 lazy_str <- "foo(bar)" 13 expect_identical(compat_lazy(lazy_str), quo(foo(bar))) 14 15 lazy_lang <- quote(foo(bar)) 16 expect_identical(compat_lazy(lazy_lang), quo(foo(bar))) 17 18 lazy_sym <- quote(foo) 19 expect_identical(compat_lazy(lazy_sym), quo(foo)) 20}) 21 22test_that("lazy_dots objects are converted to tidy quotes", { 23 env <- child_env(current_env()) 24 25 lazy_dots <- structure(class = "lazy_dots", list( 26 lazy = structure(list(expr = quote(foo(bar)), env = env), class = "lazy"), 27 lazy_lang = quote(foo(bar)) 28 )) 29 30 expected <- list( 31 lazy = new_quosure(quote(foo(bar)), env), 32 lazy_lang = quo(foo(bar)), 33 quo(foo(bar)) 34 ) 35 36 expect_identical(compat_lazy_dots(lazy_dots, current_env(), "foo(bar)"), expected) 37}) 38 39test_that("unnamed lazy_dots are given default names", { 40 lazy_dots <- structure(class = "lazy_dots", list( 41 "foo(baz)", 42 quote(foo(bar)) 43 )) 44 45 expected <- list( 46 `foo(baz)` = quo(foo(baz)), 47 `foo(bar)` = quo(foo(bar)), 48 foobarbaz = quo(foo(barbaz)) 49 ) 50 dots <- compat_lazy_dots(lazy_dots, current_env(), foobarbaz = "foo(barbaz)", .named = TRUE) 51 52 expect_identical(dots, expected) 53}) 54 55test_that("compat_lazy() handles missing arguments", { 56 expect_identical(compat_lazy(), quo()) 57}) 58 59test_that("compat_lazy_dots() takes lazy objects", { 60 lazy <- structure(list(expr = quote(foo), env = empty_env()), class = "lazy") 61 expect_identical(compat_lazy_dots(lazy), named_list(new_quosure(quote(foo), empty_env()))) 62}) 63 64test_that("compat_lazy_dots() takes symbolic objects", { 65 expect_identical(compat_lazy_dots(quote(foo), empty_env()), named_list(new_quosure(quote(foo), empty_env()))) 66 expect_identical(compat_lazy_dots(quote(foo(bar)), empty_env()), named_list(new_quosure(quote(foo(bar)), empty_env()))) 67}) 68 69test_that("compat_lazy() demotes character vectors to strings", { 70 expect_identical(compat_lazy_dots(NULL, current_env(), c("foo", "bar")), named_list(as_quosure(~foo))) 71}) 72 73test_that("compat_lazy() handles numeric vectors", { 74 expect_identical(compat_lazy_dots(NULL, current_env(), NA_real_), named_list(set_env(quo(NA_real_)))) 75 expect_warning(expect_identical(compat_lazy_dots(NULL, current_env(), 1:3), named_list(set_env(quo(1L)))), "Truncating vector") 76}) 77 78test_that("compat_lazy() handles bare formulas", { 79 expect_identical(compat_lazy(~foo), quo(foo)) 80 expect_identical(compat_lazy_dots(~foo), named_list(quo(foo))) 81}) 82 83test_that("trimws() trims", { 84 x <- " foo. " 85 expect_identical(trimws(x), "foo.") 86 expect_identical(trimws(x, "l"), "foo. ") 87 expect_identical(trimws(x, "r"), " foo.") 88}) 89 90test_that("map2() sets names", { 91 expect_identical(map2(list(foo = NULL, bar = NULL), 1:2, function(...) NULL), list(foo = NULL, bar = NULL)) 92}) 93 94test_that("map2() discards recycled names", { 95 expect_identical(map2(list(foo = NULL), 1:3, function(...) NULL), new_list(3)) 96}) 97