🔍 An RStudio addin slash regex utility belt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
749B

  1. context("test-regex")
  2. test_that("expand_matches gives data frame of indices with groups", {
  3. m <- regexec("(a)(b)(d)?", "abcaba")
  4. idx <- data.frame(
  5. start = c(1L, 1L, 2L, NA_integer_),
  6. end = c(3L, 2L, 3L, NA_integer_),
  7. group = c(0L, 1L, 2L, 3L)
  8. )
  9. expect_equal(expand_matches(m[[1]]), idx)
  10. })
  11. test_that("start/end indices are integers", {
  12. text <- "ab ab"
  13. pattern <- "(a)(b)"
  14. m <- run_regex(text, pattern, global = TRUE)
  15. expect_is(m[[1]]$idx$start, "integer")
  16. expect_is(m[[1]]$idx$end, "integer")
  17. expect_is(m[[1]]$idx$group, "integer")
  18. })
  19. test_that("max_match_index works", {
  20. m <- run_regex(c("abcaba", "aba", "z"), c("(a)(b)(d)?c?"), global = FALSE)
  21. expect_equal(max_match_index(m), c(4, 3, NA_integer_))
  22. })