File tree 1 file changed +84
-0
lines changed
1 file changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ fn main ( ) {
12
+ // test compound assignment operators with ref as right-hand side,
13
+ // for each operator, with various types as operands.
14
+
15
+ // test AddAssign
16
+ {
17
+ let mut x = 3i8 ;
18
+ x += & 2i8 ;
19
+ assert_eq ! ( x, 5i8 ) ;
20
+ }
21
+
22
+ // test SubAssign
23
+ {
24
+ let mut x = 7i16 ;
25
+ x -= & 4 ;
26
+ assert_eq ! ( x, 3i16 ) ;
27
+ }
28
+
29
+ // test MulAssign
30
+ {
31
+ let mut x = 3f32 ;
32
+ x *= & 3f32 ;
33
+ assert_eq ! ( x, 9f32 ) ;
34
+ }
35
+
36
+ // test DivAssign
37
+ {
38
+ let mut x = 6f64 ;
39
+ x /= & 2f64 ;
40
+ assert_eq ! ( x, 3f64 ) ;
41
+ }
42
+
43
+ // test RemAssign
44
+ {
45
+ let mut x = 7i64 ;
46
+ x %= & 4i64 ;
47
+ assert_eq ! ( x, 3i64 ) ;
48
+ }
49
+
50
+ // test BitOrAssign
51
+ {
52
+ let mut x = 0b1010u8 ;
53
+ x |= & 0b1100u8 ;
54
+ assert_eq ! ( x, 0b1110u8 ) ;
55
+ }
56
+
57
+ // test BitAndAssign
58
+ {
59
+ let mut x = 0b1010u16 ;
60
+ x &= & 0b1100u16 ;
61
+ assert_eq ! ( x, 0b1000u16 ) ;
62
+ }
63
+
64
+ // test BitXorAssign
65
+ {
66
+ let mut x = 0b1010u32 ;
67
+ x ^= & 0b1100u32 ;
68
+ assert_eq ! ( x, 0b0110u32 ) ;
69
+ }
70
+
71
+ // test ShlAssign
72
+ {
73
+ let mut x = 0b1010u64 ;
74
+ x <<= & 2u32 ;
75
+ assert_eq ! ( x, 0b101000u64 ) ;
76
+ }
77
+
78
+ // test ShrAssign
79
+ {
80
+ let mut x = 0b1010u64 ;
81
+ x >>= & 2i16 ;
82
+ assert_eq ! ( x, 0b10u64 ) ;
83
+ }
84
+ }
You can’t perform that action at this time.
0 commit comments