test_assert_eq

Macro test_assert_eq 

Source
macro_rules! test_assert_eq {
    ($func_name:ident, $arg:expr => $ans:expr) => { ... };
}
Expand description

Generate a test code that internally uses assert_eq!.

The first argument should be the test case name, and the second argument should be the arguments and the expected return value.

Put the arguments to the left of “=>” and the return value to the right of “=>”. And panic if the left is not equal to the right.

§Example

fn add(x: i32, y: i32) -> i32 {
     x + y
}

If you want to test this add function, you can write it as follows

test_macro::test_assert_eq!(test_case_name, add(1, 2) => 3);