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

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

Issue 2282233002: Add support for parsing, but not capturing, assers in constructor initializer lists (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: add flag Created 4 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/analyzer/lib/src/task/options.dart ('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) 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 2754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2765 * An empty list of objects used as arguments to zero-argument methods. 2765 * An empty list of objects used as arguments to zero-argument methods.
2766 */ 2766 */
2767 static const List<Object> _EMPTY_ARGUMENTS = const <Object>[]; 2767 static const List<Object> _EMPTY_ARGUMENTS = const <Object>[];
2768 2768
2769 /** 2769 /**
2770 * A flag indicating whether parser is to parse function bodies. 2770 * A flag indicating whether parser is to parse function bodies.
2771 */ 2771 */
2772 static bool parseFunctionBodies = true; 2772 static bool parseFunctionBodies = true;
2773 2773
2774 /** 2774 /**
2775 * A flag indicating whether the parser is to parse asserts in the initializer
2776 * list of a constructor.
2777 */
2778 bool enableAssertInitializer = false;
2779
2780 /**
2775 * A flag indicating whether parser is to parse async. 2781 * A flag indicating whether parser is to parse async.
2776 */ 2782 */
2777 bool parseAsync = true; 2783 bool parseAsync = true;
2778 2784
2779 /** 2785 /**
2780 * A flag indicating whether generic method support should be enabled for a 2786 * A flag indicating whether generic method support should be enabled for a
2781 * specific test. 2787 * specific test.
2782 */ 2788 */
2783 bool enableGenericMethods = false; 2789 bool enableGenericMethods = false;
2784 2790
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2837 Scanner scanner = 2843 Scanner scanner =
2838 new Scanner(null, new CharSequenceReader(source), listener); 2844 new Scanner(null, new CharSequenceReader(source), listener);
2839 scanner.scanGenericMethodComments = enableGenericMethodComments; 2845 scanner.scanGenericMethodComments = enableGenericMethodComments;
2840 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; 2846 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators;
2841 Token tokenStream = scanner.tokenize(); 2847 Token tokenStream = scanner.tokenize();
2842 listener.setLineInfo(new TestSource(), scanner.lineStarts); 2848 listener.setLineInfo(new TestSource(), scanner.lineStarts);
2843 // 2849 //
2844 // Parse the source. 2850 // Parse the source.
2845 // 2851 //
2846 Parser parser = createParser(listener); 2852 Parser parser = createParser(listener);
2853 parser.enableAssertInitializer = enableAssertInitializer;
2847 parser.parseAsync = parseAsync; 2854 parser.parseAsync = parseAsync;
2848 parser.parseGenericMethods = enableGenericMethods; 2855 parser.parseGenericMethods = enableGenericMethods;
2849 parser.parseGenericMethodComments = enableGenericMethodComments; 2856 parser.parseGenericMethodComments = enableGenericMethodComments;
2850 parser.parseFunctionBodies = parseFunctionBodies; 2857 parser.parseFunctionBodies = parseFunctionBodies;
2851 Object result = 2858 Object result =
2852 invokeParserMethodImpl(parser, methodName, objects, tokenStream); 2859 invokeParserMethodImpl(parser, methodName, objects, tokenStream);
2853 // 2860 //
2854 // Partially test the results. 2861 // Partially test the results.
2855 // 2862 //
2856 if (!listener.hasErrors) { 2863 if (!listener.hasErrors) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2966 * match those that are expected, or if the result would have been `null`. 2973 * match those that are expected, or if the result would have been `null`.
2967 */ 2974 */
2968 CompilationUnit parseCompilationUnitWithOptions(String source, 2975 CompilationUnit parseCompilationUnitWithOptions(String source,
2969 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { 2976 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) {
2970 GatheringErrorListener listener = new GatheringErrorListener(); 2977 GatheringErrorListener listener = new GatheringErrorListener();
2971 Scanner scanner = 2978 Scanner scanner =
2972 new Scanner(null, new CharSequenceReader(source), listener); 2979 new Scanner(null, new CharSequenceReader(source), listener);
2973 listener.setLineInfo(new TestSource(), scanner.lineStarts); 2980 listener.setLineInfo(new TestSource(), scanner.lineStarts);
2974 Token token = scanner.tokenize(); 2981 Token token = scanner.tokenize();
2975 Parser parser = createParser(listener); 2982 Parser parser = createParser(listener);
2983 parser.enableAssertInitializer = enableAssertInitializer;
2976 parser.parseAsync = parseAsync; 2984 parser.parseAsync = parseAsync;
2977 parser.parseFunctionBodies = parseFunctionBodies; 2985 parser.parseFunctionBodies = parseFunctionBodies;
2978 parser.parseGenericMethods = enableGenericMethods; 2986 parser.parseGenericMethods = enableGenericMethods;
2979 parser.parseGenericMethodComments = enableGenericMethodComments; 2987 parser.parseGenericMethodComments = enableGenericMethodComments;
2980 CompilationUnit unit = parser.parseCompilationUnit(token); 2988 CompilationUnit unit = parser.parseCompilationUnit(token);
2981 expect(unit, isNotNull); 2989 expect(unit, isNotNull);
2982 listener.assertErrorsWithCodes(errorCodes); 2990 listener.assertErrorsWithCodes(errorCodes);
2983 return unit; 2991 return unit;
2984 } 2992 }
2985 2993
(...skipping 4101 matching lines...) Expand 10 before | Expand all | Expand 10 after
7087 } 7095 }
7088 7096
7089 void test_parseConstructor() { 7097 void test_parseConstructor() {
7090 // TODO(brianwilkerson) Implement tests for this method. 7098 // TODO(brianwilkerson) Implement tests for this method.
7091 // parse("parseConstructor", new Class[] {Parser.CommentAndMetadata.class, 7099 // parse("parseConstructor", new Class[] {Parser.CommentAndMetadata.class,
7092 // Token.class, Token.class, SimpleIdentifier.class, Token.class, 7100 // Token.class, Token.class, SimpleIdentifier.class, Token.class,
7093 // SimpleIdentifier.class, FormalParameterList.class}, new Object[] {empt yCommentAndMetadata(), 7101 // SimpleIdentifier.class, FormalParameterList.class}, new Object[] {empt yCommentAndMetadata(),
7094 // null, null, null, null, null, null}, ""); 7102 // null, null, null, null, null, null}, "");
7095 } 7103 }
7096 7104
7105 void test_parseConstructor_assert() {
7106 enableAssertInitializer = true;
7107 ClassMember classMember = parse("parseClassMember", <Object>["C"],
7108 "C(x, y) : _x = x, assert (x < y), _y = y;");
7109 expect(classMember, new isInstanceOf<ConstructorDeclaration>());
7110 ConstructorDeclaration constructor = classMember as ConstructorDeclaration;
7111 NodeList<ConstructorInitializer> initializers = constructor.initializers;
7112 expect(initializers, hasLength(2));
7113 }
7114
7097 void test_parseConstructor_with_pseudo_function_literal() { 7115 void test_parseConstructor_with_pseudo_function_literal() {
7098 // "(b) {}" should not be misinterpreted as a function literal even though 7116 // "(b) {}" should not be misinterpreted as a function literal even though
7099 // it looks like one. 7117 // it looks like one.
7100 ClassMember classMember = 7118 ClassMember classMember =
7101 parse("parseClassMember", <Object>["C"], "C() : a = (b) {}"); 7119 parse("parseClassMember", <Object>["C"], "C() : a = (b) {}");
7102 EngineTestCase.assertInstanceOf((obj) => obj is ConstructorDeclaration, 7120 EngineTestCase.assertInstanceOf((obj) => obj is ConstructorDeclaration,
7103 ConstructorDeclaration, classMember); 7121 ConstructorDeclaration, classMember);
7104 ConstructorDeclaration constructor = classMember as ConstructorDeclaration; 7122 ConstructorDeclaration constructor = classMember as ConstructorDeclaration;
7105 NodeList<ConstructorInitializer> initializers = constructor.initializers; 7123 NodeList<ConstructorInitializer> initializers = constructor.initializers;
7106 expect(initializers, hasLength(1)); 7124 expect(initializers, hasLength(1));
(...skipping 4223 matching lines...) Expand 10 before | Expand all | Expand 10 after
11330 new Scanner(null, new CharSequenceReader(source), listener); 11348 new Scanner(null, new CharSequenceReader(source), listener);
11331 Token tokenStream = scanner.tokenize(); 11349 Token tokenStream = scanner.tokenize();
11332 // 11350 //
11333 // Parse the source. 11351 // Parse the source.
11334 // 11352 //
11335 Parser parser = new Parser(null, listener); 11353 Parser parser = new Parser(null, listener);
11336 return invokeParserMethodImpl( 11354 return invokeParserMethodImpl(
11337 parser, methodName, <Object>[tokenStream], tokenStream) as Token; 11355 parser, methodName, <Object>[tokenStream], tokenStream) as Token;
11338 } 11356 }
11339 } 11357 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/options.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698