🔍 An RStudio addin slash regex utility belt
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

39 lines
1.2KB

  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. pass = rep(1L, 4)
  9. )
  10. expect_equal(expand_matches(m[[1]]), idx)
  11. })
  12. test_that("start/end indices are integers", {
  13. text <- "ab ab"
  14. pattern <- "(a)(b)"
  15. m <- regex(text, pattern, global = TRUE)
  16. expect_is(m[[1]]$idx$start, "integer")
  17. expect_is(m[[1]]$idx$end, "integer")
  18. expect_is(m[[1]]$idx$group, "integer")
  19. })
  20. test_that("max_match_index works", {
  21. m <- regex(c("abcaba", "aba", "z"), c("(a)(b)(d)?c?"), global = FALSE)
  22. expect_equal(max_match_index(m), c(4, 3, NA_integer_))
  23. })
  24. test_that("results group (pass) is calculated correctly", {
  25. text <- "ab ab"
  26. pattern <- "(a)(b)"
  27. m <- regex(text, pattern, global = TRUE)
  28. expect_equal(unique(m[[1]]$idx$pass), c(1L, 2L))
  29. })
  30. test_that("view_regex generall works", {
  31. result <- "<p class=\"results \"> <span class=\"group g00\"><span class=\"group g01\">t</span>e</span><span class=\"group g00\"><span class=\"group g01\">s</span>t</span> </p>"
  32. expect_equal(view_regex("test", "(\\w)\\w", render = FALSE), result)
  33. })