1 #![allow(unused)]
2 
3 /// Assert that an op works for all val/ref combinations
4 macro_rules! assert_op {
5     ($left:ident $op:tt $right:ident == $expected:expr) => {
6         assert_eq!((&$left) $op (&$right), $expected);
7         assert_eq!((&$left) $op $right.clone(), $expected);
8         assert_eq!($left.clone() $op (&$right), $expected);
9         assert_eq!($left.clone() $op $right.clone(), $expected);
10     };
11 }
12 
13 /// Assert that an assign-op works for all val/ref combinations
14 macro_rules! assert_assign_op {
15     ($left:ident $op:tt $right:ident == $expected:expr) => {{
16         let mut left = $left.clone();
17         assert_eq!({ left $op &$right; left}, $expected);
18 
19         let mut left = $left.clone();
20         assert_eq!({ left $op $right.clone(); left}, $expected);
21     }};
22 }
23 
24 /// Assert that an op works for scalar left or right
25 macro_rules! assert_scalar_op {
26     (($($to:ident),*) $left:ident $op:tt $right:ident == $expected:expr) => {
27         $(
28             if let Some(left) = $left.$to() {
29                 assert_op!(left $op $right == $expected);
30             }
31             if let Some(right) = $right.$to() {
32                 assert_op!($left $op right == $expected);
33             }
34         )*
35     };
36 }
37 
38 macro_rules! assert_unsigned_scalar_op {
39     ($left:ident $op:tt $right:ident == $expected:expr) => {
40         assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128)
41                           $left $op $right == $expected);
42     };
43 }
44 
45 macro_rules! assert_signed_scalar_op {
46     ($left:ident $op:tt $right:ident == $expected:expr) => {
47         assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128,
48                            to_i8, to_i16, to_i32, to_i64, to_isize, to_i128)
49                           $left $op $right == $expected);
50     };
51 }
52 
53 /// Assert that an op works for scalar right
54 macro_rules! assert_scalar_assign_op {
55     (($($to:ident),*) $left:ident $op:tt $right:ident == $expected:expr) => {
56         $(
57             if let Some(right) = $right.$to() {
58                 let mut left = $left.clone();
59                 assert_eq!({ left $op right; left}, $expected);
60             }
61         )*
62     };
63 }
64 
65 macro_rules! assert_unsigned_scalar_assign_op {
66     ($left:ident $op:tt $right:ident == $expected:expr) => {
67         assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128)
68                                  $left $op $right == $expected);
69     };
70 }
71 
72 macro_rules! assert_signed_scalar_assign_op {
73     ($left:ident $op:tt $right:ident == $expected:expr) => {
74         assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128,
75                                   to_i8, to_i16, to_i32, to_i64, to_isize, to_i128)
76                                  $left $op $right == $expected);
77     };
78 }
79