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

Side by Side Diff: pkg/front_end/test/token_test.dart

Issue 3007943002: gracefully recover from extraneous top level modifiers (Closed)
Patch Set: revise parseTopLevelDeclaration and address comments Created 3 years, 3 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/messages.yaml ('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
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 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 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:front_end/src/fasta/scanner/string_scanner.dart'; 5 import 'package:front_end/src/fasta/scanner/string_scanner.dart';
6 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; 6 import 'package:front_end/src/fasta/scanner/token.dart' as fasta;
7 import 'package:front_end/src/scanner/token.dart'; 7 import 'package:front_end/src/scanner/token.dart';
8 import 'package:front_end/src/scanner/errors.dart' as analyzer; 8 import 'package:front_end/src/scanner/errors.dart' as analyzer;
9 import 'package:front_end/src/scanner/reader.dart' as analyzer; 9 import 'package:front_end/src/scanner/reader.dart' as analyzer;
10 import 'package:front_end/src/scanner/scanner.dart' as analyzer; 10 import 'package:front_end/src/scanner/scanner.dart' as analyzer;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 Keyword.STATIC, 165 Keyword.STATIC,
166 Keyword.TYPEDEF, 166 Keyword.TYPEDEF,
167 ]); 167 ]);
168 for (Keyword keyword in Keyword.values) { 168 for (Keyword keyword in Keyword.values) {
169 var isBuiltIn = builtInKeywords.contains(keyword); 169 var isBuiltIn = builtInKeywords.contains(keyword);
170 expect(keyword.isBuiltIn, isBuiltIn, reason: keyword.name); 170 expect(keyword.isBuiltIn, isBuiltIn, reason: keyword.name);
171 expect(keyword.isBuiltIn, isBuiltIn, reason: keyword.name); 171 expect(keyword.isBuiltIn, isBuiltIn, reason: keyword.name);
172 } 172 }
173 } 173 }
174 174
175 void test_isModifier() {
176 var modifierKeywords = new Set<Keyword>.from([
177 Keyword.ABSTRACT,
178 Keyword.CONST,
179 Keyword.FINAL,
180 Keyword.STATIC,
181 ]);
182 for (Keyword keyword in Keyword.values) {
183 var isModifier = modifierKeywords.contains(keyword);
184 var scanner = new StringScanner(keyword.lexeme, includeComments: true);
185 Token token = scanner.tokenize();
186 expect(token.isModifier, isModifier, reason: keyword.name);
187 if (isModifier) {
188 expect(token.isTopLevelKeyword, isFalse, reason: keyword.name);
189 }
190 }
191 }
192
193 void test_isTopLevelKeyword() {
194 var topLevelKeywords = new Set<Keyword>.from([
195 Keyword.CLASS,
196 Keyword.ENUM,
197 Keyword.EXPORT,
198 Keyword.IMPORT,
199 Keyword.LIBRARY,
200 Keyword.PART,
201 Keyword.TYPEDEF,
202 ]);
203 for (Keyword keyword in Keyword.values) {
204 var isTopLevelKeyword = topLevelKeywords.contains(keyword);
205 var scanner = new StringScanner(keyword.lexeme, includeComments: true);
206 Token token = scanner.tokenize();
207 expect(token.isTopLevelKeyword, isTopLevelKeyword, reason: keyword.name);
208 if (isTopLevelKeyword) {
209 expect(token.isModifier, isFalse, reason: keyword.name);
210 }
211 }
212 }
213
175 void test_pseudo_keywords() { 214 void test_pseudo_keywords() {
176 var pseudoKeywords = new Set<Keyword>.from([ 215 var pseudoKeywords = new Set<Keyword>.from([
177 Keyword.ASYNC, 216 Keyword.ASYNC,
178 Keyword.AWAIT, 217 Keyword.AWAIT,
179 Keyword.FUNCTION, 218 Keyword.FUNCTION,
180 Keyword.HIDE, 219 Keyword.HIDE,
181 Keyword.NATIVE, 220 Keyword.NATIVE,
182 Keyword.OF, 221 Keyword.OF,
183 Keyword.ON, 222 Keyword.ON,
184 Keyword.PATCH, 223 Keyword.PATCH,
(...skipping 28 matching lines...) Expand all
213 class TestScanner extends analyzer.Scanner { 252 class TestScanner extends analyzer.Scanner {
214 TestScanner(analyzer.CharacterReader reader) : super.create(reader); 253 TestScanner(analyzer.CharacterReader reader) : super.create(reader);
215 254
216 @override 255 @override
217 void reportError( 256 void reportError(
218 analyzer.ScannerErrorCode errorCode, int offset, List<Object> arguments) { 257 analyzer.ScannerErrorCode errorCode, int offset, List<Object> arguments) {
219 fail('Unexpected error $errorCode while scanning offset $offset\n' 258 fail('Unexpected error $errorCode while scanning offset $offset\n'
220 ' arguments: $arguments'); 259 ' arguments: $arguments');
221 } 260 }
222 } 261 }
OLDNEW
« no previous file with comments | « pkg/front_end/messages.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698