modifiers/
modifiers.rs

1mod common;
2use common::guard_test;
3use rest::prelude::*;
4
5fn main() {
6    // Enable enhanced output for this example
7    config().enhanced_output(true).apply();
8
9    println!("\n=== Testing AND modifier (all true) ===");
10    let number = 42;
11    // Using AND modifier with both conditions true
12    expect!(number).to_be_greater_than(30).and().to_be_less_than(50);
13
14    println!("\n=== Testing complex AND chain (passing) ===");
15    // Complex chain with multiple AND conditions
16    expect!(number).to_be_even().and().to_be_positive();
17
18    println!("\n=== Testing failing OR chain with passing part ===");
19    // Using OR modifier (will pass if any condition is true)
20    expect!(number).to_be_greater_than(50).or().to_be_less_than(30).or().to_equal(42);
21
22    println!("\n=== Testing OR chain (all false) ===");
23    // All conditions fail - should report failure and handle the panic
24    let success = guard_test(|| {
25        expect!(number).to_be_greater_than(50).or().to_be_less_than(30).or().to_be_greater_than(100);
26    });
27
28    if !success {
29        println!("Test failed as expected (all conditions were false)");
30    }
31
32    println!("\n=== Testing combined NOT with AND ===");
33    // Combining AND and OR with NOT
34    expect!(number).not().to_be_less_than(30).and().not().to_be_greater_than(50);
35
36    println!("\n=== Testing string matchers with AND ===");
37    // String example
38    let name = "Arthur";
39    expect!(name).to_contain("th").and().to_have_length(6).and().not().to_be_empty();
40
41    // Report test results
42    println!("\n=== Test Summary ===");
43    rest::Reporter::summarize();
44}