File: test-eval-bool.R

package info (click to toggle)
r-cran-tidyselect 1.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 616 kB
  • sloc: sh: 13; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,463 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
test_that("can refer to columns in | operands", {
  expect_identical(select_loc(mtcars, cyl | am), c(cyl = 2L, am = 9L))
})

test_that("can refer to columns in & operands", {
  expect_identical(select_loc(mtcars, cyl & contains("am")), set_names(int(), chr()))
  expect_identical(select_loc(mtcars, cyl & where(is.numeric)), c(cyl = 2L))
})

test_that("can use named inputs in & operands", {
  x <- list(a = 1L, b = 2L)
  expect_identical(select_loc(x, a & c(foo = a)), c(foo = 1L))
  expect_identical(select_loc(x, c(foo = a) & a), c(foo = 1L))
  expect_identical(select_loc(x, c(foo = a) & c(bar = a)), named(int()))
})

test_that("symbol operands are evaluated in strict mode", {
  foo <- 1:2
  expect_error(
    select(iris, Species | foo),
    class = "vctrs_error_subscript_oob"
  )
})

test_that("boolean operators throw relevant errors", {
  expect_error(
    select_loc(mtcars, foobar & contains("am")),
    class = "vctrs_error_subscript_oob"
  )
  expect_error(
    select_loc(mtcars, contains("am") | foobar),
    class = "vctrs_error_subscript_oob"
  )
  expect_error(
    select_loc(mtcars, cyl & am),
    "empty selection"
  )

  expect_snapshot(error = TRUE, {
    "Unknown names"
    select_loc(mtcars, foobar & contains("am"))
    select_loc(mtcars, contains("am") | foobar)

    "Empty intersection"
    select_loc(mtcars, cyl & am)

    "Symbol operands are evaluated in strict mode"
    foo <- 1:2
    select_loc(iris, Species | foo)
  })
})