Skip to main content

Expect

Enum Expect 

Source
pub enum Expect {
    AtLeast(u64),
    Eq(u64),
    Gt(u64),
    Lt(u64),
}
Expand description

An expectation over a match count, classifying it into a Verdict.

The numeric forms reuse the suite’s [+|-]N threshold grammar (the same + larger-than / - smaller-than / bare at-least convention as ct-search --size), extended with an exact form and two keywords so the common search-as-test assertions read plainly:

SpecPasses when the count isMeaning
any>= 1found something (the default)
none== 0a negative assertion
N>= Nat least N
=N== Nexactly N
+N> Nmore than N
-N< Nfewer than N

any is the default so a plain search gains framing without changing its pass condition: Expect::default().eval(count) is Success exactly when the search matched, reproducing ct-search’s historic 0/1 exit semantics.

§Examples

use coding_tools::verdict::{Expect, Verdict};

// `none` is a negative assertion: passes only when nothing matched.
assert_eq!(Expect::parse("none").unwrap().eval(0), Verdict::Success);
assert_eq!(Expect::parse("none").unwrap().eval(2), Verdict::Error);

// The default `any` passes on one or more.
assert_eq!(Expect::default().eval(0), Verdict::Error);
assert_eq!(Expect::default().eval(3), Verdict::Success);

// Thresholds: bare N is ">= N", =N exact, +N more-than, -N fewer-than.
assert_eq!(Expect::parse("3").unwrap().eval(3), Verdict::Success);
assert_eq!(Expect::parse("=2").unwrap().eval(3), Verdict::Error);
assert_eq!(Expect::parse("+0").unwrap().eval(1), Verdict::Success);
assert_eq!(Expect::parse("-10").unwrap().eval(9), Verdict::Success);

Variants§

§

AtLeast(u64)

>= N — the bare-N and any (>= 1) forms.

§

Eq(u64)

== N — the =N and none (== 0) forms.

§

Gt(u64)

> N — the +N form.

§

Lt(u64)

< N — the -N form.

Implementations§

Source§

impl Expect

Source

pub fn parse(spec: &str) -> Result<Expect, String>

Parse an expectation spec; see the type docs for the grammar.

Source

pub fn eval(self, count: u64) -> Verdict

Classify a match count into a Verdict.

Trait Implementations§

Source§

impl Clone for Expect

Source§

fn clone(&self) -> Expect

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Expect

Source§

impl Debug for Expect

Source§

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

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

impl Default for Expect

Source§

fn default() -> Self

any — pass when at least one entry matched.

Source§

impl Eq for Expect

Source§

impl PartialEq for Expect

Source§

fn eq(&self, other: &Expect) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Expect

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.