asserts_rs/
lib.rs

1pub mod debug;
2
3///
4/// ```rust
5/// use asserts_rs::*;
6/// asserts_eq!(1, 1); //OK
7/// asserts_eq!(1, 1, 1); // OK
8/// ```
9/// ```should_panic
10/// use asserts_rs::*;
11/// asserts_eq!(1, 1, 1, 2); // panic 1 not equal to 2
12/// ```
13///
14#[macro_export]
15macro_rules! asserts_eq {
16    ($expresson:expr, $expected:expr) => {
17        assert_eq!($expresson, $expected);
18    };
19
20    ($expresson:expr, $expected:expr, $($others:expr),+) => {
21        assert_eq!($expresson, $expected);
22        asserts_eq!($expresson, $($others),+);
23    };
24}
25
26///
27/// ```rust
28/// use asserts_rs::*;
29/// asserts_ne!(1, 2); //OK
30/// asserts_ne!(1, 2, 3); // OK
31/// ```
32/// ```should_panic
33/// use asserts_rs::*;
34/// asserts_ne!(1, 2, 1, 3); // panic 1 equal to 1
35/// ```
36///
37#[macro_export]
38macro_rules! asserts_ne {
39    ($expresson:expr, $expected:expr) => {
40        assert_ne!($expresson, $expected);
41    };
42
43    ($expresson:expr, $expected:expr, $($others:expr),+) => {
44        assert_ne!($expresson, $expected);
45        asserts_ne!($expresson, $($others),+);
46    };
47}
48
49///
50/// ```rust
51/// use asserts_rs::*;
52/// asserts_eq_one_of!(1, 1); //OK
53/// asserts_eq_one_of!(1, 1, 2); // OK
54/// ```
55/// ```should_panic
56/// use asserts_rs::*;
57/// asserts_eq_one_of!(1, 2, 3); // panic 1 is not equals to any of numbers in (2, 3)s
58/// ```
59///
60#[macro_export]
61macro_rules! asserts_eq_one_of {
62    ($expresson:expr, $expected:expr) => {
63        assert_eq!($expresson, $expected);
64    };
65
66    ($expresson:expr, $expected:expr, $($others:expr),+) => {
67        if ($expresson != $expected) {
68            asserts_eq_one_of!($expresson, $($others),+);
69        } else {
70            assert_eq!($expresson, $expected);
71        }
72    };
73}
74
75///
76/// ```rust
77/// use asserts_rs::*;
78/// asserts_ne_one_of!(1, 2); //OK
79/// asserts_ne_one_of!(1, 2, 3); // OK
80/// ```
81/// ```should_panic
82/// use asserts_rs::*;
83/// asserts_ne_one_of!(1, 1, 1); // panic 1 is equals to all of numbers in (1, 1)
84/// ```
85///
86#[macro_export]
87macro_rules! asserts_ne_one_of {
88    ($expresson:expr, $expected:expr) => {
89        assert_ne!($expresson, $expected);
90    };
91
92    ($expresson:expr, $expected:expr, $($others:expr),+) => {
93        if ($expresson == $expected) {
94            asserts_ne_one_of!($expresson, $($others),+);
95        } else {
96            assert_ne!($expresson, $expected);
97        }
98    };
99}
100
101#[cfg(test)]
102mod tests {
103    use super::*;
104
105    #[test]
106    fn test_asserts_eq() {
107        asserts_eq!(1, 1);
108        asserts_eq!(1, 1, 1);
109    }
110
111    #[test]
112    #[should_panic]
113    fn test_asserts_eq_should_fail() {
114        asserts_eq!(1, 2);
115        asserts_eq!(1, 2, 3);
116    }
117
118    #[test]
119    fn test_asserts_ne() {
120        asserts_ne!(1, 2);
121        asserts_ne!(1, 2, 3);
122    }
123
124    #[test]
125    #[should_panic]
126    fn test_asserts_ne_should_fail() {
127        asserts_ne!(1, 1);
128        asserts_ne!(1, 1, 1);
129    }
130
131    #[test]
132    fn test_asserts_eq_one_of() {
133        asserts_eq_one_of!(1, 1);
134        asserts_eq_one_of!(1, 1, 2);
135    }
136
137    #[test]
138    #[should_panic]
139    fn test_asserts_eq_one_of_should_fail() {
140        asserts_eq_one_of!(1, 2);
141        asserts_eq_one_of!(1, 2, 3);
142    }
143
144    #[test]
145    fn test_asserts_ne_one_of() {
146        asserts_ne_one_of!(1, 2);
147        asserts_ne_one_of!(1, 1, 2);
148        asserts_ne_one_of!(1, 2, 3);
149    }
150
151    #[test]
152    #[should_panic]
153    fn test_asserts_ne_one_of_should_fail() {
154        asserts_ne_one_of!(1, 1);
155        asserts_ne_one_of!(1, 1, 1);
156    }
157}