| 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 library analyzer.test.generated.parser_test; | 5 library analyzer.test.generated.parser_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/src/dart/ast/token.dart'; | 10 import 'package:analyzer/src/dart/ast/token.dart'; |
| (...skipping 2748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2759 * A flag indicating whether parser is to parse function bodies. | 2759 * A flag indicating whether parser is to parse function bodies. |
| 2760 */ | 2760 */ |
| 2761 static bool parseFunctionBodies = true; | 2761 static bool parseFunctionBodies = true; |
| 2762 | 2762 |
| 2763 /** | 2763 /** |
| 2764 * A flag indicating whether parser is to parse async. | 2764 * A flag indicating whether parser is to parse async. |
| 2765 */ | 2765 */ |
| 2766 bool parseAsync = true; | 2766 bool parseAsync = true; |
| 2767 | 2767 |
| 2768 /** | 2768 /** |
| 2769 * A flag indicating whether conditional directives support should be enabled | |
| 2770 * for a specific test. | |
| 2771 */ | |
| 2772 bool enableConditionalDirectives = false; | |
| 2773 | |
| 2774 /** | |
| 2775 * A flag indicating whether generic method support should be enabled for a | 2769 * A flag indicating whether generic method support should be enabled for a |
| 2776 * specific test. | 2770 * specific test. |
| 2777 */ | 2771 */ |
| 2778 bool enableGenericMethods = false; | 2772 bool enableGenericMethods = false; |
| 2779 | 2773 |
| 2780 /** | 2774 /** |
| 2781 * Whether generic method comments should be enabled for the test. | 2775 * Whether generic method comments should be enabled for the test. |
| 2782 */ | 2776 */ |
| 2783 bool enableGenericMethodComments = false; | 2777 bool enableGenericMethodComments = false; |
| 2784 | 2778 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2826 Scanner scanner = | 2820 Scanner scanner = |
| 2827 new Scanner(null, new CharSequenceReader(source), listener); | 2821 new Scanner(null, new CharSequenceReader(source), listener); |
| 2828 scanner.scanGenericMethodComments = enableGenericMethodComments; | 2822 scanner.scanGenericMethodComments = enableGenericMethodComments; |
| 2829 Token tokenStream = scanner.tokenize(); | 2823 Token tokenStream = scanner.tokenize(); |
| 2830 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 2824 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 2831 // | 2825 // |
| 2832 // Parse the source. | 2826 // Parse the source. |
| 2833 // | 2827 // |
| 2834 Parser parser = createParser(listener); | 2828 Parser parser = createParser(listener); |
| 2835 parser.parseAsync = parseAsync; | 2829 parser.parseAsync = parseAsync; |
| 2836 parser.parseConditionalDirectives = enableConditionalDirectives; | |
| 2837 parser.parseGenericMethods = enableGenericMethods; | 2830 parser.parseGenericMethods = enableGenericMethods; |
| 2838 parser.parseGenericMethodComments = enableGenericMethodComments; | 2831 parser.parseGenericMethodComments = enableGenericMethodComments; |
| 2839 parser.parseFunctionBodies = parseFunctionBodies; | 2832 parser.parseFunctionBodies = parseFunctionBodies; |
| 2840 Object result = | 2833 Object result = |
| 2841 invokeParserMethodImpl(parser, methodName, objects, tokenStream); | 2834 invokeParserMethodImpl(parser, methodName, objects, tokenStream); |
| 2842 // | 2835 // |
| 2843 // Partially test the results. | 2836 // Partially test the results. |
| 2844 // | 2837 // |
| 2845 if (!listener.hasErrors) { | 2838 if (!listener.hasErrors) { |
| 2846 expect(result, isNotNull); | 2839 expect(result, isNotNull); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2957 CompilationUnit parseCompilationUnitWithOptions(String source, | 2950 CompilationUnit parseCompilationUnitWithOptions(String source, |
| 2958 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { | 2951 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { |
| 2959 GatheringErrorListener listener = new GatheringErrorListener(); | 2952 GatheringErrorListener listener = new GatheringErrorListener(); |
| 2960 Scanner scanner = | 2953 Scanner scanner = |
| 2961 new Scanner(null, new CharSequenceReader(source), listener); | 2954 new Scanner(null, new CharSequenceReader(source), listener); |
| 2962 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 2955 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 2963 Token token = scanner.tokenize(); | 2956 Token token = scanner.tokenize(); |
| 2964 Parser parser = createParser(listener); | 2957 Parser parser = createParser(listener); |
| 2965 parser.parseAsync = parseAsync; | 2958 parser.parseAsync = parseAsync; |
| 2966 parser.parseFunctionBodies = parseFunctionBodies; | 2959 parser.parseFunctionBodies = parseFunctionBodies; |
| 2967 parser.parseConditionalDirectives = enableConditionalDirectives; | |
| 2968 parser.parseGenericMethods = enableGenericMethods; | 2960 parser.parseGenericMethods = enableGenericMethods; |
| 2969 parser.parseGenericMethodComments = enableGenericMethodComments; | 2961 parser.parseGenericMethodComments = enableGenericMethodComments; |
| 2970 CompilationUnit unit = parser.parseCompilationUnit(token); | 2962 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 2971 expect(unit, isNotNull); | 2963 expect(unit, isNotNull); |
| 2972 listener.assertErrorsWithCodes(errorCodes); | 2964 listener.assertErrorsWithCodes(errorCodes); |
| 2973 return unit; | 2965 return unit; |
| 2974 } | 2966 } |
| 2975 | 2967 |
| 2976 /** | 2968 /** |
| 2977 * Parse the given source as an expression. | 2969 * Parse the given source as an expression. |
| (...skipping 4277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7255 BinaryExpression expression = | 7247 BinaryExpression expression = |
| 7256 parse4("parseEqualityExpression", "super == y"); | 7248 parse4("parseEqualityExpression", "super == y"); |
| 7257 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, | 7249 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, |
| 7258 SuperExpression, expression.leftOperand); | 7250 SuperExpression, expression.leftOperand); |
| 7259 expect(expression.operator, isNotNull); | 7251 expect(expression.operator, isNotNull); |
| 7260 expect(expression.operator.type, TokenType.EQ_EQ); | 7252 expect(expression.operator.type, TokenType.EQ_EQ); |
| 7261 expect(expression.rightOperand, isNotNull); | 7253 expect(expression.rightOperand, isNotNull); |
| 7262 } | 7254 } |
| 7263 | 7255 |
| 7264 void test_parseExportDirective_configuration_multiple() { | 7256 void test_parseExportDirective_configuration_multiple() { |
| 7265 enableConditionalDirectives = true; | |
| 7266 ExportDirective directive = parse( | 7257 ExportDirective directive = parse( |
| 7267 "parseExportDirective", | 7258 "parseExportDirective", |
| 7268 <Object>[emptyCommentAndMetadata()], | 7259 <Object>[emptyCommentAndMetadata()], |
| 7269 "export 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';"); | 7260 "export 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';"); |
| 7270 expect(directive.keyword, isNotNull); | 7261 expect(directive.keyword, isNotNull); |
| 7271 expect(directive.uri, isNotNull); | 7262 expect(directive.uri, isNotNull); |
| 7272 expect(directive.configurations, hasLength(2)); | 7263 expect(directive.configurations, hasLength(2)); |
| 7273 _expectDottedName(directive.configurations[0].name, ['a']); | 7264 _expectDottedName(directive.configurations[0].name, ['a']); |
| 7274 _expectDottedName(directive.configurations[1].name, ['c']); | 7265 _expectDottedName(directive.configurations[1].name, ['c']); |
| 7275 expect(directive.combinators, hasLength(0)); | 7266 expect(directive.combinators, hasLength(0)); |
| 7276 expect(directive.semicolon, isNotNull); | 7267 expect(directive.semicolon, isNotNull); |
| 7277 } | 7268 } |
| 7278 | 7269 |
| 7279 void test_parseExportDirective_configuration_single() { | 7270 void test_parseExportDirective_configuration_single() { |
| 7280 enableConditionalDirectives = true; | |
| 7281 ExportDirective directive = parse( | 7271 ExportDirective directive = parse( |
| 7282 "parseExportDirective", | 7272 "parseExportDirective", |
| 7283 <Object>[emptyCommentAndMetadata()], | 7273 <Object>[emptyCommentAndMetadata()], |
| 7284 "export 'lib/lib.dart' if (a.b == 'c.dart') '';"); | 7274 "export 'lib/lib.dart' if (a.b == 'c.dart') '';"); |
| 7285 expect(directive.keyword, isNotNull); | 7275 expect(directive.keyword, isNotNull); |
| 7286 expect(directive.uri, isNotNull); | 7276 expect(directive.uri, isNotNull); |
| 7287 expect(directive.configurations, hasLength(1)); | 7277 expect(directive.configurations, hasLength(1)); |
| 7288 _expectDottedName(directive.configurations[0].name, ['a', 'b']); | 7278 _expectDottedName(directive.configurations[0].name, ['a', 'b']); |
| 7289 expect(directive.combinators, hasLength(0)); | 7279 expect(directive.combinators, hasLength(0)); |
| 7290 expect(directive.semicolon, isNotNull); | 7280 expect(directive.semicolon, isNotNull); |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8465 expect(clause.implementsKeyword, isNotNull); | 8455 expect(clause.implementsKeyword, isNotNull); |
| 8466 } | 8456 } |
| 8467 | 8457 |
| 8468 void test_parseImplementsClause_single() { | 8458 void test_parseImplementsClause_single() { |
| 8469 ImplementsClause clause = parse4("parseImplementsClause", "implements A"); | 8459 ImplementsClause clause = parse4("parseImplementsClause", "implements A"); |
| 8470 expect(clause.interfaces, hasLength(1)); | 8460 expect(clause.interfaces, hasLength(1)); |
| 8471 expect(clause.implementsKeyword, isNotNull); | 8461 expect(clause.implementsKeyword, isNotNull); |
| 8472 } | 8462 } |
| 8473 | 8463 |
| 8474 void test_parseImportDirective_configuration_multiple() { | 8464 void test_parseImportDirective_configuration_multiple() { |
| 8475 enableConditionalDirectives = true; | |
| 8476 ImportDirective directive = parse( | 8465 ImportDirective directive = parse( |
| 8477 "parseImportDirective", | 8466 "parseImportDirective", |
| 8478 <Object>[emptyCommentAndMetadata()], | 8467 <Object>[emptyCommentAndMetadata()], |
| 8479 "import 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';"); | 8468 "import 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';"); |
| 8480 expect(directive.keyword, isNotNull); | 8469 expect(directive.keyword, isNotNull); |
| 8481 expect(directive.uri, isNotNull); | 8470 expect(directive.uri, isNotNull); |
| 8482 expect(directive.configurations, hasLength(2)); | 8471 expect(directive.configurations, hasLength(2)); |
| 8483 _expectDottedName(directive.configurations[0].name, ['a']); | 8472 _expectDottedName(directive.configurations[0].name, ['a']); |
| 8484 _expectDottedName(directive.configurations[1].name, ['c']); | 8473 _expectDottedName(directive.configurations[1].name, ['c']); |
| 8485 expect(directive.deferredKeyword, isNull); | 8474 expect(directive.deferredKeyword, isNull); |
| 8486 expect(directive.asKeyword, isNull); | 8475 expect(directive.asKeyword, isNull); |
| 8487 expect(directive.prefix, isNull); | 8476 expect(directive.prefix, isNull); |
| 8488 expect(directive.combinators, hasLength(0)); | 8477 expect(directive.combinators, hasLength(0)); |
| 8489 expect(directive.semicolon, isNotNull); | 8478 expect(directive.semicolon, isNotNull); |
| 8490 } | 8479 } |
| 8491 | 8480 |
| 8492 void test_parseImportDirective_configuration_single() { | 8481 void test_parseImportDirective_configuration_single() { |
| 8493 enableConditionalDirectives = true; | |
| 8494 ImportDirective directive = parse( | 8482 ImportDirective directive = parse( |
| 8495 "parseImportDirective", | 8483 "parseImportDirective", |
| 8496 <Object>[emptyCommentAndMetadata()], | 8484 <Object>[emptyCommentAndMetadata()], |
| 8497 "import 'lib/lib.dart' if (a.b == 'c.dart') '';"); | 8485 "import 'lib/lib.dart' if (a.b == 'c.dart') '';"); |
| 8498 expect(directive.keyword, isNotNull); | 8486 expect(directive.keyword, isNotNull); |
| 8499 expect(directive.uri, isNotNull); | 8487 expect(directive.uri, isNotNull); |
| 8500 expect(directive.configurations, hasLength(1)); | 8488 expect(directive.configurations, hasLength(1)); |
| 8501 _expectDottedName(directive.configurations[0].name, ['a', 'b']); | 8489 _expectDottedName(directive.configurations[0].name, ['a', 'b']); |
| 8502 expect(directive.deferredKeyword, isNull); | 8490 expect(directive.deferredKeyword, isNull); |
| 8503 expect(directive.asKeyword, isNull); | 8491 expect(directive.asKeyword, isNull); |
| (...skipping 2681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11185 new Scanner(null, new CharSequenceReader(source), listener); | 11173 new Scanner(null, new CharSequenceReader(source), listener); |
| 11186 Token tokenStream = scanner.tokenize(); | 11174 Token tokenStream = scanner.tokenize(); |
| 11187 // | 11175 // |
| 11188 // Parse the source. | 11176 // Parse the source. |
| 11189 // | 11177 // |
| 11190 Parser parser = new Parser(null, listener); | 11178 Parser parser = new Parser(null, listener); |
| 11191 return invokeParserMethodImpl( | 11179 return invokeParserMethodImpl( |
| 11192 parser, methodName, <Object>[tokenStream], tokenStream) as Token; | 11180 parser, methodName, <Object>[tokenStream], tokenStream) as Token; |
| 11193 } | 11181 } |
| 11194 } | 11182 } |
| OLD | NEW |