fluent_test/backend/modifiers/
not.rs

1use crate::backend::Assertion;
2
3/// Not modifier trait for negating assertions
4pub trait NotModifier<T> {
5    /// Creates a negated assertion
6    fn not(self) -> Self;
7}
8
9impl<T: Clone> NotModifier<T> for Assertion<T> {
10    /// Creates a negated assertion
11    /// This provides a fluent API for negated assertions:
12    /// expect(value).not().to_equal(x)
13    fn not(self) -> Self {
14        return Self {
15            value: self.value.clone(),
16            expr_str: self.expr_str,
17            negated: !self.negated,
18            steps: self.steps.clone(),
19            in_chain: self.in_chain, // Preserve chain status
20            is_final: self.is_final, // Preserve finality status
21        };
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use crate::prelude::*;
28
29    #[test]
30    fn test_not_modifier() {
31        // Disable deduplication for tests
32        crate::Reporter::disable_deduplication();
33
34        let value = 42;
35
36        // These should pass
37        expect!(value).not().to_equal(100);
38        expect!(value).not().to_be_less_than(10);
39
40        // Test with chains
41        let chain = expect!(value)
42            .not()
43            .to_be_less_than(30) // "not less than 30" is true for 42
44            .and()
45            .not()
46            .to_be_greater_than(50); // "not greater than 50" is true for 42
47
48        let result = chain.evaluate();
49        assert!(result, "NOT chain with AND should evaluate to true when both conditions are true");
50    }
51}