combined_matchers/
combined_matchers.rs1mod common;
2use common::guard_test;
3use rest::prelude::*;
4use std::collections::HashMap;
5
6fn main() {
7 config().enhanced_output(true).apply();
9
10 println!("FluentTest Example: Combined Matchers with Logical Chaining");
11
12 let number = 42;
14 println!("\n--- Numeric assertions ---");
15
16 let success = guard_test(|| {
17 expect!(number).to_be_greater_than(30).and().to_be_less_than(50).and().to_be_even();
18 });
19
20 if success {
21 println!("✅ Verified number is between 30 and 50 and is even.");
22 }
23
24 let greeting = "Hello, World!";
26 println!("\n--- String assertions ---");
27
28 let success = guard_test(|| {
29 expect!(greeting).to_contain("Hello").and().to_start_with("Hello").and().to_have_length(13);
30 });
31
32 if success {
33 println!("✅ Verified greeting contains 'Hello', starts with 'Hello', and has length 13.");
34 }
35
36 let numbers = vec![1, 2, 3, 4, 5];
38 println!("\n--- Collection assertions ---");
39
40 let success = guard_test(|| {
41 expect!(&numbers).to_have_length(5).and().to_contain(3).and().not().to_be_empty();
42 });
43
44 if success {
45 println!("✅ Verified collection has 5 items including 3 and is not empty.");
46 }
47
48 let maybe_value: Option<i32> = Some(42);
50 println!("\n--- Option assertions ---");
51
52 let success = guard_test(|| {
53 expect!(&maybe_value).to_be_some().and().to_contain(&42);
54 });
55
56 if success {
57 println!("✅ Verified Option is Some and contains 42.");
58 }
59
60 let result: Result<i32, &str> = Ok(42);
62 println!("\n--- Result assertions ---");
63
64 let success = guard_test(|| {
65 expect!(&result).to_be_ok().and().to_contain_ok(&42);
66 });
67
68 if success {
69 println!("✅ Verified Result is Ok and contains 42.");
70 }
71
72 let mut map = HashMap::new();
74 map.insert("key1", "value1");
75 map.insert("key2", "value2");
76 println!("\n--- HashMap assertions ---");
77
78 let success = guard_test(|| {
79 expect!(&map).to_have_length(2).and().to_contain_key("key1").and().to_contain_entry("key2", "value2");
80 });
81
82 if success {
83 println!("✅ Verified HashMap has 2 entries with the expected key-value pairs.");
84 }
85
86 println!("\n--- Complex combined assertion ---");
88
89 let success = guard_test(|| {
90 expect!(number).to_be_greater_than(40).and().to_be_less_than(50).or().to_be_even();
91 });
92
93 let success2 = guard_test(|| {
94 expect!(&numbers).not().to_be_empty().and().to_contain(3).or().to_have_length(10);
95 });
96
97 if success && success2 {
98 println!("✅ Verified complex combined assertions with AND, OR, and NOT.");
99 }
100
101 println!("\nAll examples completed successfully!");
102}