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

Side by Side Diff: pkg/analyzer/test/generated/parser_fasta_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 | « no previous file | pkg/front_end/lib/src/fasta/parser/listener.dart » ('j') | 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:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/token.dart' as analyzer; 6 import 'package:analyzer/dart/ast/token.dart' as analyzer;
7 import 'package:analyzer/dart/ast/token.dart' show TokenType; 7 import 'package:analyzer/dart/ast/token.dart' show TokenType;
8 import 'package:analyzer/error/error.dart'; 8 import 'package:analyzer/error/error.dart';
9 import 'package:analyzer/error/listener.dart' show ErrorReporter; 9 import 'package:analyzer/error/listener.dart' show ErrorReporter;
10 import 'package:analyzer/src/dart/scanner/scanner.dart'; 10 import 'package:analyzer/src/dart/scanner/scanner.dart';
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // TODO(brianwilkerson) Does not recover. 190 // TODO(brianwilkerson) Does not recover.
191 super.test_constAndVar(); 191 super.test_constAndVar();
192 } 192 }
193 193
194 @override 194 @override
195 @failingTest 195 @failingTest
196 void test_constClass() { 196 void test_constClass() {
197 // TODO(brianwilkerson) Wrong errors: 197 // TODO(brianwilkerson) Wrong errors:
198 // Expected 1 errors of type ParserErrorCode.CONST_CLASS, found 0; 198 // Expected 1 errors of type ParserErrorCode.CONST_CLASS, found 0;
199 // 0 errors of type ParserErrorCode.EXTRANEOUS_MODIFIER, found 2 (1, 7) 199 // 0 errors of type ParserErrorCode.EXTRANEOUS_MODIFIER, found 2 (1, 7)
200
201 // TODO(danrubel): Rather than reporting ParserErrorCode.EXTRANEOUS_MODIFIER
202 // report ParserErrorCode.CONST_CLASS to better help the user
200 super.test_constClass(); 203 super.test_constClass();
201 } 204 }
202 205
203 @override 206 @override
204 @failingTest 207 @failingTest
205 void test_constConstructorWithBody() { 208 void test_constConstructorWithBody() {
206 // TODO(brianwilkerson) Wrong errors: 209 // TODO(brianwilkerson) Wrong errors:
207 // Expected 1 errors of type ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, fo und 0 210 // Expected 1 errors of type ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, fo und 0
208 super.test_constConstructorWithBody(); 211 super.test_constConstructorWithBody();
209 } 212 }
210 213
211 @override 214 @override
212 @failingTest 215 @failingTest
213 void test_constEnum() {
214 // TODO(brianwilkerson) Wrong errors:
215 // Expected 1 errors of type ParserErrorCode.CONST_ENUM, found 0;
216 // 0 errors of type ParserErrorCode.EXTRANEOUS_MODIFIER, found 2 (1, 7)
217 super.test_constEnum();
218 }
219
220 @override
221 @failingTest
222 void test_constFactory() { 216 void test_constFactory() {
223 // TODO(brianwilkerson) Wrong errors: 217 // TODO(brianwilkerson) Wrong errors:
224 // Expected 1 errors of type ParserErrorCode.CONST_FACTORY, found 0 218 // Expected 1 errors of type ParserErrorCode.CONST_FACTORY, found 0
225 super.test_constFactory(); 219 super.test_constFactory();
226 } 220 }
227 221
228 @override 222 @override
229 @failingTest 223 @failingTest
230 void test_constMethod() { 224 void test_constMethod() {
231 // TODO(brianwilkerson) Wrong errors: 225 // TODO(brianwilkerson) Wrong errors:
(...skipping 13 matching lines...) Expand all
245 @failingTest 239 @failingTest
246 void test_constructorWithReturnType_var() { 240 void test_constructorWithReturnType_var() {
247 // TODO(brianwilkerson) Wrong errors: 241 // TODO(brianwilkerson) Wrong errors:
248 // Expected 1 errors of type ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, f ound 0; 242 // Expected 1 errors of type ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, f ound 0;
249 // 0 errors of type ParserErrorCode.EXTRANEOUS_MODIFIER, found 1 (0) 243 // 0 errors of type ParserErrorCode.EXTRANEOUS_MODIFIER, found 1 (0)
250 super.test_constructorWithReturnType_var(); 244 super.test_constructorWithReturnType_var();
251 } 245 }
252 246
253 @override 247 @override
254 @failingTest 248 @failingTest
255 void test_constTypedef() {
256 // TODO(brianwilkerson) Wrong errors:
257 // Expected 1 errors of type ParserErrorCode.CONST_TYPEDEF, found 0;
258 // 0 errors of type ParserErrorCode.EXTRANEOUS_MODIFIER, found 2 (1, 7)
259 super.test_constTypedef();
260 }
261
262 @override
263 @failingTest
264 void test_continueOutsideOfLoop_continueInIfStatement() { 249 void test_continueOutsideOfLoop_continueInIfStatement() {
265 // TODO(brianwilkerson) Wrong errors: 250 // TODO(brianwilkerson) Wrong errors:
266 // Expected 1 errors of type ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, found 0 251 // Expected 1 errors of type ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, found 0
267 super.test_continueOutsideOfLoop_continueInIfStatement(); 252 super.test_continueOutsideOfLoop_continueInIfStatement();
268 } 253 }
269 254
270 @override 255 @override
271 @failingTest 256 @failingTest
272 void test_continueOutsideOfLoop_functionExpression_inALoop() { 257 void test_continueOutsideOfLoop_functionExpression_inALoop() {
273 // TODO(brianwilkerson) Wrong errors: 258 // TODO(brianwilkerson) Wrong errors:
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 } 766 }
782 767
783 @override 768 @override
784 @failingTest 769 @failingTest
785 void test_finalAndVar() { 770 void test_finalAndVar() {
786 super.test_finalAndVar(); 771 super.test_finalAndVar();
787 } 772 }
788 773
789 @override 774 @override
790 @failingTest 775 @failingTest
791 void test_finalClass() {
792 super.test_finalClass();
793 }
794
795 @override
796 @failingTest
797 void test_finalConstructor() { 776 void test_finalConstructor() {
798 super.test_finalConstructor(); 777 super.test_finalConstructor();
799 } 778 }
800 779
801 @override 780 @override
802 @failingTest 781 @failingTest
803 void test_finalEnum() {
804 super.test_finalEnum();
805 }
806
807 @override
808 @failingTest
809 void test_finalMethod() { 782 void test_finalMethod() {
810 super.test_finalMethod(); 783 super.test_finalMethod();
811 } 784 }
812 785
813 @override 786 @override
814 @failingTest 787 @failingTest
815 void test_finalTypedef() {
816 super.test_finalTypedef();
817 }
818
819 @override
820 @failingTest
821 void test_functionTypedParameter_const() { 788 void test_functionTypedParameter_const() {
822 super.test_functionTypedParameter_const(); 789 super.test_functionTypedParameter_const();
823 } 790 }
824 791
825 @override 792 @override
826 @failingTest 793 @failingTest
827 void test_functionTypedParameter_final() { 794 void test_functionTypedParameter_final() {
828 super.test_functionTypedParameter_final(); 795 super.test_functionTypedParameter_final();
829 } 796 }
830 797
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 } 1637 }
1671 1638
1672 @override 1639 @override
1673 @failingTest 1640 @failingTest
1674 void test_staticSetterWithoutBody() { 1641 void test_staticSetterWithoutBody() {
1675 super.test_staticSetterWithoutBody(); 1642 super.test_staticSetterWithoutBody();
1676 } 1643 }
1677 1644
1678 @override 1645 @override
1679 @failingTest 1646 @failingTest
1680 void test_staticTopLevelDeclaration_class() {
1681 super.test_staticTopLevelDeclaration_class();
1682 }
1683
1684 @override
1685 @failingTest
1686 void test_staticTopLevelDeclaration_enum() {
1687 super.test_staticTopLevelDeclaration_enum();
1688 }
1689
1690 @override
1691 @failingTest
1692 void test_staticTopLevelDeclaration_function() {
1693 super.test_staticTopLevelDeclaration_function();
1694 }
1695
1696 @override
1697 @failingTest
1698 void test_staticTopLevelDeclaration_typedef() {
1699 super.test_staticTopLevelDeclaration_typedef();
1700 }
1701
1702 @override
1703 @failingTest
1704 void test_staticTopLevelDeclaration_variable() {
1705 super.test_staticTopLevelDeclaration_variable();
1706 }
1707
1708 @override
1709 @failingTest
1710 void test_string_unterminated_interpolation_block() { 1647 void test_string_unterminated_interpolation_block() {
1711 super.test_string_unterminated_interpolation_block(); 1648 super.test_string_unterminated_interpolation_block();
1712 } 1649 }
1713 1650
1714 @override 1651 @override
1715 @failingTest 1652 @failingTest
1716 void test_switchHasCaseAfterDefaultCase() { 1653 void test_switchHasCaseAfterDefaultCase() {
1717 super.test_switchHasCaseAfterDefaultCase(); 1654 super.test_switchHasCaseAfterDefaultCase();
1718 } 1655 }
1719 1656
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
2508 return result; 2445 return result;
2509 } 2446 }
2510 2447
2511 List<ErrorCode> _toFastaGeneratedAnalyzerErrorCodes( 2448 List<ErrorCode> _toFastaGeneratedAnalyzerErrorCodes(
2512 List<ErrorCode> expectedErrorCodes) => 2449 List<ErrorCode> expectedErrorCodes) =>
2513 expectedErrorCodes.map((code) { 2450 expectedErrorCodes.map((code) {
2514 if (code == ParserErrorCode.ABSTRACT_CLASS_MEMBER || 2451 if (code == ParserErrorCode.ABSTRACT_CLASS_MEMBER ||
2515 code == ParserErrorCode.ABSTRACT_ENUM || 2452 code == ParserErrorCode.ABSTRACT_ENUM ||
2516 code == ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION || 2453 code == ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION ||
2517 code == ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE || 2454 code == ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE ||
2518 code == ParserErrorCode.ABSTRACT_TYPEDEF) 2455 code == ParserErrorCode.ABSTRACT_TYPEDEF ||
2456 code == ParserErrorCode.CONST_ENUM ||
2457 code == ParserErrorCode.CONST_TYPEDEF ||
2458 code == ParserErrorCode.FINAL_CLASS ||
2459 code == ParserErrorCode.FINAL_ENUM ||
2460 code == ParserErrorCode.FINAL_TYPEDEF ||
2461 code == ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION)
2519 return ParserErrorCode.EXTRANEOUS_MODIFIER; 2462 return ParserErrorCode.EXTRANEOUS_MODIFIER;
2520 return code; 2463 return code;
2521 }).toList(); 2464 }).toList();
2522 } 2465 }
2523 2466
2524 /** 2467 /**
2525 * Tests of the fasta parser based on [FormalParameterParserTestMixin]. 2468 * Tests of the fasta parser based on [FormalParameterParserTestMixin].
2526 */ 2469 */
2527 @reflectiveTest 2470 @reflectiveTest
2528 class FormalParameterParserTest_Fasta extends FastaParserTestCase 2471 class FormalParameterParserTest_Fasta extends FastaParserTestCase
(...skipping 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after
4313 allowNativeClause = false; 4256 allowNativeClause = false;
4314 test_parseClassDeclaration_native_missing_literal(); 4257 test_parseClassDeclaration_native_missing_literal();
4315 } 4258 }
4316 4259
4317 void test_parseClassDeclaration_native_not_allowed() { 4260 void test_parseClassDeclaration_native_not_allowed() {
4318 allowNativeClause = false; 4261 allowNativeClause = false;
4319 test_parseClassDeclaration_native(); 4262 test_parseClassDeclaration_native();
4320 } 4263 }
4321 4264
4322 @override 4265 @override
4266 void test_parseCompilationUnit_builtIn_asFunctionName() {
4267 //super.test_parseCompilationUnit_builtIn_asFunctionName();
4268
4269 // This is a subset of
4270 // super.test_parseCompilationUnit_builtIn_asFunctionName
4271 // that passes. The remainder are in the
4272 // test_parseCompilationUnit_builtIn_asFunctionName2 method below
4273 parseCompilationUnit('abstract(x) => 0;');
4274 parseCompilationUnit('as(x) => 0;');
4275 parseCompilationUnit('dynamic(x) => 0;');
4276 parseCompilationUnit('external(x) => 0;');
4277 parseCompilationUnit('factory(x) => 0;');
4278 parseCompilationUnit('get(x) => 0;');
4279 parseCompilationUnit('implements(x) => 0;');
4280 parseCompilationUnit('operator(x) => 0;');
4281 parseCompilationUnit('set(x) => 0;');
4282 parseCompilationUnit('static(x) => 0;');
4283 parseCompilationUnit('static(abstract) => 0;');
4284 parseCompilationUnit('typedef(x) => 0;');
4285 }
4286
4323 @failingTest 4287 @failingTest
4324 void test_parseCompilationUnit_abstractAsPrefix_parameterized() { 4288 void test_parseCompilationUnit_builtIn_asFunctionName2() {
4325 // TODO(danrubel): built-in "abstract" cannot be used as a type 4289 // TODO(paulberry,ahe): Fasta's parser is confused when one of the built-in
4326 super.test_parseCompilationUnit_abstractAsPrefix_parameterized(); 4290 // identifiers `export`, `import`, `library`, `part`, or `typedef` appears
4291 // as the name of a top level function with an implicit return type.
4292 parseCompilationUnit('export(x) => 0;');
4293 parseCompilationUnit('import(x) => 0;');
4294 parseCompilationUnit('library(x) => 0;');
4295 parseCompilationUnit('part(x) => 0;');
4327 } 4296 }
4328 4297
4329 @override 4298 @override
4330 @failingTest
4331 void test_parseCompilationUnit_builtIn_asFunctionName() {
4332 // TODO(paulberry,ahe): Fasta's parser is confused when one of the built-in
4333 // identifiers `export`, `import`, `library`, `part`, or `typedef` appears
4334 // as the name of a top level function with an implicit return type.
4335 super.test_parseCompilationUnit_builtIn_asFunctionName();
4336 }
4337
4338 @override
4339 @failingTest 4299 @failingTest
4340 void test_parseCompilationUnit_exportAsPrefix() { 4300 void test_parseCompilationUnit_exportAsPrefix() {
4341 // TODO(paulberry): As of commit 5de9108 this syntax is invalid. 4301 // TODO(paulberry): As of commit 5de9108 this syntax is invalid.
4342 super.test_parseCompilationUnit_exportAsPrefix(); 4302 super.test_parseCompilationUnit_exportAsPrefix();
4343 } 4303 }
4344 4304
4345 @override 4305 @override
4346 @failingTest 4306 @failingTest
4347 void test_parseCompilationUnit_exportAsPrefix_parameterized() { 4307 void test_parseCompilationUnit_exportAsPrefix_parameterized() {
4348 // TODO(paulberry): As of commit 5de9108 this syntax is invalid. 4308 // TODO(paulberry): As of commit 5de9108 this syntax is invalid.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4380 @override 4340 @override
4381 @failingTest 4341 @failingTest
4382 void test_parseDirectives_mixed() { 4342 void test_parseDirectives_mixed() {
4383 // TODO(paulberry,ahe): This test verifies the analyzer parser's ability to 4343 // TODO(paulberry,ahe): This test verifies the analyzer parser's ability to
4384 // stop parsing as soon as the first non-directive is encountered; this is 4344 // stop parsing as soon as the first non-directive is encountered; this is
4385 // useful for quickly traversing an import graph. Consider adding a similar 4345 // useful for quickly traversing an import graph. Consider adding a similar
4386 // ability to Fasta's parser. 4346 // ability to Fasta's parser.
4387 super.test_parseDirectives_mixed(); 4347 super.test_parseDirectives_mixed();
4388 } 4348 }
4389 } 4349 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/parser/listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698