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 #[cfg(not(has_i128))] 39 macro_rules! assert_unsigned_scalar_op { 40 ($left:ident $op:tt $right:ident == $expected:expr) => { 41 assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize) 42 $left $op $right == $expected); 43 }; 44 } 45 46 #[cfg(has_i128)] 47 macro_rules! assert_unsigned_scalar_op { 48 ($left:ident $op:tt $right:ident == $expected:expr) => { 49 assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128) 50 $left $op $right == $expected); 51 }; 52 } 53 54 #[cfg(not(has_i128))] 55 macro_rules! assert_signed_scalar_op { 56 ($left:ident $op:tt $right:ident == $expected:expr) => { 57 assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize, 58 to_i8, to_i16, to_i32, to_i64, to_isize) 59 $left $op $right == $expected); 60 }; 61 } 62 63 #[cfg(has_i128)] 64 macro_rules! assert_signed_scalar_op { 65 ($left:ident $op:tt $right:ident == $expected:expr) => { 66 assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128, 67 to_i8, to_i16, to_i32, to_i64, to_isize, to_i128) 68 $left $op $right == $expected); 69 }; 70 } 71 72 /// Assert that an op works for scalar right 73 macro_rules! assert_scalar_assign_op { 74 (($($to:ident),*) $left:ident $op:tt $right:ident == $expected:expr) => { 75 $( 76 if let Some(right) = $right.$to() { 77 let mut left = $left.clone(); 78 assert_eq!({ left $op right; left}, $expected); 79 } 80 )* 81 }; 82 } 83 84 #[cfg(not(has_i128))] 85 macro_rules! assert_unsigned_scalar_assign_op { 86 ($left:ident $op:tt $right:ident == $expected:expr) => { 87 assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize) 88 $left $op $right == $expected); 89 }; 90 } 91 92 #[cfg(has_i128)] 93 macro_rules! assert_unsigned_scalar_assign_op { 94 ($left:ident $op:tt $right:ident == $expected:expr) => { 95 assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128) 96 $left $op $right == $expected); 97 }; 98 } 99 100 #[cfg(not(has_i128))] 101 macro_rules! assert_signed_scalar_assign_op { 102 ($left:ident $op:tt $right:ident == $expected:expr) => { 103 assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, 104 to_i8, to_i16, to_i32, to_i64, to_isize) 105 $left $op $right == $expected); 106 }; 107 } 108 109 #[cfg(has_i128)] 110 macro_rules! assert_signed_scalar_assign_op { 111 ($left:ident $op:tt $right:ident == $expected:expr) => { 112 assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128, 113 to_i8, to_i16, to_i32, to_i64, to_isize, to_i128) 114 $left $op $right == $expected); 115 }; 116 } 117