Function equal

Source
pub fn equal<E, T, R>(a: E, b: R)
where E: Debug + Unwrappable<T, R>, E::Output: Debug + PartialEq<R>, R: Debug + PartialEq + PartialEq<T>,
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);
}