Struct regex_test::TestResult
source · pub struct TestResult { /* private fields */ }
Expand description
The result of executing a regex search.
When using the test runner, callers must provide a closure that takes
a RegexTest
and returns a TestResult
. The TestResult
is meant to
capture the results of matching the haystack against the regex specified by
the RegexTest
.
Usually this consists of one or more matches, which can be constructed via
TestResult::matches
(for just overall matches) or TestResult::captures
(for matches with capture group spans). But the regex engine may also
report whether a match exists, or just whether a pattern matched or not.
That can be done via TestResult::matched
and TestResult::which
,
respectively.
Implementations§
source§impl TestResult
impl TestResult
sourcepub fn matched(yes: bool) -> TestResult
pub fn matched(yes: bool) -> TestResult
Create a test result that indicates just whether any match was found or not.
sourcepub fn which<I: IntoIterator<Item = usize>>(it: I) -> TestResult
pub fn which<I: IntoIterator<Item = usize>>(it: I) -> TestResult
Create a test result that indicates which out of possibly many regexes
matched the haystack. If which
is empty, then this is equivalent to
TestResult::matched(false)
.
Note that the iterator should consist of pattern IDs, where each ID corresponds to a pattern that matches anywhere in the haystack. Multiple patterns may match the same region of the haystack. That is, this supports overlapping matches.
sourcepub fn matches<I: IntoIterator<Item = Match>>(it: I) -> TestResult
pub fn matches<I: IntoIterator<Item = Match>>(it: I) -> TestResult
Create a test result containing a sequence of all matches in the test’s haystack. This is useful when the regex engine only reports overall matches and not the spans of each matching capture group.
If the sequence is empty, then this is equivalent to
TestResult::matched(false)
.
sourcepub fn captures<I: IntoIterator<Item = Captures>>(it: I) -> TestResult
pub fn captures<I: IntoIterator<Item = Captures>>(it: I) -> TestResult
Create a test result containing a sequence of all capturing matches in
the test’s haystack. Each match is a Captures
, and each Captures
should include the spans of all matching capturing groups.
If the sequence is empty, then this is equivalent to
TestResult::matched(false)
.
sourcepub fn skip() -> TestResult
pub fn skip() -> TestResult
Indicate that this test should be skipped. It will not be counted as a failure.
sourcepub fn fail(why: &str) -> TestResult
pub fn fail(why: &str) -> TestResult
Indicate that this test should be failed for the reason given.
This is useful when a test needs to be failed for reasons that the test runner itself cannot check. That is, the test is failed by the implementation being tested.
Trait Implementations§
source§impl Clone for TestResult
impl Clone for TestResult
source§fn clone(&self) -> TestResult
fn clone(&self) -> TestResult
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more