File: test-modifiers.R

package info (click to toggle)
r-cran-stringr 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,112 kB
  • sloc: javascript: 11; sh: 9; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,164 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
test_that("patterns coerced to character", {
  x <- factor("a")

  expect_snapshot({
    . <- regex(x)
    . <- coll(x)
    . <- fixed(x)
  })
})

test_that("useful error message for bad type", {
  expect_snapshot(error = TRUE, {
    type(1:3)
  })
})

test_that("fallback for regex (#433)", {
  expect_equal(type(structure("x", class = "regex")), "regex")
})

test_that("ignore_case sets strength, but can override manually", {
  x1 <- coll("x", strength = 1)
  x2 <- coll("x", ignore_case = TRUE)
  x3 <- coll("x")

  expect_equal(attr(x1, "options")$strength, 1)
  expect_equal(attr(x2, "options")$strength, 2)
  expect_equal(attr(x3, "options")$strength, 3)
})

test_that("boundary has length 1", {
  expect_length(boundary(), 1)
})

test_that("subsetting preserves class and options", {
  x <- regex("a", multiline = TRUE)
  expect_equal(x[], x)
})

test_that("useful errors for NAs", {
  expect_snapshot(error = TRUE, {
    type(NA)
    type(c("a", "b", NA_character_, "c"))
  })
})

test_that("stringr_pattern methods", {
  ex <- coll(c("foo", "bar"))
  expect_true(inherits(ex[1], "stringr_pattern"))
  expect_true(inherits(ex[[1]], "stringr_pattern"))
})