| has_match | R Documentation |
Check whether x matches the regular expression pattern. This is intended
for use inside assert(): unlike grepl(), which only returns
TRUE/FALSE and hides the input on failure, a failing has_match() shows
the actual string so you can see what was produced.
has_match(
x,
pattern,
negate = FALSE,
fixed = inherits(pattern, "AsIs"),
perl = !fixed,
...
)
x |
A character vector. Multiple elements are collapsed into a single string (separated by newlines) before matching. |
pattern |
A regular expression. By default, matching uses Perl mode with
the "dotall" flag enabled, so |
negate |
If |
fixed |
Whether to match |
perl |
Whether to use Perl-compatible regular expressions (which also
enables the dotall flag). Defaults to |
... |
Additional arguments passed to |
TRUE if x matches pattern (or does not match it when
negate = TRUE), otherwise FALSE.
library(testit)
assert('the page has a script but no style', {
html = '<html>\n<script>x</script>\n</html>'
(has_match(html, '<script>.*</script>'))
(has_match(html, '<style>', negate = TRUE))
(has_match(html, !'<style>')) # same, via the !pattern shorthand
(has_match(html, I('<script>x</script>'))) # literal match (fixed = TRUE)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.