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

Side by Side Diff: pkg/analyzer/test/generated/scanner_test.dart

Issue 1043583002: Scanner/parser support for DEP 9 (null-aware operators). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library engine.scanner_test; 5 library engine.scanner_test;
6 6
7 import 'package:analyzer/src/generated/error.dart'; 7 import 'package:analyzer/src/generated/error.dart';
8 import 'package:analyzer/src/generated/scanner.dart'; 8 import 'package:analyzer/src/generated/scanner.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } else { 163 } else {
164 // keyword.substring(0, keyword.length() - 1) 164 // keyword.substring(0, keyword.length() - 1)
165 expect(state, isNotNull); 165 expect(state, isNotNull);
166 } 166 }
167 } 167 }
168 } 168 }
169 } 169 }
170 170
171 @reflectiveTest 171 @reflectiveTest
172 class ScannerTest { 172 class ScannerTest {
173 /**
174 * If non-null, this value is used to override the default value of
175 * [Scanner.enableNullAwareOperators] before scanning.
176 */
177 bool _enableNullAwareOperators;
178
173 void fail_incomplete_string_interpolation() { 179 void fail_incomplete_string_interpolation() {
174 // https://code.google.com/p/dart/issues/detail?id=18073 180 // https://code.google.com/p/dart/issues/detail?id=18073
175 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, 181 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9,
176 "\"foo \${bar", [ 182 "\"foo \${bar", [
177 new StringToken(TokenType.STRING, "\"foo ", 0), 183 new StringToken(TokenType.STRING, "\"foo ", 0),
178 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 5), 184 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 5),
179 new StringToken(TokenType.IDENTIFIER, "bar", 7) 185 new StringToken(TokenType.IDENTIFIER, "bar", 7)
180 ]); 186 ]);
181 } 187 }
182 188
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 } 719 }
714 720
715 void test_plus_plus() { 721 void test_plus_plus() {
716 _assertToken(TokenType.PLUS_PLUS, "++"); 722 _assertToken(TokenType.PLUS_PLUS, "++");
717 } 723 }
718 724
719 void test_question() { 725 void test_question() {
720 _assertToken(TokenType.QUESTION, "?"); 726 _assertToken(TokenType.QUESTION, "?");
721 } 727 }
722 728
729 void test_question_dot() {
730 _enableNullAwareOperators = true;
731 _assertToken(TokenType.QUESTION_PERIOD, "?.");
732 }
733
734 void test_question_question() {
735 _enableNullAwareOperators = true;
736 _assertToken(TokenType.QUESTION_QUESTION, "??");
737 }
738
739 void test_question_question_eq() {
740 _enableNullAwareOperators = true;
741 _assertToken(TokenType.QUESTION_QUESTION_EQ, "??=");
742 }
743
723 void test_scriptTag_withArgs() { 744 void test_scriptTag_withArgs() {
724 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart -debug"); 745 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart -debug");
725 } 746 }
726 747
727 void test_scriptTag_withoutSpace() { 748 void test_scriptTag_withoutSpace() {
728 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart"); 749 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart");
729 } 750 }
730 751
731 void test_scriptTag_withSpace() { 752 void test_scriptTag_withSpace() {
732 _assertToken(TokenType.SCRIPT_TAG, "#! /bin/dart"); 753 _assertToken(TokenType.SCRIPT_TAG, "#! /bin/dart");
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 Token _scan(String source) { 1222 Token _scan(String source) {
1202 GatheringErrorListener listener = new GatheringErrorListener(); 1223 GatheringErrorListener listener = new GatheringErrorListener();
1203 Token token = _scanWithListener(source, listener); 1224 Token token = _scanWithListener(source, listener);
1204 listener.assertNoErrors(); 1225 listener.assertNoErrors();
1205 return token; 1226 return token;
1206 } 1227 }
1207 1228
1208 Token _scanWithListener(String source, GatheringErrorListener listener) { 1229 Token _scanWithListener(String source, GatheringErrorListener listener) {
1209 Scanner scanner = 1230 Scanner scanner =
1210 new Scanner(null, new CharSequenceReader(source), listener); 1231 new Scanner(null, new CharSequenceReader(source), listener);
1232 if (_enableNullAwareOperators != null) {
1233 scanner.enableNullAwareOperators = _enableNullAwareOperators;
1234 }
1211 Token result = scanner.tokenize(); 1235 Token result = scanner.tokenize();
1212 listener.setLineInfo(new TestSource(), scanner.lineStarts); 1236 listener.setLineInfo(new TestSource(), scanner.lineStarts);
1213 return result; 1237 return result;
1214 } 1238 }
1215 } 1239 }
1216 1240
1217 /** 1241 /**
1218 * An `ExpectedLocation` encodes information about the expected location of a 1242 * An `ExpectedLocation` encodes information about the expected location of a
1219 * given offset in source code. 1243 * given offset in source code.
1220 */ 1244 */
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue); 1379 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue);
1356 expect(TokenType.MINUS.isUserDefinableOperator, isTrue); 1380 expect(TokenType.MINUS.isUserDefinableOperator, isTrue);
1357 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue); 1381 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue);
1358 expect(TokenType.PLUS.isUserDefinableOperator, isTrue); 1382 expect(TokenType.PLUS.isUserDefinableOperator, isTrue);
1359 expect(TokenType.SLASH.isUserDefinableOperator, isTrue); 1383 expect(TokenType.SLASH.isUserDefinableOperator, isTrue);
1360 expect(TokenType.STAR.isUserDefinableOperator, isTrue); 1384 expect(TokenType.STAR.isUserDefinableOperator, isTrue);
1361 expect(TokenType.TILDE.isUserDefinableOperator, isTrue); 1385 expect(TokenType.TILDE.isUserDefinableOperator, isTrue);
1362 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue); 1386 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue);
1363 } 1387 }
1364 } 1388 }
OLDNEW
« pkg/analyzer/test/generated/parser_test.dart ('K') | « pkg/analyzer/test/generated/parser_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698