Debian Codegraph @

tests/arith_assign.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 #![cfg(op_assign)]
11 #![recursion_limit = "128"]
12 #[macro_use] extern crate custom_derive;
13 #[macro_use] extern crate newtype_derive;
14
15 custom_derive! {
16 #[derive(Copy, Clone, Eq, PartialEq, Debug,
17 NewtypeAddAssign, NewtypeAddAssign(&Self), NewtypeAddAssign(i32),
18 NewtypeBitAndAssign, NewtypeBitAndAssign(&Self),
19 NewtypeBitOrAssign, NewtypeBitOrAssign(&Self),
20 NewtypeBitXorAssign, NewtypeBitXorAssign(&Self),
21 NewtypeDivAssign, NewtypeDivAssign(&Self),
22 NewtypeMulAssign, NewtypeMulAssign(&Self),
23 NewtypeRemAssign, NewtypeRemAssign(&Self),
24 NewtypeSubAssign, NewtypeSubAssign(&Self),
25 NewtypeShlAssign, NewtypeShlAssign(&Self), NewtypeShlAssign(i32),
26 NewtypeShrAssign, NewtypeShrAssign(&Self), NewtypeShrAssign(i32),
27 NewtypeFrom
28 )]
29 pub struct Dummy(i32);
30 }
31
32 macro_rules! oa {
33 (@as_stmt $s:stmt) => { $s };
34
35 ($var:ident $op:tt $rhs:expr) => {
36 {
37 let mut $var = $var;
38 oa!(@as_stmt $var $op $rhs);
39 $var
40 }
41 };
42 }
43
44 #[test]
45 fn test_arith_assign() {
46 let a = Dummy::from(4);
47 let b = Dummy::from(7);
48
49 assert_eq!(oa!(a += b), Dummy::from(4 + 7));
50 assert_eq!(oa!(a += &b), Dummy::from(4 + 7));
51
52 assert_eq!(oa!(a += b), Dummy::from(4 + 7));
53 assert_eq!(oa!(a += &b), Dummy::from(4 + 7));
54 assert_eq!(oa!(a += 7), Dummy::from(4 + 7));
55 assert_eq!(oa!(a += 7), Dummy::from(4 + 7));
56 assert_eq!(oa!(a &= b), Dummy::from(4 & 7));
57 assert_eq!(oa!(a &= &b), Dummy::from(4 & 7));
58 assert_eq!(oa!(a |= b), Dummy::from(4 | 7));
59 assert_eq!(oa!(a |= &b), Dummy::from(4 | 7));
60 assert_eq!(oa!(a ^= b), Dummy::from(4 ^ 7));
61 assert_eq!(oa!(a ^= &b), Dummy::from(4 ^ 7));
62 assert_eq!(oa!(a /= b), Dummy::from(4 / 7));
63 assert_eq!(oa!(a /= &b), Dummy::from(4 / 7));
64 assert_eq!(oa!(a *= b), Dummy::from(4 * 7));
65 assert_eq!(oa!(a *= &b), Dummy::from(4 * 7));
66 assert_eq!(oa!(a %= b), Dummy::from(4 % 7));
67 assert_eq!(oa!(a %= &b), Dummy::from(4 % 7));
68 assert_eq!(oa!(a -= b), Dummy::from(4 - 7));
69 assert_eq!(oa!(a -= &b), Dummy::from(4 - 7));
70
71 assert_eq!(oa!(a <<= b), Dummy::from(4 << 7));
72 assert_eq!(oa!(a <<= &b), Dummy::from(4 << 7));
73 assert_eq!(oa!(a <<= 7), Dummy::from(4 << 7));
74
75 assert_eq!(oa!(a >>= b), Dummy::from(4 >> 7));
76 assert_eq!(oa!(a >>= &b), Dummy::from(4 >> 7));
77 assert_eq!(oa!(a >>= 7), Dummy::from(4 >> 7));
78 }