-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathexpression_test.dart
117 lines (101 loc) · 2.68 KB
/
expression_test.dart
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// Tests basic expressions. Does not attempt to validate the details of arithmetic, coercion, and
// so forth.
class ExpressionTest {
ExpressionTest() {}
int foo = -1;
static testMain() {
var test = new ExpressionTest();
test.testBinary();
test.testUnary();
test.testShifts();
test.testBitwise();
test.testIncrement();
test.testMangling();
}
testBinary() {
int x = 4, y = 2;
Expect.equals(6, x + y);
Expect.equals(2, x - y);
Expect.equals(8, x * y);
Expect.equals(2, x / y);
Expect.equals(0, x % y);
}
testUnary() {
int x = 4, y = 2, z = -5;
bool t = true, f = false;
Expect.equals(-4, -x);
Expect.equals(4, ~z);
Expect.equals(f, !t);
}
testShifts() {
int x = 4, y = 2;
Expect.equals(y, x >> 1);
Expect.equals(x, y << 1);
}
testBitwise() {
int x = 4, y = 2;
Expect.equals(6, (x | y));
Expect.equals(0, (x & y));
Expect.equals(6, (x ^ y));
}
int operator [](int index) {
return foo;
}
operator []=(int index, int value) {
foo = value;
}
testIncrement() {
int x = 4, a = x++;
Expect.equals(4, a);
Expect.equals(5, x);
Expect.equals(6, ++x);
Expect.equals(6, x++);
Expect.equals(7, x);
Expect.equals(6, --x);
Expect.equals(6, x--);
Expect.equals(5, x);
this.foo = 0;
Expect.equals(0, this.foo++);
Expect.equals(1, this.foo);
Expect.equals(2, ++this.foo);
Expect.equals(2, this.foo);
Expect.equals(2, this.foo--);
Expect.equals(1, this.foo);
Expect.equals(0, --this.foo);
Expect.equals(0, this.foo);
Expect.equals(0, this[0]++);
Expect.equals(1, this[0]);
Expect.equals(2, ++this[0]);
Expect.equals(2, this[0]);
Expect.equals(2, this[0]--);
Expect.equals(1, this[0]);
Expect.equals(0, --this[0]);
Expect.equals(0, this[0]);
int $0 = 42, $1 = 87, $2 = 117;
Expect.equals(42, $0++);
Expect.equals(43, $0);
Expect.equals(44, ++$0);
Expect.equals(88, $0 += $0);
Expect.equals(87, $1++);
Expect.equals(88, $1);
Expect.equals(89, ++$1);
Expect.equals(178, ($1 += $1));
Expect.equals(117, $2++);
Expect.equals(118, $2);
Expect.equals(119, ++$2);
}
void testMangling() {
int $0 = 42, $1 = 87, $2 = 117;
this[0] = 0;
Expect.equals(42, (this[0] += $0));
Expect.equals(129, (this[0] += $1));
Expect.equals(246, (this[0] += $2));
}
}
main() {
ExpressionTest.testMain();
}