fluent_test/backend/modifiers/and.rs
1use crate::backend::Assertion;
2use crate::backend::LogicalOp;
3
4/// AND modifier trait for chaining assertions
5pub trait AndModifier<T> {
6 /// Creates an AND-chained assertion that allows for multiple assertions on the same value
7 /// This provides a fluent API for multiple assertions:
8 /// expect(value).to_be_greater_than(5).and().to_be_less_than(10)
9 fn and(self) -> Self;
10}
11
12impl<T: Clone> AndModifier<T> for Assertion<T> {
13 /// Returns a new Assertion with the same value, allowing for chaining assertions
14 fn and(self) -> Self {
15 // The previous assertion was intermediate (not final)
16 let mut result = self;
17 result.mark_as_intermediate();
18
19 // Set the logical operator for the last step
20 result.set_last_logic(LogicalOp::And);
21
22 return Self {
23 value: result.value.clone(),
24 expr_str: result.expr_str,
25 negated: result.negated,
26 steps: result.steps.clone(),
27 in_chain: true, // Always mark as part of a chain
28 is_final: false, // This is not the final step - there will be more after 'and()'
29 };
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use crate::prelude::*;
36
37 #[test]
38 fn test_and_modifier() {
39 // Disable deduplication for tests
40 crate::Reporter::disable_deduplication();
41
42 let value = 42;
43
44 // Simple test that doesn't trigger thread-local issues
45 expect!(value).to_be_greater_than(30).and().to_be_less_than(50);
46 }
47}