File: mod.rs

package info (click to toggle)
rust-num-bigint 0.4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 664 kB
  • sloc: makefile: 4
file content (78 lines) | stat: -rw-r--r-- 2,766 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#![allow(unused)]

/// Assert that an op works for all val/ref combinations
macro_rules! assert_op {
    ($left:ident $op:tt $right:ident == $expected:expr) => {
        assert_eq!((&$left) $op (&$right), $expected);
        assert_eq!((&$left) $op $right.clone(), $expected);
        assert_eq!($left.clone() $op (&$right), $expected);
        assert_eq!($left.clone() $op $right.clone(), $expected);
    };
}

/// Assert that an assign-op works for all val/ref combinations
macro_rules! assert_assign_op {
    ($left:ident $op:tt $right:ident == $expected:expr) => {{
        let mut left = $left.clone();
        assert_eq!({ left $op &$right; left}, $expected);

        let mut left = $left.clone();
        assert_eq!({ left $op $right.clone(); left}, $expected);
    }};
}

/// Assert that an op works for scalar left or right
macro_rules! assert_scalar_op {
    (($($to:ident),*) $left:ident $op:tt $right:ident == $expected:expr) => {
        $(
            if let Some(left) = $left.$to() {
                assert_op!(left $op $right == $expected);
            }
            if let Some(right) = $right.$to() {
                assert_op!($left $op right == $expected);
            }
        )*
    };
}

macro_rules! assert_unsigned_scalar_op {
    ($left:ident $op:tt $right:ident == $expected:expr) => {
        assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128)
                          $left $op $right == $expected);
    };
}

macro_rules! assert_signed_scalar_op {
    ($left:ident $op:tt $right:ident == $expected:expr) => {
        assert_scalar_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128,
                           to_i8, to_i16, to_i32, to_i64, to_isize, to_i128)
                          $left $op $right == $expected);
    };
}

/// Assert that an op works for scalar right
macro_rules! assert_scalar_assign_op {
    (($($to:ident),*) $left:ident $op:tt $right:ident == $expected:expr) => {
        $(
            if let Some(right) = $right.$to() {
                let mut left = $left.clone();
                assert_eq!({ left $op right; left}, $expected);
            }
        )*
    };
}

macro_rules! assert_unsigned_scalar_assign_op {
    ($left:ident $op:tt $right:ident == $expected:expr) => {
        assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128)
                                 $left $op $right == $expected);
    };
}

macro_rules! assert_signed_scalar_assign_op {
    ($left:ident $op:tt $right:ident == $expected:expr) => {
        assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128,
                                  to_i8, to_i16, to_i32, to_i64, to_isize, to_i128)
                                 $left $op $right == $expected);
    };
}