Learn R Programming

testthat (version 0.6)

matches: Expectation: does string match regular expression?

Description

If the object to be tested has length greater than one, all elements of the vector must match the pattern in order to pass.

Usage

matches(regexp, all = TRUE)

expect_match(object, regexp, all = TRUE, info = NULL, label = NULL)

Arguments

regexp
regular expression to test against
all
should all elements of actual value match regexp (TRUE), or does only one need to match (FALSE)
object
object to test
info
extra information to be included in the message (useful when writing tests in loops).
label
object label. When NULL, computed from deparsed object.

See Also

str_detect for the function that powers the string matching

Other expectations: equals, expect_equal, expect_equivalent, expect_error, expect_false, expect_identical, expect_is, expect_message, expect_output, expect_true, expect_warning, gives_warning, is_a, is_equivalent_to, is_false, is_identical_to, is_true, prints_text, shows_message, takes_less_than, throws_error

Examples

Run this code
expect_that("Testing is fun", matches("fun"))
expect_that("Testing is fun", matches("f.n"))
expect_match("Testing is fun", "f.n")

Run the code above in your browser using DataLab