Function common_testing::assert::equal

source ·
pub fn equal<E, R>(a: E, b: R)
where E: Debug + Unwrappable<R>, R: Debug + PartialEq,
Expand description

Asserts two values are equal using PartialEq, allowing for different types to be compared. Automatically unwraps Result and Option, failing the test if the value is Err or None. This is useful for removing boilerplate .unwrap().unwrap() calls in tests.

Error message will show the values that were compared using pretty_assertions crate.

Example

use common_testing::assert;

#[test]
fn test_1() {
  let result = "abc";
  equal(result, "abc");
  equal(&result, &"abc");
  equal(5, 5);
  equal(&5, &5);
  equal(Result::Ok(5), 5);
  equal(Option::Some(5), 5);
  equal(Result::Ok(Option::Some(5)), 5);
  equal(Option::Some(Result::Ok(5)), 5);
}