🔍 An RStudio addin slash regex utility belt
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

36 lines
1.7KB

  1. context("test-wrap_result.R")
  2. test_that("wrap_result handles zero length groups", {
  3. # Issue #9
  4. # Type 'q()' to quit R.
  5. # (?<=\()([^)]*)(?=\))
  6. text <- "Type 'q()' to quit R."
  7. pattern <- "(?<=\\()([^)]*)(?=\\))"
  8. res <- wrap_result(run_regex(text, pattern, perl = TRUE)[[1]])
  9. expect_equal(res, "Type 'q(<span class=\"group g00\"><span class=\"group g01\"></span></span>)' to quit R.")
  10. })
  11. test_that("wrap_results generally works", {
  12. text <- "apples"
  13. pattern <- "apples"
  14. res <- wrap_result(run_regex(text, pattern, perl = TRUE)[[1]])
  15. expect_equal(res, "<span class=\"group g00\">apples</span>")
  16. text <- "He wheeled the bike past the winding road."
  17. pattern <- "(a|the) ([^ ]+)"
  18. res <- wrap_result(run_regex(text, pattern, perl = TRUE)[[1]])
  19. expect_equal(res, "He wheeled <span class=\"group g00\"><span class=\"group g01\">the</span> <span class=\"group g02\">bike</span></span> past the winding road.")
  20. text <- ".15in"
  21. pattern <- "^(auto|inherit|((\\.\\d+)|(\\d+(\\.\\d+)?))(%|in|cm|mm|em|ex|pt|pc|px|vh|vw|vmin|vmax))$"
  22. res <- wrap_result(run_regex(text, pattern, perl = TRUE)[[1]])
  23. expect_equal(res, "<span class=\"group g00\"><span class=\"group g01\"><span class=\"group g02 pad01\"><span class=\"group g03 pad02\">.15</span></span><span class=\"group g06 pad01\">in</span></span></span>")
  24. })
  25. test_that("wrap_results works when groups start and end at same index", {
  26. text <- "7282298386"
  27. pattern <- "\\(?(\\d{3})[-). ]?(\\d{3})[- .]?(\\d{4})"
  28. res <- wrap_result(run_regex(text, pattern, perl = TRUE)[[1]])
  29. expect_equal(res, "<span class=\"group g00\"><span class=\"group g01\">728</span><span class=\"group g02\">229</span><span class=\"group g03\">8386</span></span>")
  30. })