tests/testthat/test-str-detect2.R

test_that("special cases are correct", {
  expect_equal(str_detect2(character(), "x"), logical())

  expect_equal(str_detect2(NA, "x"), FALSE)
  expect_equal(str_detect2(NA, "x", negate = TRUE), TRUE)
})

test_that("vectorised patterns work", {
  expect_equal(
    str_detect2("ab", c("a", "b", "c")),
    c(TRUE, TRUE, FALSE)
  )
  expect_equal(
    str_detect2(c("ca", "ab"), c("a", "c")),
    c(TRUE, FALSE)
  )

  expect_equal(
    str_detect2("ab", c("a", "b", "c"), negate = TRUE),
    c(FALSE, FALSE, TRUE)
  )
})

Try the tidyplus package in your browser

Any scripts or data that you put into this service are public.

tidyplus documentation built on April 3, 2025, 7:44 p.m.