1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
test_that("can subset with regexps", {
x <- c("a", "b", "c")
expect_equal(str_subset(x, "a|c"), c("a", "c"))
expect_equal(str_subset(x, "a|c", negate = TRUE), "b")
})
test_that("can subset with fixed patterns", {
expect_equal(str_subset(c("i", "I"), fixed("i")), "i")
expect_equal(
str_subset(c("i", "I"), fixed("i", ignore_case = TRUE)),
c("i", "I")
)
# negation works
expect_equal(str_subset(c("i", "I"), fixed("i"), negate = TRUE), "I")
})
test_that("str_which is equivalent to grep", {
expect_equal(
str_which(head(letters), "[aeiou]"),
grep("[aeiou]", head(letters))
)
# negation works
expect_equal(
str_which(head(letters), "[aeiou]", negate = TRUE),
grep("[aeiou]", head(letters), invert = TRUE)
)
})
test_that("can use fixed() and coll()", {
expect_equal(str_subset(c("x", "."), fixed(".")), ".")
expect_equal(str_subset(c("i", "\u0131"), turkish_I()), "\u0131")
})
test_that("can't use boundaries", {
expect_snapshot(error = TRUE, {
str_subset(c("a", "b c"), "")
str_subset(c("a", "b c"), boundary())
})
})
|