pub struct Assertion<T> {
pub value: T,
pub expr_str: &'static str,
pub negated: bool,
pub steps: Vec<AssertionStep>,
pub in_chain: bool,
pub is_final: bool,
}
Expand description
Represents the complete assertion with all steps
Fields§
§value: T
The value being tested
expr_str: &'static str
The expression string (variable name)
negated: bool
Whether the current assertion is negated
steps: Vec<AssertionStep>
All steps in the assertion chain
in_chain: bool
Flag to track if this is part of a chain
is_final: bool
Flag to mark the final step in a chain
Implementations§
Source§impl<T> Assertion<T>
impl<T> Assertion<T>
Sourcepub fn add_step(&self, sentence: AssertionSentence, result: bool) -> Selfwhere
T: Clone,
pub fn add_step(&self, sentence: AssertionSentence, result: bool) -> Selfwhere
T: Clone,
Add an assertion step and get back a cloned Assertion for chaining
Sourcepub fn set_last_logic(&mut self, op: LogicalOp)
pub fn set_last_logic(&mut self, op: LogicalOp)
Set the logical operation for the last step
Sourcepub fn mark_as_intermediate(&mut self)
pub fn mark_as_intermediate(&mut self)
Mark this assertion as non-final (intermediate step in a chain)
Sourcepub fn mark_as_final(&mut self)
pub fn mark_as_final(&mut self)
Mark this assertion as final (last step in a chain)
Sourcepub fn calculate_chain_result(&self) -> bool
pub fn calculate_chain_result(&self) -> bool
Calculate if the entire chain passes
Sourcepub fn evaluate(self) -> boolwhere
T: Clone,
pub fn evaluate(self) -> boolwhere
T: Clone,
Explicitly evaluate the assertion chain Returns true if the assertion passed, false otherwise
Examples found in repository?
examples/enhanced_output.rs (line 16)
3fn main() {
4 println!("FluentTest Enhanced Output Example\n");
5
6 // Enable enhanced output for this example
7 config().enhanced_output(true).apply();
8
9 // Use various expectations to show the enhanced formatting
10 println!("Running assertions with enhanced output enabled:");
11
12 // Number assertions
13 let number = 42;
14 print_result("expect!(number).to_be_even()", || {
15 // Call evaluate explicitly to get the boolean result
16 expect!(number).to_be_even().evaluate()
17 });
18
19 print_result("expect!(number).to_be_greater_than(30).and().to_be_less_than(50)", || {
20 expect!(number).to_be_greater_than(30).and().to_be_less_than(50).evaluate()
21 });
22
23 // Failing assertion - use catch_unwind for this since it will panic
24 let result = std::panic::catch_unwind(|| {
25 expect!(number).to_be_greater_than(100);
26 });
27 match result {
28 Ok(_) => println!("\n🔍 expect!(number).to_be_greater_than(100)\n ❌ Failed but did not panic"),
29 Err(e) => {
30 if let Some(s) = e.downcast_ref::<String>() {
31 println!("\n🔍 expect!(number).to_be_greater_than(100)\n ❌ Failed with: {}", s);
32 } else {
33 println!("\n🔍 expect!(number).to_be_greater_than(100)\n ❌ Failed with panic");
34 }
35 }
36 }
37
38 // String assertions
39 let text = "Hello, world!";
40 print_result("expect!(text).to_contain(\"world\")", || expect!(text).to_contain("world").evaluate());
41
42 // Collection assertions
43 let items = vec![1, 2, 3, 4, 5];
44 print_result("expect!(items.as_slice()).to_have_length(5)", || expect!(items.as_slice()).to_have_length(5).evaluate());
45
46 println!("\nNOTE: Without enhanced output enabled (the default), these assertions would");
47 println!(" produce standard Rust assertion messages instead of the detailed ones shown above.");
48 println!("\nUse config().enhanced_output(true).apply() to enable enhanced output in your code,");
49 println!("or set the FLUENT_TEST_ENHANCED_OUTPUT=true environment variable.");
50}
Trait Implementations§
Source§impl<T: Clone> AndModifier<T> for Assertion<T>
impl<T: Clone> AndModifier<T> for Assertion<T>
Source§impl<V> BooleanMatchers for Assertion<V>
impl<V> BooleanMatchers for Assertion<V>
fn to_be_true(self) -> Self
fn to_be_false(self) -> Self
Source§impl<T, V> CollectionMatchers<T> for Assertion<V>
impl<T, V> CollectionMatchers<T> for Assertion<V>
fn to_be_empty(self) -> Self
fn to_have_length(self, expected: usize) -> Self
fn to_contain<U: PartialEq<T> + Debug>(self, expected: U) -> Self
fn to_contain_all_of<U: PartialEq<T> + Debug>(self, expected: &[U]) -> Self
fn to_equal_collection<U: PartialEq<T> + Debug>(self, expected: &[U]) -> Self
Source§impl<V, T> EqualityMatchers<T> for Assertion<V>
impl<V, T> EqualityMatchers<T> for Assertion<V>
Source§impl<M, K, V> HashMapMatchers<K, V> for Assertion<M>
impl<M, K, V> HashMapMatchers<K, V> for Assertion<M>
fn to_be_empty(self) -> Self
fn to_have_length(self, expected: usize) -> Self
fn to_contain_key<Q>(self, key: &Q) -> Self
fn to_contain_entry<Q, R>(self, key: &Q, value: &R) -> Self
Source§impl<T: Clone> NotModifier<T> for Assertion<T>
impl<T: Clone> NotModifier<T> for Assertion<T>
Source§impl<V> NumericMatchers<i32> for Assertion<V>
impl<V> NumericMatchers<i32> for Assertion<V>
fn to_be_positive(self) -> Self
fn to_be_negative(self) -> Self
fn to_be_zero(self) -> Self
fn to_be_greater_than(self, expected: i32) -> Self
fn to_be_greater_than_or_equal(self, expected: i32) -> Self
fn to_be_less_than(self, expected: i32) -> Self
fn to_be_less_than_or_equal(self, expected: i32) -> Self
fn to_be_in_range(self, range: Range<i32>) -> Self
fn to_be_even(self) -> Self
fn to_be_odd(self) -> Self
Source§impl<T, V> OptionMatchers<T> for Assertion<V>
impl<T, V> OptionMatchers<T> for Assertion<V>
fn to_be_some(self) -> Self
fn to_be_none(self) -> Self
fn to_contain(self, expected: &T) -> Selfwhere
T: PartialEq,
Source§impl<T: Clone> OrModifier<T> for Assertion<T>
impl<T: Clone> OrModifier<T> for Assertion<T>
Source§impl<V, T, E> ResultMatchers<T, E> for Assertion<V>
impl<V, T, E> ResultMatchers<T, E> for Assertion<V>
Source§impl<V> StringMatchers for Assertion<V>
impl<V> StringMatchers for Assertion<V>
fn to_be_empty(self) -> Self
fn to_have_length(self, expected: usize) -> Self
Source§fn to_contain(self, substring: &str) -> Self
fn to_contain(self, substring: &str) -> Self
Check if the string contains a substring
Source§fn to_contain_substring(self, substring: &str) -> Self
fn to_contain_substring(self, substring: &str) -> Self
Type-specific version of to_contain to avoid trait conflicts
fn to_start_with(self, prefix: &str) -> Self
fn to_end_with(self, suffix: &str) -> Self
fn to_match(self, pattern: &str) -> Self
Auto Trait Implementations§
impl<T> Freeze for Assertion<T>where
T: Freeze,
impl<T> RefUnwindSafe for Assertion<T>where
T: RefUnwindSafe,
impl<T> Send for Assertion<T>where
T: Send,
impl<T> Sync for Assertion<T>where
T: Sync,
impl<T> Unpin for Assertion<T>where
T: Unpin,
impl<T> UnwindSafe for Assertion<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more