Assert that an output does not match a regular expression
Source:R/assertion-helpers.R
assert_not_matches.Rdassert_not_matches() checks that an output field does not match a
Perl-compatible regular expression. A missing field passes.
Usage
assert_not_matches(
field = NULL,
pattern,
message = NULL,
ignore_case = FALSE,
type = c("assert", "suggest")
)Arguments
- field
The output field to check. With
NULL, the whole output is checked, which suits outputs with a single field. A missing field fails the check.- pattern
A regular expression (Perl syntax) that must not match.
- message
The message shown when the check fails, which
with_assertions()also sends back to the model on a retry. WithNULL, a message naming the field and pattern.- ignore_case
If
TRUE, ignore case when matching.- type
"assert"(the default) for a hard assertion, which makeswith_assertions()retry when it fails, or"suggest"for a soft one, which only gives a warning.
Value
An assertion for assertion_set() or with_assertions().
Examples
assert_not_matches("answer", "https?://", "Do not include links")
#>
#> ── Hard Assertion
#> • Field: any field
#> • Message: "Do not include links"
assert_not_matches("summary", "```", "Do not include code blocks")
#>
#> ── Hard Assertion
#> • Field: any field
#> • Message: "Do not include code blocks"