tests/testthat/test-something_but.R

context("test-rx_something_but")

test_that("something_but rule works", {

  # expect match
  expect_true(grepl(rx_something_but(value = "a"), "b"))
  expect_true(grepl(rx_something_but(value = "a", mode = "lazy"), "b"))

  # dont expect match
  expect_false(grepl(rx_something_but(value = "a"), "a"))

  # expect to match something but "a"
  expect_equal(
    regmatches("abc", gregexpr(rx_something_but(value = "a"), "abc"))[[1]], "bc"
  )
  expect_true(
    compare(regmatches("abc", gregexpr(rx_something_but(value = "a", mode = "lazy"), "abc"))[[1]], c("b", "c"))$equal
  )

  # expect an error if invalid 'mode' is given
  expect_error(rx_something_but(mode = "whatever"))
})

Try the RVerbalExpressions package in your browser

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

RVerbalExpressions documentation built on Nov. 6, 2019, 5:08 p.m.