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

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

Issue 1851753002: Enable conditional directives by default. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
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 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 2730 matching lines...) Expand 10 before | Expand all | Expand 10 after
2741 * A flag indicating whether parser is to parse function bodies. 2741 * A flag indicating whether parser is to parse function bodies.
2742 */ 2742 */
2743 static bool parseFunctionBodies = true; 2743 static bool parseFunctionBodies = true;
2744 2744
2745 /** 2745 /**
2746 * A flag indicating whether parser is to parse async. 2746 * A flag indicating whether parser is to parse async.
2747 */ 2747 */
2748 bool parseAsync = true; 2748 bool parseAsync = true;
2749 2749
2750 /** 2750 /**
2751 * A flag indicating whether conditional directives support should be enabled
2752 * for a specific test.
2753 */
2754 bool enableConditionalDirectives = false;
2755
2756 /**
2757 * A flag indicating whether generic method support should be enabled for a 2751 * A flag indicating whether generic method support should be enabled for a
2758 * specific test. 2752 * specific test.
2759 */ 2753 */
2760 bool enableGenericMethods = false; 2754 bool enableGenericMethods = false;
2761 2755
2762 /** 2756 /**
2763 * Whether generic method comments should be enabled for the test. 2757 * Whether generic method comments should be enabled for the test.
2764 */ 2758 */
2765 bool enableGenericMethodComments = false; 2759 bool enableGenericMethodComments = false;
2766 2760
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2808 Scanner scanner = 2802 Scanner scanner =
2809 new Scanner(null, new CharSequenceReader(source), listener); 2803 new Scanner(null, new CharSequenceReader(source), listener);
2810 scanner.scanGenericMethodComments = enableGenericMethodComments; 2804 scanner.scanGenericMethodComments = enableGenericMethodComments;
2811 Token tokenStream = scanner.tokenize(); 2805 Token tokenStream = scanner.tokenize();
2812 listener.setLineInfo(new TestSource(), scanner.lineStarts); 2806 listener.setLineInfo(new TestSource(), scanner.lineStarts);
2813 // 2807 //
2814 // Parse the source. 2808 // Parse the source.
2815 // 2809 //
2816 Parser parser = createParser(listener); 2810 Parser parser = createParser(listener);
2817 parser.parseAsync = parseAsync; 2811 parser.parseAsync = parseAsync;
2818 parser.parseConditionalDirectives = enableConditionalDirectives;
2819 parser.parseGenericMethods = enableGenericMethods; 2812 parser.parseGenericMethods = enableGenericMethods;
2820 parser.parseGenericMethodComments = enableGenericMethodComments; 2813 parser.parseGenericMethodComments = enableGenericMethodComments;
2821 parser.parseFunctionBodies = parseFunctionBodies; 2814 parser.parseFunctionBodies = parseFunctionBodies;
2822 Object result = 2815 Object result =
2823 invokeParserMethodImpl(parser, methodName, objects, tokenStream); 2816 invokeParserMethodImpl(parser, methodName, objects, tokenStream);
2824 // 2817 //
2825 // Partially test the results. 2818 // Partially test the results.
2826 // 2819 //
2827 if (!listener.hasErrors) { 2820 if (!listener.hasErrors) {
2828 expect(result, isNotNull); 2821 expect(result, isNotNull);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2939 CompilationUnit parseCompilationUnitWithOptions(String source, 2932 CompilationUnit parseCompilationUnitWithOptions(String source,
2940 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { 2933 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) {
2941 GatheringErrorListener listener = new GatheringErrorListener(); 2934 GatheringErrorListener listener = new GatheringErrorListener();
2942 Scanner scanner = 2935 Scanner scanner =
2943 new Scanner(null, new CharSequenceReader(source), listener); 2936 new Scanner(null, new CharSequenceReader(source), listener);
2944 listener.setLineInfo(new TestSource(), scanner.lineStarts); 2937 listener.setLineInfo(new TestSource(), scanner.lineStarts);
2945 Token token = scanner.tokenize(); 2938 Token token = scanner.tokenize();
2946 Parser parser = createParser(listener); 2939 Parser parser = createParser(listener);
2947 parser.parseAsync = parseAsync; 2940 parser.parseAsync = parseAsync;
2948 parser.parseFunctionBodies = parseFunctionBodies; 2941 parser.parseFunctionBodies = parseFunctionBodies;
2949 parser.parseConditionalDirectives = enableConditionalDirectives;
2950 parser.parseGenericMethods = enableGenericMethods; 2942 parser.parseGenericMethods = enableGenericMethods;
2951 parser.parseGenericMethodComments = enableGenericMethodComments; 2943 parser.parseGenericMethodComments = enableGenericMethodComments;
2952 CompilationUnit unit = parser.parseCompilationUnit(token); 2944 CompilationUnit unit = parser.parseCompilationUnit(token);
2953 expect(unit, isNotNull); 2945 expect(unit, isNotNull);
2954 listener.assertErrorsWithCodes(errorCodes); 2946 listener.assertErrorsWithCodes(errorCodes);
2955 return unit; 2947 return unit;
2956 } 2948 }
2957 2949
2958 /** 2950 /**
2959 * Parse the given source as an expression. 2951 * Parse the given source as an expression.
(...skipping 4260 matching lines...) Expand 10 before | Expand all | Expand 10 after
7220 BinaryExpression expression = 7212 BinaryExpression expression =
7221 parse4("parseEqualityExpression", "super == y"); 7213 parse4("parseEqualityExpression", "super == y");
7222 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, 7214 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression,
7223 SuperExpression, expression.leftOperand); 7215 SuperExpression, expression.leftOperand);
7224 expect(expression.operator, isNotNull); 7216 expect(expression.operator, isNotNull);
7225 expect(expression.operator.type, TokenType.EQ_EQ); 7217 expect(expression.operator.type, TokenType.EQ_EQ);
7226 expect(expression.rightOperand, isNotNull); 7218 expect(expression.rightOperand, isNotNull);
7227 } 7219 }
7228 7220
7229 void test_parseExportDirective_configuration_multiple() { 7221 void test_parseExportDirective_configuration_multiple() {
7230 enableConditionalDirectives = true;
7231 ExportDirective directive = parse( 7222 ExportDirective directive = parse(
7232 "parseExportDirective", 7223 "parseExportDirective",
7233 <Object>[emptyCommentAndMetadata()], 7224 <Object>[emptyCommentAndMetadata()],
7234 "export 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';"); 7225 "export 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';");
7235 expect(directive.keyword, isNotNull); 7226 expect(directive.keyword, isNotNull);
7236 expect(directive.uri, isNotNull); 7227 expect(directive.uri, isNotNull);
7237 expect(directive.configurations, hasLength(2)); 7228 expect(directive.configurations, hasLength(2));
7238 _expectDottedName(directive.configurations[0].name, ['a']); 7229 _expectDottedName(directive.configurations[0].name, ['a']);
7239 _expectDottedName(directive.configurations[1].name, ['c']); 7230 _expectDottedName(directive.configurations[1].name, ['c']);
7240 expect(directive.combinators, hasLength(0)); 7231 expect(directive.combinators, hasLength(0));
7241 expect(directive.semicolon, isNotNull); 7232 expect(directive.semicolon, isNotNull);
7242 } 7233 }
7243 7234
7244 void test_parseExportDirective_configuration_single() { 7235 void test_parseExportDirective_configuration_single() {
7245 enableConditionalDirectives = true;
7246 ExportDirective directive = parse( 7236 ExportDirective directive = parse(
7247 "parseExportDirective", 7237 "parseExportDirective",
7248 <Object>[emptyCommentAndMetadata()], 7238 <Object>[emptyCommentAndMetadata()],
7249 "export 'lib/lib.dart' if (a.b == 'c.dart') '';"); 7239 "export 'lib/lib.dart' if (a.b == 'c.dart') '';");
7250 expect(directive.keyword, isNotNull); 7240 expect(directive.keyword, isNotNull);
7251 expect(directive.uri, isNotNull); 7241 expect(directive.uri, isNotNull);
7252 expect(directive.configurations, hasLength(1)); 7242 expect(directive.configurations, hasLength(1));
7253 _expectDottedName(directive.configurations[0].name, ['a', 'b']); 7243 _expectDottedName(directive.configurations[0].name, ['a', 'b']);
7254 expect(directive.combinators, hasLength(0)); 7244 expect(directive.combinators, hasLength(0));
7255 expect(directive.semicolon, isNotNull); 7245 expect(directive.semicolon, isNotNull);
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
8426 expect(clause.implementsKeyword, isNotNull); 8416 expect(clause.implementsKeyword, isNotNull);
8427 } 8417 }
8428 8418
8429 void test_parseImplementsClause_single() { 8419 void test_parseImplementsClause_single() {
8430 ImplementsClause clause = parse4("parseImplementsClause", "implements A"); 8420 ImplementsClause clause = parse4("parseImplementsClause", "implements A");
8431 expect(clause.interfaces, hasLength(1)); 8421 expect(clause.interfaces, hasLength(1));
8432 expect(clause.implementsKeyword, isNotNull); 8422 expect(clause.implementsKeyword, isNotNull);
8433 } 8423 }
8434 8424
8435 void test_parseImportDirective_configuration_multiple() { 8425 void test_parseImportDirective_configuration_multiple() {
8436 enableConditionalDirectives = true;
8437 ImportDirective directive = parse( 8426 ImportDirective directive = parse(
8438 "parseImportDirective", 8427 "parseImportDirective",
8439 <Object>[emptyCommentAndMetadata()], 8428 <Object>[emptyCommentAndMetadata()],
8440 "import 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';"); 8429 "import 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';");
8441 expect(directive.keyword, isNotNull); 8430 expect(directive.keyword, isNotNull);
8442 expect(directive.uri, isNotNull); 8431 expect(directive.uri, isNotNull);
8443 expect(directive.configurations, hasLength(2)); 8432 expect(directive.configurations, hasLength(2));
8444 _expectDottedName(directive.configurations[0].name, ['a']); 8433 _expectDottedName(directive.configurations[0].name, ['a']);
8445 _expectDottedName(directive.configurations[1].name, ['c']); 8434 _expectDottedName(directive.configurations[1].name, ['c']);
8446 expect(directive.deferredKeyword, isNull); 8435 expect(directive.deferredKeyword, isNull);
8447 expect(directive.asKeyword, isNull); 8436 expect(directive.asKeyword, isNull);
8448 expect(directive.prefix, isNull); 8437 expect(directive.prefix, isNull);
8449 expect(directive.combinators, hasLength(0)); 8438 expect(directive.combinators, hasLength(0));
8450 expect(directive.semicolon, isNotNull); 8439 expect(directive.semicolon, isNotNull);
8451 } 8440 }
8452 8441
8453 void test_parseImportDirective_configuration_single() { 8442 void test_parseImportDirective_configuration_single() {
8454 enableConditionalDirectives = true;
8455 ImportDirective directive = parse( 8443 ImportDirective directive = parse(
8456 "parseImportDirective", 8444 "parseImportDirective",
8457 <Object>[emptyCommentAndMetadata()], 8445 <Object>[emptyCommentAndMetadata()],
8458 "import 'lib/lib.dart' if (a.b == 'c.dart') '';"); 8446 "import 'lib/lib.dart' if (a.b == 'c.dart') '';");
8459 expect(directive.keyword, isNotNull); 8447 expect(directive.keyword, isNotNull);
8460 expect(directive.uri, isNotNull); 8448 expect(directive.uri, isNotNull);
8461 expect(directive.configurations, hasLength(1)); 8449 expect(directive.configurations, hasLength(1));
8462 _expectDottedName(directive.configurations[0].name, ['a', 'b']); 8450 _expectDottedName(directive.configurations[0].name, ['a', 'b']);
8463 expect(directive.deferredKeyword, isNull); 8451 expect(directive.deferredKeyword, isNull);
8464 expect(directive.asKeyword, isNull); 8452 expect(directive.asKeyword, isNull);
(...skipping 2545 matching lines...) Expand 10 before | Expand all | Expand 10 after
11010 new Scanner(null, new CharSequenceReader(source), listener); 10998 new Scanner(null, new CharSequenceReader(source), listener);
11011 Token tokenStream = scanner.tokenize(); 10999 Token tokenStream = scanner.tokenize();
11012 // 11000 //
11013 // Parse the source. 11001 // Parse the source.
11014 // 11002 //
11015 Parser parser = new Parser(null, listener); 11003 Parser parser = new Parser(null, listener);
11016 return invokeParserMethodImpl( 11004 return invokeParserMethodImpl(
11017 parser, methodName, <Object>[tokenStream], tokenStream) as Token; 11005 parser, methodName, <Object>[tokenStream], tokenStream) as Token;
11018 } 11006 }
11019 } 11007 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698