pub struct Reporter;
Implementations§
Source§impl Reporter
impl Reporter
Sourcepub fn reset_message_cache()
pub fn reset_message_cache()
Clear the message cache to allow duplicated messages in different test scopes
Sourcepub fn enable_deduplication()
pub fn enable_deduplication()
Enable deduplication of messages
Sourcepub fn disable_deduplication()
pub fn disable_deduplication()
Disable deduplication of messages (for tests)
Sourcepub fn enable_silent_mode()
pub fn enable_silent_mode()
Enable silent mode to suppress intermediate output in chains
Sourcepub fn disable_silent_mode()
pub fn disable_silent_mode()
Disable silent mode to show all output
Sourcepub fn summarize()
pub fn summarize()
Examples found in repository?
examples/basic.rs (line 30)
3fn main() {
4 // Enable enhanced output for this example
5 config().enhanced_output(true).apply();
6
7 // Just to demonstrate the API
8 let x = 42;
9 let name = "Arthur";
10
11 // Integer tests - direct and by reference
12 expect!(x).to_be_greater_than(30);
13 expect!(x).to_be_less_than(50);
14 expect!(x).to_be_even();
15
16 // Create a reference to demonstrate the & removal in output
17 let x_ref = &x;
18 expect!(x_ref).to_equal(&42);
19
20 // String tests - direct and by reference
21 expect!(name).to_contain("th");
22 expect!(name).to_have_length(6);
23
24 // Create a reference to demonstrate the & removal in output
25 let name_ref = &name;
26 let arthur = "Arthur";
27 expect!(name_ref).to_equal(&arthur);
28
29 // Report test results
30 fluent_test::Reporter::summarize();
31}
More examples
examples/modifiers.rs (line 43)
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 fluent_test::Reporter::summarize();
44}
examples/new_matchers.rs (line 54)
4fn main() {
5 // Enable enhanced output for this example
6 config().enhanced_output(true).apply();
7
8 // Boolean matchers
9 let is_enabled = true;
10 expect!(is_enabled).to_be_true();
11 expect!(!is_enabled).to_be_false();
12
13 // Option matchers
14 let maybe_value: Option<i32> = Some(42);
15 expect!(&maybe_value).to_be_some();
16 expect!(&maybe_value).to_contain(&42);
17
18 let empty_option: Option<i32> = None;
19 expect!(&empty_option).to_be_none();
20 expect!(&empty_option).not().to_be_some();
21
22 // Result matchers
23 let success_result: Result<i32, &str> = Ok(42);
24 expect!(&success_result).to_be_ok();
25 expect!(&success_result).to_contain_ok(&42);
26
27 let error_result: Result<i32, &str> = Err("failed");
28 expect!(&error_result).to_be_err();
29 expect!(&error_result).to_contain_err(&"failed");
30
31 // Collection matchers
32 let numbers = vec![1, 2, 3, 4, 5];
33 let numbers_slice = numbers.as_slice();
34 expect!(numbers_slice).to_have_length(5);
35 expect!(numbers_slice).to_contain(3);
36 expect!(numbers_slice).to_contain_all_of(&[1, 5]);
37 expect!(numbers_slice).to_equal_collection(&[1, 2, 3, 4, 5]);
38
39 let empty_vec: Vec<i32> = vec![];
40 let empty_slice = empty_vec.as_slice();
41 expect!(empty_slice).to_be_empty();
42
43 // HashMap matchers
44 let mut user_scores = HashMap::new();
45 user_scores.insert("Alice", 100);
46 user_scores.insert("Bob", 85);
47
48 expect!(&user_scores).to_have_length(2);
49 expect!(&user_scores).to_contain_key("Alice");
50 expect!(&user_scores).to_contain_entry("Bob", &85);
51 expect!(&user_scores).not().to_contain_key("Charlie");
52
53 // Report test results
54 fluent_test::Reporter::summarize();
55}
examples/conjugation.rs (line 48)
3fn main() {
4 // Enable enhanced output for this example
5 config().enhanced_output(true).apply();
6
7 println!("Testing verb conjugation in assertions\n");
8
9 println!("=== Testing singular vs plural variable names ===");
10
11 // Singular variable names
12 let number = 42;
13 let value = 42;
14 let item = "hello";
15 let element = [1, 2, 3];
16
17 expect!(number).to_be_even(); // Should be "number is even"
18 expect!(value).to_be_positive(); // Should be "value is positive"
19 expect!(item).to_have_length(5); // Should be "item has length 5"
20 expect!(&element).to_have_length(3); // Should be "element has length 3"
21
22 // Plural variable names
23 let numbers = vec![1, 2, 3, 4, 5];
24 let values = vec![10, 20, 30];
25 let items = ["a", "b", "c"];
26 let elements = [5, 6, 7];
27
28 expect!(numbers.as_slice()).to_have_length(5); // Should be "numbers have length 5"
29 expect!(values.as_slice()).to_have_length(3); // Should be "values have length 3"
30 expect!(&items).to_contain("b"); // Should be "items contain 'b'"
31 expect!(&elements).to_have_length(3); // Should be "elements have length 3"
32
33 println!("\n=== Testing logical chains ===");
34
35 // Singular with chains
36 expect!(number).to_be_greater_than(30).and().to_be_less_than(50); // Should be "number is greater than 30 AND be less than 50"
37
38 // Plural with chains
39 expect!(numbers.as_slice()).to_have_length(5).and().to_contain(3); // Should be "numbers have length 5 AND contain 3"
40
41 // Mixed cases
42 let user = "John";
43 let users = ["John", "Alice", "Bob"];
44
45 expect!(user).to_equal("John"); // Should be "user is equal to 'John'"
46 expect!(&users).to_contain("Alice"); // Should be "users contain 'Alice'"
47
48 fluent_test::Reporter::summarize();
49}
Auto Trait Implementations§
impl Freeze for Reporter
impl RefUnwindSafe for Reporter
impl Send for Reporter
impl Sync for Reporter
impl Unpin for Reporter
impl UnwindSafe for Reporter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more