fluent_test/backend/modifiers/or.rs
1use crate::backend::Assertion;
2use crate::backend::LogicalOp;
3
4/// OR modifier trait for chaining assertions
5pub trait OrModifier<T> {
6 /// Creates an OR-chained assertion that allows for multiple assertions on the same value
7 /// This provides a fluent API for alternative assertions:
8 /// expect(value).to_be_greater_than(100).or().to_be_less_than(0)
9 fn or(self) -> Self;
10}
11
12impl<T: Clone> OrModifier<T> for Assertion<T> {
13 /// Returns a new Assertion with the same value, allowing for OR chaining assertions
14 fn or(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::Or);
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 'or()'
29 };
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use crate::prelude::*;
36
37 #[test]
38 fn test_or_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(100).or().to_be_less_than(100);
46 }
47}