enhanced_output/
enhanced_output.rs

1use fluent_test::prelude::*;
2
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}
51
52// Helper function to run an assertion and print the result
53fn print_result<F>(desc: &str, f: F)
54where
55    F: FnOnce() -> bool,
56{
57    println!("\nšŸ” {}", desc);
58    match f() {
59        true => println!("  āœ… Passed"),
60        false => println!("  āŒ Failed (but did not panic)"),
61    }
62}