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

source

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.

source

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.

source

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.

source

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

source

pub fn regexes(&self) -> &[String]

Return all of the regexes that should be matched for this test. This slice may be empty!

source

pub fn haystack(&self) -> &[u8]

Return the bytes on which the regex should be matched.

source

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.

source

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.

source

pub fn compiles(&self) -> bool

Returns true if the regex(es) in this test are expected to compile.

source

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.

source

pub fn case_insensitive(&self) -> bool

Returns true if regex matching should be performed without regard to case.

source

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.

source

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.

source

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.

source

pub fn match_kind(&self) -> MatchKind

Return the match semantics required by this test.

source

pub fn search_kind(&self) -> SearchKind

Return the search semantics required by this test.

Trait Implementations§

source§

impl Clone for RegexTest

source§

fn clone(&self) -> RegexTest

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 RegexTest

source§

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

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for RegexTest

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,