|
1 | | -test_that("extra arguments to matches passed onto grepl", { |
2 | | - expect_success(expect_match("te*st", "e*", fixed = TRUE)) |
3 | | - expect_success(expect_match("test", "TEST", ignore.case = TRUE)) |
4 | | -}) |
| 1 | +test_that("generates useful failure messages", { |
| 2 | + zero <- character(0) |
| 3 | + expect_snapshot_failure(expect_match(zero, 'asdf')) |
5 | 4 |
|
6 | | -test_that("special regex characters are escaped in output", { |
7 | | - error <- tryCatch( |
8 | | - expect_match("f() test", "f() test"), |
9 | | - expectation = function(e) e$message |
10 | | - ) |
11 | | - expect_equal( |
12 | | - error, |
13 | | - "\"f\\(\\) test\" does not match \"f() test\".\nActual value: \"f\\(\\) test\"" |
14 | | - ) |
15 | | -}) |
| 5 | + one <- "bcde" |
| 6 | + expect_snapshot_failure(expect_match(one, 'asdf')) |
16 | 7 |
|
17 | | -test_that("correct reporting of expected label", { |
18 | | - expect_failure(expect_match("[a]", "[b]"), escape_regex("[a]"), fixed = TRUE) |
19 | | - expect_failure(expect_match("[a]", "[b]", fixed = TRUE), "[a]", fixed = TRUE) |
| 8 | + many <- letters[1:5] |
| 9 | + expect_snapshot_failure(expect_match(many, 'asdf')) |
20 | 10 | }) |
21 | 11 |
|
22 | | -test_that("errors if obj is empty str", { |
23 | | - x <- character(0) |
24 | | - err <- expect_error( |
25 | | - expect_match(x, 'asdf'), |
26 | | - class = "expectation_failure" |
27 | | - ) |
28 | | - expect_match(err$message, 'is empty') |
| 12 | +test_that("checks its inputs", { |
| 13 | + expect_snapshot(error = TRUE, { |
| 14 | + expect_match(1) |
| 15 | + expect_match("x", 1) |
| 16 | + expect_match("x", "x", fixed = 1) |
| 17 | + expect_match("x", "x", perl = 1) |
| 18 | + expect_match("x", "x", all = 1) |
| 19 | + }) |
29 | 20 | }) |
30 | 21 |
|
31 | | -test_that("prints multiple unmatched values", { |
32 | | - err <- expect_error( |
33 | | - expect_match(letters[1:10], 'asdf'), |
34 | | - class = "expectation_failure" |
35 | | - ) |
36 | | - expect_match(err$message, "does not match") |
| 22 | +test_that("extra arguments passed onto grepl", { |
| 23 | + expect_failure(expect_match("\\s", "\\s")) |
| 24 | + expect_success(expect_match("\\s", "\\s", fixed = TRUE)) |
| 25 | + |
| 26 | + expect_failure(expect_match("test", "TEST")) |
| 27 | + expect_success(expect_match("test", "TEST", ignore.case = TRUE)) |
37 | 28 | }) |
38 | 29 |
|
39 | 30 | test_that("expect_no_match works", { |
40 | 31 | expect_success(expect_no_match("[a]", "[b]")) |
41 | 32 | expect_success(expect_no_match("[a]", "[b]", fixed = TRUE)) |
42 | | - expect_failure( |
43 | | - expect_no_match("te*st", "e*", fixed = TRUE), |
44 | | - escape_regex("te*st") |
45 | | - ) |
46 | | - expect_failure(expect_no_match("test", "TEST", ignore.case = TRUE), "test") |
| 33 | + |
| 34 | + x <- "te*st" |
| 35 | + expect_snapshot_failure(expect_no_match(x, "e*", fixed = TRUE)) |
| 36 | + x <- "test" |
| 37 | + expect_snapshot_failure(expect_no_match(x, "TEST", ignore.case = TRUE)) |
| 38 | +}) |
| 39 | + |
| 40 | +test_that("empty string is never a match", { |
| 41 | + expect_success(expect_no_match(character(), "x")) |
47 | 42 | }) |
0 commit comments