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

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

Issue 2199323002: Initial implementation for lazy compound assignment operators (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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 2768 matching lines...) Expand 10 before | Expand all | Expand 10 after
2779 * specific test. 2779 * specific test.
2780 */ 2780 */
2781 bool enableGenericMethods = false; 2781 bool enableGenericMethods = false;
2782 2782
2783 /** 2783 /**
2784 * Whether generic method comments should be enabled for the test. 2784 * Whether generic method comments should be enabled for the test.
2785 */ 2785 */
2786 bool enableGenericMethodComments = false; 2786 bool enableGenericMethodComments = false;
2787 2787
2788 /** 2788 /**
2789 * A flag indicating whether lazy assignment operators should be enabled for
2790 * the test.
2791 */
2792 bool enableLazyAssignmentOperators = false;
2793
2794 /**
2789 * Return a CommentAndMetadata object with the given values that can be used f or testing. 2795 * Return a CommentAndMetadata object with the given values that can be used f or testing.
2790 * 2796 *
2791 * @param comment the comment to be wrapped in the object 2797 * @param comment the comment to be wrapped in the object
2792 * @param annotations the annotations to be wrapped in the object 2798 * @param annotations the annotations to be wrapped in the object
2793 * @return a CommentAndMetadata object that can be used for testing 2799 * @return a CommentAndMetadata object that can be used for testing
2794 */ 2800 */
2795 CommentAndMetadata commentAndMetadata(Comment comment, 2801 CommentAndMetadata commentAndMetadata(Comment comment,
2796 [List<Annotation> annotations]) { 2802 [List<Annotation> annotations]) {
2797 return new CommentAndMetadata(comment, annotations); 2803 return new CommentAndMetadata(comment, annotations);
2798 } 2804 }
(...skipping 23 matching lines...) Expand all
2822 * scanning and parsing the source do not match the expected errors 2828 * scanning and parsing the source do not match the expected errors
2823 */ 2829 */
2824 Object invokeParserMethod(String methodName, List<Object> objects, 2830 Object invokeParserMethod(String methodName, List<Object> objects,
2825 String source, GatheringErrorListener listener) { 2831 String source, GatheringErrorListener listener) {
2826 // 2832 //
2827 // Scan the source. 2833 // Scan the source.
2828 // 2834 //
2829 Scanner scanner = 2835 Scanner scanner =
2830 new Scanner(null, new CharSequenceReader(source), listener); 2836 new Scanner(null, new CharSequenceReader(source), listener);
2831 scanner.scanGenericMethodComments = enableGenericMethodComments; 2837 scanner.scanGenericMethodComments = enableGenericMethodComments;
2838 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators;
2832 Token tokenStream = scanner.tokenize(); 2839 Token tokenStream = scanner.tokenize();
2833 listener.setLineInfo(new TestSource(), scanner.lineStarts); 2840 listener.setLineInfo(new TestSource(), scanner.lineStarts);
2834 // 2841 //
2835 // Parse the source. 2842 // Parse the source.
2836 // 2843 //
2837 Parser parser = createParser(listener); 2844 Parser parser = createParser(listener);
2838 parser.parseAsync = parseAsync; 2845 parser.parseAsync = parseAsync;
2839 parser.parseGenericMethods = enableGenericMethods; 2846 parser.parseGenericMethods = enableGenericMethods;
2840 parser.parseGenericMethodComments = enableGenericMethodComments; 2847 parser.parseGenericMethodComments = enableGenericMethodComments;
2841 parser.parseFunctionBodies = parseFunctionBodies; 2848 parser.parseFunctionBodies = parseFunctionBodies;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3033 listener.setLineInfo(new TestSource(), scanner.lineStarts); 3040 listener.setLineInfo(new TestSource(), scanner.lineStarts);
3034 Token token = scanner.tokenize(); 3041 Token token = scanner.tokenize();
3035 Parser parser = createParser(listener); 3042 Parser parser = createParser(listener);
3036 CompilationUnit unit = parser.parseCompilationUnit(token); 3043 CompilationUnit unit = parser.parseCompilationUnit(token);
3037 expect(unit, isNotNull); 3044 expect(unit, isNotNull);
3038 listener.assertErrorsWithCodes(errorCodes); 3045 listener.assertErrorsWithCodes(errorCodes);
3039 return unit; 3046 return unit;
3040 } 3047 }
3041 3048
3042 /** 3049 /**
3043 * Parse the given source as a statement. 3050 * Parse the given [source] as a statement. The [errorCodes] are the error
3044 * 3051 * codes of the errors that are expected to be found. If
3045 * @param source the source to be parsed 3052 * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators
3046 * @param errorCodes the error codes of the errors that are expected to be fou nd 3053 * should be enabled.
3047 * @return the statement that was parsed
3048 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
3049 * not match those that are expected, or if the result would have be en `null`
3050 */ 3054 */
3051 static Statement parseStatement(String source, 3055 static Statement parseStatement(String source,
3052 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { 3056 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST,
3057 bool enableLazyAssignmentOperators]) {
3053 GatheringErrorListener listener = new GatheringErrorListener(); 3058 GatheringErrorListener listener = new GatheringErrorListener();
3054 Scanner scanner = 3059 Scanner scanner =
3055 new Scanner(null, new CharSequenceReader(source), listener); 3060 new Scanner(null, new CharSequenceReader(source), listener);
3061 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators;
3056 listener.setLineInfo(new TestSource(), scanner.lineStarts); 3062 listener.setLineInfo(new TestSource(), scanner.lineStarts);
3057 Token token = scanner.tokenize(); 3063 Token token = scanner.tokenize();
3058 Parser parser = createParser(listener); 3064 Parser parser = createParser(listener);
3059 Statement statement = parser.parseStatement(token); 3065 Statement statement = parser.parseStatement(token);
3060 expect(statement, isNotNull); 3066 expect(statement, isNotNull);
3061 listener.assertErrorsWithCodes(errorCodes); 3067 listener.assertErrorsWithCodes(errorCodes);
3062 return statement; 3068 return statement;
3063 } 3069 }
3064 3070
3065 /** 3071 /**
(...skipping 4379 matching lines...) Expand 10 before | Expand all | Expand 10 after
7445 7451
7446 void test_parseExpression_assign() { 7452 void test_parseExpression_assign() {
7447 // TODO(brianwilkerson) Implement more tests for this method. 7453 // TODO(brianwilkerson) Implement more tests for this method.
7448 AssignmentExpression expression = parse4("parseExpression", "x = y"); 7454 AssignmentExpression expression = parse4("parseExpression", "x = y");
7449 expect(expression.leftHandSide, isNotNull); 7455 expect(expression.leftHandSide, isNotNull);
7450 expect(expression.operator, isNotNull); 7456 expect(expression.operator, isNotNull);
7451 expect(expression.operator.type, TokenType.EQ); 7457 expect(expression.operator.type, TokenType.EQ);
7452 expect(expression.rightHandSide, isNotNull); 7458 expect(expression.rightHandSide, isNotNull);
7453 } 7459 }
7454 7460
7461 void test_parseExpression_assign_compound() {
7462 enableLazyAssignmentOperators = true;
7463 AssignmentExpression expression = parse4("parseExpression", "x ||= y");
7464 expect(expression.leftHandSide, isNotNull);
7465 expect(expression.operator, isNotNull);
7466 expect(expression.operator.type, TokenType.BAR_BAR_EQ);
7467 expect(expression.rightHandSide, isNotNull);
7468 }
7469
7455 void test_parseExpression_comparison() { 7470 void test_parseExpression_comparison() {
7456 BinaryExpression expression = parse4("parseExpression", "--a.b == c"); 7471 BinaryExpression expression = parse4("parseExpression", "--a.b == c");
7457 expect(expression.leftOperand, isNotNull); 7472 expect(expression.leftOperand, isNotNull);
7458 expect(expression.operator, isNotNull); 7473 expect(expression.operator, isNotNull);
7459 expect(expression.operator.type, TokenType.EQ_EQ); 7474 expect(expression.operator.type, TokenType.EQ_EQ);
7460 expect(expression.rightOperand, isNotNull); 7475 expect(expression.rightOperand, isNotNull);
7461 } 7476 }
7462 7477
7463 void test_parseExpression_function_async() { 7478 void test_parseExpression_function_async() {
7464 FunctionExpression expression = parseExpression("() async {}"); 7479 FunctionExpression expression = parseExpression("() async {}");
(...skipping 3848 matching lines...) Expand 10 before | Expand all | Expand 10 after
11313 new Scanner(null, new CharSequenceReader(source), listener); 11328 new Scanner(null, new CharSequenceReader(source), listener);
11314 Token tokenStream = scanner.tokenize(); 11329 Token tokenStream = scanner.tokenize();
11315 // 11330 //
11316 // Parse the source. 11331 // Parse the source.
11317 // 11332 //
11318 Parser parser = new Parser(null, listener); 11333 Parser parser = new Parser(null, listener);
11319 return invokeParserMethodImpl( 11334 return invokeParserMethodImpl(
11320 parser, methodName, <Object>[tokenStream], tokenStream) as Token; 11335 parser, methodName, <Object>[tokenStream], tokenStream) as Token;
11321 } 11336 }
11322 } 11337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698