Debian Codegraph @

tests/arith.rs

raw symbols SCIP
1 /*
2 Copyright ⓒ 2015 rust-custom-derive contributors.
3
4 Licensed under the MIT license (see LICENSE or <http://opensource.org
5 /licenses/MIT>) or the Apache License, Version 2.0 (see LICENSE of
6 <http://www.apache.org/licenses/LICENSE-2.0>), at your option. All
7 files in the project carrying such notice may not be copied, modified,
8 or distributed except according to those terms.
9 */
10 #![recursion_limit = "128"]
11 #[macro_use] extern crate custom_derive;
12 #[macro_use] extern crate newtype_derive;
13
14 custom_derive! {
15 #[derive(Copy, Clone, Eq, PartialEq, Debug,
16 NewtypeAdd, NewtypeAdd(&self), NewtypeAdd(i32), NewtypeAdd(&self, i32),
17 NewtypeBitAnd, NewtypeBitAnd(&self),
18 NewtypeBitOr, NewtypeBitOr(&self),
19 NewtypeBitXor, NewtypeBitXor(&self),
20 NewtypeDiv, NewtypeDiv(&self),
21 NewtypeMul, NewtypeMul(&self),
22 NewtypeRem, NewtypeRem(&self),
23 NewtypeSub, NewtypeSub(&self),
24
25 NewtypeShl(), NewtypeShl(&self), NewtypeShl(usize), NewtypeShl(&self, usize),
26 NewtypeShr(), NewtypeShr(&self), NewtypeShr(usize), NewtypeShr(&self, usize),
27
28 NewtypeNeg, NewtypeNeg(&self),
29 NewtypeNot, NewtypeNot(&self),
30
31 NewtypeFrom
32 )]
33 pub struct Dummy(i32);
34 }
35
36 #[test]
37 fn test_arith() {
38 let a = Dummy::from(4);
39 let b = Dummy::from(7);
40
41 assert_eq!(a + b, Dummy::from(4 + 7));
42 assert_eq!(&a + &b, Dummy::from(4 + 7));
43 assert_eq!(a + 7, Dummy::from(4 + 7));
44 assert_eq!(&a + 7, Dummy::from(4 + 7));
45 assert_eq!(a & b, Dummy::from(4 & 7));
46 assert_eq!(&a & &b, Dummy::from(4 & 7));
47 assert_eq!(a | b, Dummy::from(4 | 7));
48 assert_eq!(&a | &b, Dummy::from(4 | 7));
49 assert_eq!(a ^ b, Dummy::from(4 ^ 7));
50 assert_eq!(&a ^ &b, Dummy::from(4 ^ 7));
51 assert_eq!(a / b, Dummy::from(4 / 7));
52 assert_eq!(&a / &b, Dummy::from(4 / 7));
53 assert_eq!(a * b, Dummy::from(4 * 7));
54 assert_eq!(&a * &b, Dummy::from(4 * 7));
55 assert_eq!(a % b, Dummy::from(4 % 7));
56 assert_eq!(&a % &b, Dummy::from(4 % 7));
57 assert_eq!(a - b, Dummy::from(4 - 7));
58 assert_eq!(&a - &b, Dummy::from(4 - 7));
59
60 assert_eq!(a << b, Dummy::from(4 << 7));
61 assert_eq!(&a << &b, Dummy::from(4 << 7));
62 assert_eq!(a << 7, Dummy::from(4 << 7));
63
64 assert_eq!(a >> b, Dummy::from(4 >> 7));
65 assert_eq!(&a >> &b, Dummy::from(4 >> 7));
66 assert_eq!(a >> 7, Dummy::from(4 >> 7));
67
68 assert_eq!(-a, Dummy::from(-4));
69 assert_eq!(-&a, Dummy::from(-4));
70 assert_eq!(!a, Dummy::from(!4));
71 assert_eq!(!&a, Dummy::from(!4));
72 }