sweet/matchers/
matcher_eq.rs1use super::*;
2use std::fmt::Debug;
3
4#[extend::ext(name=SweetEq)]
5pub impl<T> T
6where
7 T: Debug,
8{
9 fn xpect_eq<U>(&self, expected: U) -> &Self
22 where
23 T: PartialEq<U>,
24 U: Debug,
25 {
26 if self != &expected {
27 assert_ext::panic_expected_received_debug(expected, self);
28 }
29 self
30 }
31 fn xpect_not_eq<U>(&self, expected: U) -> &Self
44 where
45 T: PartialEq<U>,
46 U: Debug,
47 {
48 if self == &expected {
49 assert_ext::panic_expected_received_display_debug(
50 format!("NOT {:?}", expected),
51 self,
52 );
53 }
54 self
55 }
56}
57
58#[cfg(test)]
59mod test {
60 use crate::prelude::*;
61
62 #[test]
63 fn equality() {
64 true.xpect_eq(true);
65 (&true).xpect_eq(true);
66
67 "foo".xpect_eq("foo");
68 "foo".to_string().xpect_eq("foo");
69
70 "foo".xpect_not_eq("bar".to_string());
71 "foo".to_string().xpect_not_eq("bar");
72 }
73}