| 1 |
test_that("can refer to columns in | operands", { |
| 2 |
expect_identical(select_loc(mtcars, cyl | am), c(cyl = 2L, am = 9L)) |
| 3 |
}) |
| 4 |
|
| 5 |
test_that("can refer to columns in & operands", { |
| 6 |
expect_identical(select_loc(mtcars, cyl & contains("am")), set_names(int(), chr())) |
| 7 |
expect_identical(select_loc(mtcars, cyl & where(is.numeric)), c(cyl = 2L)) |
| 8 |
}) |
| 9 |
|
| 10 |
test_that("can use named inputs in & operands", { |
| 11 |
x <- list(a = 1L, b = 2L) |
| 12 |
expect_identical(select_loc(x, a & c(foo = a)), c(foo = 1L)) |
| 13 |
expect_identical(select_loc(x, c(foo = a) & a), c(foo = 1L)) |
| 14 |
expect_identical(select_loc(x, c(foo = a) & c(bar = a)), named(int())) |
| 15 |
}) |
| 16 |
|
| 17 |
test_that("symbol operands are evaluated in strict mode", { |
| 18 |
foo <- 1:2 |
| 19 |
expect_error( |
| 20 |
select(iris, Species | foo), |
| 21 |
class = "vctrs_error_subscript_oob" |
| 22 |
) |
| 23 |
}) |
| 24 |
|
| 25 |
test_that("boolean operators throw relevant errors", { |
| 26 |
expect_error( |
| 27 |
select_loc(mtcars, foobar & contains("am")), |
| 28 |
class = "vctrs_error_subscript_oob" |
| 29 |
) |
| 30 |
expect_error( |
| 31 |
select_loc(mtcars, contains("am") | foobar), |
| 32 |
class = "vctrs_error_subscript_oob" |
| 33 |
) |
| 34 |
expect_error( |
| 35 |
select_loc(mtcars, cyl & am), |
| 36 |
"empty selection" |
| 37 |
) |
| 38 |
|
| 39 |
expect_snapshot(error = TRUE, { |
| 40 |
"Unknown names" |
| 41 |
select_loc(mtcars, foobar & contains("am")) |
| 42 |
select_loc(mtcars, contains("am") | foobar) |
| 43 |
|
| 44 |
"Empty intersection" |
| 45 |
select_loc(mtcars, cyl & am) |
| 46 |
|
| 47 |
"Symbol operands are evaluated in strict mode" |
| 48 |
foo <- 1:2 |
| 49 |
select_loc(iris, Species | foo) |
| 50 |
}) |
| 51 |
}) |