mod.rs 2.7 KB

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