tests/testthat/test-whitespace.R

context("test-rx_whitespace")

test_that("whitespace special character works", {

  # expect minimal output
  expect_equal(rx_whitespace() %>% as.character(), "\\s")

  # expect match
  expect_true(grepl(rx_whitespace(), " "))

  # expect match only spaces
  expect_equal(
    regmatches("a b c", gregexpr(rx_whitespace(), "a b c"))[[1]], c(" ", " ")
  )

  # dont expect match
  expect_false(grepl(rx_whitespace(), "abc"))

  # expect inverse behavior
  expect_false(grepl(rx_whitespace(inverse = TRUE), " "))
  expect_false(grepl(rx_whitespace(inverse = TRUE), "\t"))
  expect_false(grepl(rx_whitespace(inverse = TRUE), "\n"))
  expect_false(grepl(rx_whitespace(inverse = TRUE), "\r"))

  # expect error if incorrect value to inverse arg
  expect_error(rx_whitespace(inverse = 1))

})

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.