Struct regex_test::RegexTest
source · pub struct RegexTest { /* private fields */ }
Expand description
A regex test describes the inputs and expected outputs of a regex match.
Each RegexTest
represents a single [[test]]
table in a TOML test file.
Implementations§
source§impl RegexTest
impl RegexTest
sourcepub fn group(&self) -> &str
pub fn group(&self) -> &str
Return the group name of this test.
Usually the group name corresponds to a collection of related
tests. More specifically, when using RegexTests::load
, the
group name corresponds to the file stem (the file name without the
.toml
suffix). Otherwise, the group name is whatever is given to
RegexTests::load_slice
.
sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
The name of this test.
Note that this is only the name as given in the [[test]]
block. The
actual full name used for filtering and reporting can be retrieved with
RegexTest::full_name
.
sourcepub fn additional_name(&self) -> &str
pub fn additional_name(&self) -> &str
The additional name for this test.
This is only non-empty when the test runner was expanded with
TestRunner::expand
.
sourcepub fn full_name(&self) -> &str
pub fn full_name(&self) -> &str
The full name of this test, which is formed by joining the group
name, the test name and the additional name with a /
.
sourcepub fn regexes(&self) -> &[String]
pub fn regexes(&self) -> &[String]
Return all of the regexes that should be matched for this test. This slice may be empty!
sourcepub fn bounds(&self) -> Span
pub fn bounds(&self) -> Span
Returns the bounds of a search.
If the test didn’t specify any bounds, then the bounds returned are equivalent to the entire haystack.
sourcepub fn match_limit(&self) -> Option<usize>
pub fn match_limit(&self) -> Option<usize>
Returns the limit on the number of matches that should be reported, if specified in the test.
This is useful for tests that only want to check for the first match. In which case, the match limit is set to 1.
If there is no match limit, then regex engines are expected to report all matches.
sourcepub fn compiles(&self) -> bool
pub fn compiles(&self) -> bool
Returns true if the regex(es) in this test are expected to compile.
sourcepub fn anchored(&self) -> bool
pub fn anchored(&self) -> bool
Whether the regex should perform an anchored search.
This is distinct from putting a ^
in the regex in that bounds
may
be specified that permit the regex search to start at a position
i > 0
. In which case, enabling anchored mode here requires that any
matches produced must have a start offset at i
.
sourcepub fn case_insensitive(&self) -> bool
pub fn case_insensitive(&self) -> bool
Returns true if regex matching should be performed without regard to case.
sourcepub fn unicode(&self) -> bool
pub fn unicode(&self) -> bool
Returns true if regex matching should have Unicode mode enabled.
For example, [^a]
matches any UTF-8 encoding of any codepoint other
than a
. Case insensitivty should be Unicode aware. Unicode classes
like \pL
are available. The Perl classes \w
, \s
and \d
should
be Unicode aware. And so on.
This is enabled by default.
sourcepub fn utf8(&self) -> bool
pub fn utf8(&self) -> bool
Returns true if regex matching should exclusively match valid UTF-8. When this is disabled, matching on arbitrary bytes is permitted.
When this is enabled, all regex match substrings should be entirely valid UTF-8. While parts of the haystack the regex searches through may not be valid UTF-8, only the portions that are valid UTF-8 may be reported in match spans.
Importantly, this includes zero-width matches. Zero-width matches must never split the UTF-8 encoding of a single codepoint when this is enabled.
This is enabled by default.
sourcepub fn line_terminator(&self) -> u8
pub fn line_terminator(&self) -> u8
Returns the line terminator that should be used for the multi-line
assertions (?m:^)
and (?m:$)
.
If it isn’t set, then this defaults to \n
.
sourcepub fn match_kind(&self) -> MatchKind
pub fn match_kind(&self) -> MatchKind
Return the match semantics required by this test.
sourcepub fn search_kind(&self) -> SearchKind
pub fn search_kind(&self) -> SearchKind
Return the search semantics required by this test.