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

source

pub fn matched(yes: bool) -> TestResult

Create a test result that indicates just whether any match was found or not.

source

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.

source

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).

source

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).

source

pub fn skip() -> TestResult

Indicate that this test should be skipped. It will not be counted as a failure.

source

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

source§

fn clone(&self) -> TestResult

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TestResult

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.