tests/testthat/test-searches.R

test_that("multi_grepl() examples are correct", {
  x <- c("apple", "banana", "lemon")

  expect_equal(
    multi_grepl(x, c("a" = "^[ab]", "b" = "lem")),
    c("a", "a", "b")
  )

  expect_equal(
    # lemon not matches on either
    multi_grepl(x, c("a" = "^[ab]", "b" = "q")),
    c("a", "a", NA_character_)
  )

  expect_equal(
    # apple matches "a" before "b"
    multi_grepl(x, c("a" = "^[ab]", "b" = "e")),
    c("a", "a", "b")
  )

  expect_equal(
    multi_grepl(x, c("a" = "^[ab]", "b" = "e"), simplify = FALSE),
    list(c("a", "b"), "a", "b")
  )

  expect_equal(
    multi_grepl(x, c("^[ab]", "e"), simplify = FALSE),
    list(c(1L, 2L), 1L, 2L)
  )

  expect_equal(
    # returned as positions
    multi_grepl(x, c("^[ab]", "e")),
    c(1L, 1L, 2L)
  )
})

Try the mark package in your browser

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

mark documentation built on May 29, 2024, 5:13 a.m.