Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: tests/language/precedence_test.dart

Issue 2755433004: align fasta.PrecedenceInfo.precedence with analyzer.TokenType.precedence (Closed)
Patch Set: merge Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/front_end/test/scanner_roundtrip_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 // Dart test program to test operation precedence.
5
6 library precedence_test;
7 import "package:expect/expect.dart";
8
9 main() {
10 testBang();
11 testIndexWithPrefixAdd();
12 testIndexWithPostfixAdd();
13 testTilde();
14 testUnaryPrefixWithAdd();
15 testUnaryPostfixWithAdd();
16 testUnaryPrefixWithMultiply();
17 testUnaryPostfixWithMultiply();
18 }
19
20 void testBang() {
21 int x = 3;
22
23 Expect.equals(!true == false, true);
24 Expect.equals(!x.isEven, true);
25 Expect.equals(!(++x).isEven, false);
26 Expect.equals(x, 4);
27 Expect.equals(!(x++).isEven, false);
28 Expect.equals(x, 5);
29 }
30
31 void testIndexWithPrefixAdd() {
32 var x = <int>[3];
33
34 Expect.equals(++x[0] + 3, 7);
35 Expect.equals(x[0], 4);
36 Expect.equals(++x[0] - 3, 2);
37 Expect.equals(x[0], 5);
38 Expect.equals(--x[0] + 4, 8);
39 Expect.equals(x[0], 4);
40 Expect.equals(--x[0] - 4, -1);
41 Expect.equals(x[0], 3);
42
43 Expect.equals(3 + ++x[0], 7);
44 Expect.equals(x[0], 4);
45 Expect.equals(3 - ++x[0], -2);
46 Expect.equals(x[0], 5);
47 Expect.equals(4 + --x[0], 8);
48 Expect.equals(x[0], 4);
49 Expect.equals(4 - --x[0], 1);
50 Expect.equals(x[0], 3);
51 }
52
53 void testIndexWithPostfixAdd() {
54 var x = <int>[3];
55
56 Expect.equals(x[0]++ + 3, 6);
57 Expect.equals(x[0], 4);
58 Expect.equals(x[0]++ - 3, 1);
59 Expect.equals(x[0], 5);
60 Expect.equals(x[0]-- + 4, 9);
61 Expect.equals(x[0], 4);
62 Expect.equals(x[0]-- - 4, 0);
63 Expect.equals(x[0], 3);
64
65 Expect.equals(3 + x[0]++, 6);
66 Expect.equals(x[0], 4);
67 Expect.equals(3 - x[0]++, -1);
68 Expect.equals(x[0], 5);
69 Expect.equals(4 + x[0]--, 9);
70 Expect.equals(x[0], 4);
71 Expect.equals(4 - x[0]--, 0);
72 Expect.equals(x[0], 3);
73 }
74
75 void testTilde() {
76 int x = 3;
77
78 Expect.equals(~x.sign, ~(x.sign));
79 Expect.equals(~x + 7, (~3) + 7);
80
81 Expect.equals(~++x + 7, (~4) + 7);
82 Expect.equals(x, 4);
83 Expect.equals(~x++ + 7, (~4) + 7);
84 Expect.equals(x, 5);
85
86 Expect.equals(~--x + 7, (~4) + 7);
87 Expect.equals(x, 4);
88 Expect.equals(~x-- + 7, (~4) + 7);
89 Expect.equals(x, 3);
90 }
91
92 void testUnaryPrefixWithAdd() {
93 int x = 3;
94
95 Expect.equals(++x + 3, 7);
96 Expect.equals(x, 4);
97 Expect.equals(++x - 3, 2);
98 Expect.equals(x, 5);
99 Expect.equals(--x + 4, 8);
100 Expect.equals(x, 4);
101 Expect.equals(--x - 4, -1);
102 Expect.equals(x, 3);
103
104 Expect.equals(3 + ++x, 7);
105 Expect.equals(x, 4);
106 Expect.equals(3 - ++x, -2);
107 Expect.equals(x, 5);
108 Expect.equals(4 + --x, 8);
109 Expect.equals(x, 4);
110 Expect.equals(4 - --x, 1);
111 Expect.equals(x, 3);
112 }
113
114 void testUnaryPostfixWithAdd() {
115 int x = 3;
116
117 Expect.equals(x++ + 3, 6);
118 Expect.equals(x, 4);
119 Expect.equals(x++ - 3, 1);
120 Expect.equals(x, 5);
121 Expect.equals(x-- + 4, 9);
122 Expect.equals(x, 4);
123 Expect.equals(x-- - 4, 0);
124 Expect.equals(x, 3);
125
126 Expect.equals(3 + x++, 6);
127 Expect.equals(x, 4);
128 Expect.equals(3 - x++, -1);
129 Expect.equals(x, 5);
130 Expect.equals(4 + x--, 9);
131 Expect.equals(x, 4);
132 Expect.equals(4 - x--, 0);
133 Expect.equals(x, 3);
134 }
135
136 void testUnaryPrefixWithMultiply() {
137 int x = 3;
138
139 Expect.equals(++x * 3, 12);
140 Expect.equals(x, 4);
141 Expect.equals(++x / 5, 1.0);
142 Expect.equals(x, 5);
143 Expect.equals(--x * 3, 12);
144 Expect.equals(x, 4);
145 Expect.equals(--x / 4, 0.75);
146 Expect.equals(x, 3);
147
148 Expect.equals(3 * ++x, 12);
149 Expect.equals(x, 4);
150 Expect.equals(5 / ++x, 1.0);
151 Expect.equals(x, 5);
152 Expect.equals(3 * --x, 12);
153 Expect.equals(x, 4);
154 Expect.equals(6 / --x, 2.0);
155 Expect.equals(x, 3);
156 }
157
158 void testUnaryPostfixWithMultiply() {
159 int x = 3;
160
161 Expect.equals(x++ * 3, 9);
162 Expect.equals(x, 4);
163 Expect.equals(x++ / 4, 1.0);
164 Expect.equals(x, 5);
165 Expect.equals(x-- * 3, 15);
166 Expect.equals(x, 4);
167 Expect.equals(x-- / 4, 1.0);
168 Expect.equals(x, 3);
169
170 Expect.equals(3 * x++, 9);
171 Expect.equals(x, 4);
172 Expect.equals(3 / x++, 0.75);
173 Expect.equals(x, 5);
174 Expect.equals(4 * x--, 20);
175 Expect.equals(x, 4);
176 Expect.equals(4 / x--, 1.0);
177 Expect.equals(x, 3);
178 }
179
OLDNEW
« no previous file with comments | « pkg/front_end/test/scanner_roundtrip_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698