| OLD | NEW |
| 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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/error/error.dart'; | 9 import 'package:analyzer/error/error.dart'; |
| 10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 void set enableNnbd(bool value); | 51 void set enableNnbd(bool value); |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Set a flag indicating whether the parser is to parse part-of directives | 54 * Set a flag indicating whether the parser is to parse part-of directives |
| 55 * that specify a URI rather than a library name. | 55 * that specify a URI rather than a library name. |
| 56 */ | 56 */ |
| 57 void set enableUriInPartOf(bool value); | 57 void set enableUriInPartOf(bool value); |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * The error listener to which scanner and parser errors will be reported. |
| 61 * |
| 62 * This field is typically initialized by invoking [createParser]. |
| 63 */ |
| 64 GatheringErrorListener get listener; |
| 65 |
| 66 /** |
| 60 * Get the parser used by the test. | 67 * Get the parser used by the test. |
| 61 * | 68 * |
| 62 * Caller must first invoke [createParser]. | 69 * Caller must first invoke [createParser]. |
| 63 */ | 70 */ |
| 64 Parser get parser; | 71 Parser get parser; |
| 65 | 72 |
| 66 /** | 73 /** |
| 67 * Flag indicating whether the fasta parser is being used. | 74 * Flag indicating whether the fasta parser is being used. |
| 68 */ | 75 */ |
| 69 bool get usingFastaParser; | 76 bool get usingFastaParser; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 82 /** | 89 /** |
| 83 * Asserts that no errors occurred during parsing. | 90 * Asserts that no errors occurred during parsing. |
| 84 */ | 91 */ |
| 85 void assertNoErrors(); | 92 void assertNoErrors(); |
| 86 | 93 |
| 87 /** | 94 /** |
| 88 * Prepares to parse using tokens scanned from the given [content] string. | 95 * Prepares to parse using tokens scanned from the given [content] string. |
| 89 */ | 96 */ |
| 90 void createParser(String content); | 97 void createParser(String content); |
| 91 | 98 |
| 99 void expectNotNullIfNoErrors(Object result); |
| 100 |
| 92 Expression parseAdditiveExpression(String code); | 101 Expression parseAdditiveExpression(String code); |
| 93 | 102 |
| 94 Expression parseAssignableExpression(String code, bool primaryAllowed); | 103 Expression parseAssignableExpression(String code, bool primaryAllowed); |
| 95 | 104 |
| 96 Expression parseAssignableSelector(String code, bool optional, | 105 Expression parseAssignableSelector(String code, bool optional, |
| 97 {bool allowConditional: true}); | 106 {bool allowConditional: true}); |
| 98 | 107 |
| 99 AwaitExpression parseAwaitExpression(String code); | 108 AwaitExpression parseAwaitExpression(String code); |
| 100 | 109 |
| 101 Expression parseBitwiseAndExpression(String code); | 110 Expression parseBitwiseAndExpression(String code); |
| (...skipping 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2035 invocation3.function); | 2044 invocation3.function); |
| 2036 expect(invocation4.methodName.name, "a"); | 2045 expect(invocation4.methodName.name, "a"); |
| 2037 expect(invocation4.typeArguments, isNotNull); | 2046 expect(invocation4.typeArguments, isNotNull); |
| 2038 ArgumentList argumentList4 = invocation4.argumentList; | 2047 ArgumentList argumentList4 = invocation4.argumentList; |
| 2039 expect(argumentList4, isNotNull); | 2048 expect(argumentList4, isNotNull); |
| 2040 expect(argumentList4.arguments, hasLength(1)); | 2049 expect(argumentList4.arguments, hasLength(1)); |
| 2041 } | 2050 } |
| 2042 } | 2051 } |
| 2043 | 2052 |
| 2044 /** | 2053 /** |
| 2045 * The class `ErrorParserTest` defines parser tests that test the parsing of cod
e to ensure | 2054 * The class `ErrorParserTest` defines parser tests that test the parsing |
| 2046 * that errors are correctly reported, and in some cases, not reported. | 2055 * of code to ensure that errors are correctly reported, |
| 2056 * and in some cases, not reported. |
| 2047 */ | 2057 */ |
| 2048 @reflectiveTest | 2058 @reflectiveTest |
| 2049 class ErrorParserTest extends ParserTestCase { | 2059 class ErrorParserTest extends ParserTestCase with ErrorParserTestMixin {} |
| 2060 |
| 2061 abstract class ErrorParserTestMixin implements AbstractParserTestCase { |
| 2050 void test_abstractClassMember_constructor() { | 2062 void test_abstractClassMember_constructor() { |
| 2051 createParser('abstract C.c();'); | 2063 createParser('abstract C.c();'); |
| 2052 ClassMember member = parser.parseClassMember('C'); | 2064 ClassMember member = parser.parseClassMember('C'); |
| 2053 expectNotNullIfNoErrors(member); | 2065 expectNotNullIfNoErrors(member); |
| 2054 listener.assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]); | 2066 listener.assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]); |
| 2055 } | 2067 } |
| 2056 | 2068 |
| 2057 void test_abstractClassMember_field() { | 2069 void test_abstractClassMember_field() { |
| 2058 createParser('abstract C f;'); | 2070 createParser('abstract C f;'); |
| 2059 ClassMember member = parser.parseClassMember('C'); | 2071 ClassMember member = parser.parseClassMember('C'); |
| (...skipping 6239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8299 * in type names. | 8311 * in type names. |
| 8300 */ | 8312 */ |
| 8301 bool enableNnbd = false; | 8313 bool enableNnbd = false; |
| 8302 | 8314 |
| 8303 /** | 8315 /** |
| 8304 * A flag indicating whether the parser is to parse part-of directives that | 8316 * A flag indicating whether the parser is to parse part-of directives that |
| 8305 * specify a URI rather than a library name. | 8317 * specify a URI rather than a library name. |
| 8306 */ | 8318 */ |
| 8307 bool enableUriInPartOf = false; | 8319 bool enableUriInPartOf = false; |
| 8308 | 8320 |
| 8309 /** | 8321 @override |
| 8310 * The error listener to which scanner and parser errors will be reported. | |
| 8311 * | |
| 8312 * This field is typically initialized by invoking [createParser]. | |
| 8313 */ | |
| 8314 GatheringErrorListener listener; | 8322 GatheringErrorListener listener; |
| 8315 | 8323 |
| 8316 /** | 8324 /** |
| 8317 * The parser used by the test. | 8325 * The parser used by the test. |
| 8318 * | 8326 * |
| 8319 * This field is typically initialized by invoking [createParser]. | 8327 * This field is typically initialized by invoking [createParser]. |
| 8320 */ | 8328 */ |
| 8321 Parser parser; | 8329 Parser parser; |
| 8322 | 8330 |
| 8323 @override | 8331 @override |
| (...skipping 30 matching lines...) Expand all Loading... |
| 8354 // | 8362 // |
| 8355 parser = new Parser(source, listener); | 8363 parser = new Parser(source, listener); |
| 8356 parser.enableAssertInitializer = enableAssertInitializer; | 8364 parser.enableAssertInitializer = enableAssertInitializer; |
| 8357 parser.parseGenericMethodComments = enableGenericMethodComments; | 8365 parser.parseGenericMethodComments = enableGenericMethodComments; |
| 8358 parser.parseFunctionBodies = parseFunctionBodies; | 8366 parser.parseFunctionBodies = parseFunctionBodies; |
| 8359 parser.enableNnbd = enableNnbd; | 8367 parser.enableNnbd = enableNnbd; |
| 8360 parser.enableUriInPartOf = enableUriInPartOf; | 8368 parser.enableUriInPartOf = enableUriInPartOf; |
| 8361 parser.currentToken = tokenStream; | 8369 parser.currentToken = tokenStream; |
| 8362 } | 8370 } |
| 8363 | 8371 |
| 8372 @override |
| 8364 void expectNotNullIfNoErrors(Object result) { | 8373 void expectNotNullIfNoErrors(Object result) { |
| 8365 if (!listener.hasErrors) { | 8374 if (!listener.hasErrors) { |
| 8366 expect(result, isNotNull); | 8375 expect(result, isNotNull); |
| 8367 } | 8376 } |
| 8368 } | 8377 } |
| 8369 | 8378 |
| 8370 @override | 8379 @override |
| 8371 Expression parseAdditiveExpression(String code) { | 8380 Expression parseAdditiveExpression(String code) { |
| 8372 createParser(code); | 8381 createParser(code); |
| 8373 return parser.parseAdditiveExpression(); | 8382 return parser.parseAdditiveExpression(); |
| (...skipping 7050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15424 expectCommentText(typeVariable.documentationComment, '/// Doc'); | 15433 expectCommentText(typeVariable.documentationComment, '/// Doc'); |
| 15425 } | 15434 } |
| 15426 | 15435 |
| 15427 /** | 15436 /** |
| 15428 * Assert that the given [name] is in declaration context. | 15437 * Assert that the given [name] is in declaration context. |
| 15429 */ | 15438 */ |
| 15430 void _assertIsDeclarationName(SimpleIdentifier name) { | 15439 void _assertIsDeclarationName(SimpleIdentifier name) { |
| 15431 expect(name.inDeclarationContext(), isTrue); | 15440 expect(name.inDeclarationContext(), isTrue); |
| 15432 } | 15441 } |
| 15433 } | 15442 } |
| OLD | NEW |