context("test-wrap_result.R") test_that("wrap_result handles zero length groups", { # Issue #9 # Type 'q()' to quit R. # (?<=\()([^)]*)(?=\)) text <- "Type 'q()' to quit R." pattern <- "(?<=\\()([^)]*)(?=\\))" res <- wrap_result(run_regex(text, pattern, perl = TRUE, global = FALSE)[[1]]) expect_equal(res, "Type 'q()' to quit R.") }) test_that("wrap_results generally works", { text <- "apples" pattern <- "apples" res <- wrap_result(run_regex(text, pattern, perl = TRUE, global = FALSE)[[1]]) expect_equal(res, "apples") text <- "He wheeled the bike past the winding road." pattern <- "(a|the) ([^ ]+)" res <- wrap_result(run_regex(text, pattern, perl = TRUE, global = FALSE)[[1]]) expect_equal(res, "He wheeled the bike past the winding road.") text <- ".15in" pattern <- "^(auto|inherit|((\\.\\d+)|(\\d+(\\.\\d+)?))(%|in|cm|mm|em|ex|pt|pc|px|vh|vw|vmin|vmax))$" res <- wrap_result(run_regex(text, pattern, perl = TRUE, global = FALSE)[[1]]) expect_equal(res, ".15in") }) test_that("wrap_results works when groups start and end at same index", { text <- "7282298386" pattern <- "\\(?(\\d{3})[-). ]?(\\d{3})[- .]?(\\d{4})" res <- wrap_result(run_regex(text, pattern, perl = TRUE, global = FALSE)[[1]]) expect_equal(res, "7282298386") }) test_that("wrap_regex searches globally", { text <- "ab ab" pattern <- "(a)(b)" result <- paste(rep("ab", 2), collapse = " ") expect_equal(wrap_result(run_regex(text, pattern, global = TRUE)[[1]]), result) })