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

Side by Side Diff: tests/compiler/dart2js/parser_test.dart

Issue 1151163004: Implementation of null-aware operators. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'parser_helper.dart'; 6 import 'parser_helper.dart';
7 import 'package:compiler/src/tree/tree.dart'; 7 import 'package:compiler/src/tree/tree.dart';
8 8
9 void testStatement(String statement) { 9 void testStatement(String statement) {
10 Node node = parseStatement(statement); 10 Node node = parseStatement(statement);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Should parse as: a ? (b = c) : d. 137 // Should parse as: a ? (b = c) : d.
138 conditional = node.expression; 138 conditional = node.expression;
139 Expect.isNotNull(conditional.thenExpression.asSendSet()); 139 Expect.isNotNull(conditional.thenExpression.asSendSet());
140 Expect.isNull(conditional.elseExpression.asSendSet()); 140 Expect.isNull(conditional.elseExpression.asSendSet());
141 141
142 node = parseStatement("a ? b = c : d = e;"); 142 node = parseStatement("a ? b = c : d = e;");
143 // Should parse as: a ? (b = c) : (d = e). 143 // Should parse as: a ? (b = c) : (d = e).
144 conditional = node.expression; 144 conditional = node.expression;
145 Expect.isNotNull(conditional.thenExpression.asSendSet()); 145 Expect.isNotNull(conditional.thenExpression.asSendSet());
146 Expect.isNotNull(conditional.elseExpression.asSendSet()); 146 Expect.isNotNull(conditional.elseExpression.asSendSet());
147
148 node = parseStatement("a ?? b ? c : d;");
149 // Should parse as: (a ?? b) ? c : d;
150 conditional = node.expression;
151 Expect.isNotNull(conditional.condition.asSend());
152 Expect.isTrue(conditional.condition.asSend().isIfNull);
153 Expect.isNotNull(conditional.thenExpression.asSend());
154 Expect.isNotNull(conditional.elseExpression.asSend());
155 }
156
157 void testNullOperators() {
158 Expression node = parseStatement("a ?? b;").expression;
159 Expect.isNotNull(node.asSend());
160 Expect.isTrue(node.asSend().isIfNull);
161
162 node = parseStatement("a ??= b;").expression;
163 Expect.isNotNull(node.asSendSet());
164 Expect.isTrue(node.asSendSet().isIfNullAssignment);
165
166 node = parseStatement("a?.b;").expression;
167 Expect.isNotNull(node.asSend());
168 Expect.isTrue(node.asSend().isConditional);
169
170 node = parseStatement("a?.m();").expression;
171 Expect.isNotNull(node.asSend());
172 Expect.isTrue(node.asSend().isConditional);
147 } 173 }
148 174
149 void testAssignment() { 175 void testAssignment() {
150 ExpressionStatement node; 176 ExpressionStatement node;
151 Expression expression; 177 Expression expression;
152 SendSet sendSet; 178 SendSet sendSet;
153 179
154 node = parseStatement("a = b;"); 180 node = parseStatement("a = b;");
155 expression = node.expression; 181 expression = node.expression;
156 Expect.isNotNull(expression.asSendSet()); 182 Expect.isNotNull(expression.asSendSet());
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 void main() { 357 void main() {
332 testGenericTypes(); 358 testGenericTypes();
333 // TODO(ahe): Enable this test when we handle library prefixes. 359 // TODO(ahe): Enable this test when we handle library prefixes.
334 // testPrefixedGenericTypes(); 360 // testPrefixedGenericTypes();
335 testUnaryExpression(); 361 testUnaryExpression();
336 testChainedMethodCalls(); 362 testChainedMethodCalls();
337 testFunctionStatement(); 363 testFunctionStatement();
338 testDoStatement(); 364 testDoStatement();
339 testWhileStatement(); 365 testWhileStatement();
340 testConditionalExpression(); 366 testConditionalExpression();
367 testNullOperators();
341 testAssignment(); 368 testAssignment();
342 testIndex(); 369 testIndex();
343 testPostfix(); 370 testPostfix();
344 testOperatorParse(); 371 testOperatorParse();
345 testMissingCloseParen(); 372 testMissingCloseParen();
346 testMissingCloseBraceInClass(); 373 testMissingCloseBraceInClass();
347 testUnmatchedAngleBracket(); 374 testUnmatchedAngleBracket();
348 } 375 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/warnings.dart ('k') | tests/compiler/dart2js_extra/conditional_send_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698