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

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

Issue 2486873003: Move scanner into pkg/front_end/lib/src/scanner. (Closed)
Patch Set: Created 4 years, 1 month 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/error/error.dart'; 10 import 'package:analyzer/error/error.dart';
(...skipping 2919 matching lines...) Expand 10 before | Expand all | Expand 10 after
2930 expect(result, isNotNull); 2930 expect(result, isNotNull);
2931 } 2931 }
2932 } 2932 }
2933 2933
2934 /** 2934 /**
2935 * Parse the given [source] as a compilation unit. Throw an exception if the 2935 * Parse the given [source] as a compilation unit. Throw an exception if the
2936 * source could not be parsed, if the compilation errors in the source do not 2936 * source could not be parsed, if the compilation errors in the source do not
2937 * match those that are expected, or if the result would have been `null`. 2937 * match those that are expected, or if the result would have been `null`.
2938 */ 2938 */
2939 CompilationUnit parseCompilationUnitWithOptions(String source, 2939 CompilationUnit parseCompilationUnitWithOptions(String source,
2940 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { 2940 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
2941 createParser(source); 2941 createParser(source);
2942 CompilationUnit unit = parser.parseCompilationUnit2(); 2942 CompilationUnit unit = parser.parseCompilationUnit2();
2943 expect(unit, isNotNull); 2943 expect(unit, isNotNull);
2944 listener.assertErrorsWithCodes(errorCodes); 2944 listener.assertErrorsWithCodes(errorCodes);
2945 return unit; 2945 return unit;
2946 } 2946 }
2947 2947
2948 /** 2948 /**
2949 * Parse the given source as an expression. 2949 * Parse the given source as an expression.
2950 * 2950 *
2951 * @param source the source to be parsed 2951 * @param source the source to be parsed
2952 * @param errorCodes the error codes of the errors that are expected to be fou nd 2952 * @param errorCodes the error codes of the errors that are expected to be fou nd
2953 * @return the expression that was parsed 2953 * @return the expression that was parsed
2954 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 2954 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
2955 * not match those that are expected, or if the result would have be en `null` 2955 * not match those that are expected, or if the result would have be en `null`
2956 */ 2956 */
2957 Expression parseExpression(String source, 2957 Expression parseExpression(String source,
2958 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { 2958 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
2959 createParser(source); 2959 createParser(source);
2960 Expression expression = parser.parseExpression2(); 2960 Expression expression = parser.parseExpression2();
2961 expectNotNullIfNoErrors(expression); 2961 expectNotNullIfNoErrors(expression);
2962 listener.assertErrorsWithCodes(errorCodes); 2962 listener.assertErrorsWithCodes(errorCodes);
2963 return expression; 2963 return expression;
2964 } 2964 }
2965 2965
2966 @override 2966 @override
2967 void setUp() { 2967 void setUp() {
2968 super.setUp(); 2968 super.setUp();
2969 parseFunctionBodies = true; 2969 parseFunctionBodies = true;
2970 } 2970 }
2971 2971
2972 /** 2972 /**
2973 * Parse the given source as a compilation unit. 2973 * Parse the given source as a compilation unit.
2974 * 2974 *
2975 * @param source the source to be parsed 2975 * @param source the source to be parsed
2976 * @param errorCodes the error codes of the errors that are expected to be fou nd 2976 * @param errorCodes the error codes of the errors that are expected to be fou nd
2977 * @return the compilation unit that was parsed 2977 * @return the compilation unit that was parsed
2978 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 2978 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
2979 * not match those that are expected, or if the result would have be en `null` 2979 * not match those that are expected, or if the result would have be en `null`
2980 */ 2980 */
2981 static CompilationUnit parseCompilationUnit(String source, 2981 static CompilationUnit parseCompilationUnit(String source,
2982 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { 2982 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
2983 GatheringErrorListener listener = new GatheringErrorListener(); 2983 GatheringErrorListener listener = new GatheringErrorListener();
2984 Scanner scanner = 2984 Scanner scanner =
2985 new Scanner(null, new CharSequenceReader(source), listener); 2985 new Scanner(null, new CharSequenceReader(source), listener);
2986 listener.setLineInfo(new TestSource(), scanner.lineStarts); 2986 listener.setLineInfo(new TestSource(), scanner.lineStarts);
2987 Token token = scanner.tokenize(); 2987 Token token = scanner.tokenize();
2988 Parser parser = new Parser(null, listener); 2988 Parser parser = new Parser(null, listener);
2989 CompilationUnit unit = parser.parseCompilationUnit(token); 2989 CompilationUnit unit = parser.parseCompilationUnit(token);
2990 expect(unit, isNotNull); 2990 expect(unit, isNotNull);
2991 listener.assertErrorsWithCodes(errorCodes); 2991 listener.assertErrorsWithCodes(errorCodes);
2992 return unit; 2992 return unit;
(...skipping 14 matching lines...) Expand all
3007 return unit; 3007 return unit;
3008 } 3008 }
3009 3009
3010 /** 3010 /**
3011 * Parse the given [source] as a statement. The [errorCodes] are the error 3011 * Parse the given [source] as a statement. The [errorCodes] are the error
3012 * codes of the errors that are expected to be found. If 3012 * codes of the errors that are expected to be found. If
3013 * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators 3013 * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators
3014 * should be enabled. 3014 * should be enabled.
3015 */ 3015 */
3016 static Statement parseStatement(String source, 3016 static Statement parseStatement(String source,
3017 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST, 3017 [List<ErrorCode> errorCodes = const <ErrorCode>[],
3018 bool enableLazyAssignmentOperators]) { 3018 bool enableLazyAssignmentOperators]) {
3019 GatheringErrorListener listener = new GatheringErrorListener(); 3019 GatheringErrorListener listener = new GatheringErrorListener();
3020 Scanner scanner = 3020 Scanner scanner =
3021 new Scanner(null, new CharSequenceReader(source), listener); 3021 new Scanner(null, new CharSequenceReader(source), listener);
3022 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; 3022 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators;
3023 listener.setLineInfo(new TestSource(), scanner.lineStarts); 3023 listener.setLineInfo(new TestSource(), scanner.lineStarts);
3024 Token token = scanner.tokenize(); 3024 Token token = scanner.tokenize();
3025 Parser parser = new Parser(null, listener); 3025 Parser parser = new Parser(null, listener);
3026 Statement statement = parser.parseStatement(token); 3026 Statement statement = parser.parseStatement(token);
3027 expect(statement, isNotNull); 3027 expect(statement, isNotNull);
3028 listener.assertErrorsWithCodes(errorCodes); 3028 listener.assertErrorsWithCodes(errorCodes);
3029 return statement; 3029 return statement;
3030 } 3030 }
3031 3031
3032 /** 3032 /**
3033 * Parse the given source as a sequence of statements. 3033 * Parse the given source as a sequence of statements.
3034 * 3034 *
3035 * @param source the source to be parsed 3035 * @param source the source to be parsed
3036 * @param expectedCount the number of statements that are expected 3036 * @param expectedCount the number of statements that are expected
3037 * @param errorCodes the error codes of the errors that are expected to be fou nd 3037 * @param errorCodes the error codes of the errors that are expected to be fou nd
3038 * @return the statements that were parsed 3038 * @return the statements that were parsed
3039 * @throws Exception if the source could not be parsed, if the number of state ments does not match 3039 * @throws Exception if the source could not be parsed, if the number of state ments does not match
3040 * the expected count, if the compilation errors in the source do no t match those that 3040 * the expected count, if the compilation errors in the source do no t match those that
3041 * are expected, or if the result would have been `null` 3041 * are expected, or if the result would have been `null`
3042 */ 3042 */
3043 static List<Statement> parseStatements(String source, int expectedCount, 3043 static List<Statement> parseStatements(String source, int expectedCount,
3044 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { 3044 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
3045 GatheringErrorListener listener = new GatheringErrorListener(); 3045 GatheringErrorListener listener = new GatheringErrorListener();
3046 Scanner scanner = 3046 Scanner scanner =
3047 new Scanner(null, new CharSequenceReader(source), listener); 3047 new Scanner(null, new CharSequenceReader(source), listener);
3048 listener.setLineInfo(new TestSource(), scanner.lineStarts); 3048 listener.setLineInfo(new TestSource(), scanner.lineStarts);
3049 Token token = scanner.tokenize(); 3049 Token token = scanner.tokenize();
3050 Parser parser = new Parser(null, listener); 3050 Parser parser = new Parser(null, listener);
3051 List<Statement> statements = parser.parseStatements(token); 3051 List<Statement> statements = parser.parseStatements(token);
3052 expect(statements, hasLength(expectedCount)); 3052 expect(statements, hasLength(expectedCount));
3053 listener.assertErrorsWithCodes(errorCodes); 3053 listener.assertErrorsWithCodes(errorCodes);
3054 return statements; 3054 return statements;
(...skipping 10410 matching lines...) Expand 10 before | Expand all | Expand 10 after
13465 /** 13465 /**
13466 * Parse the given source as a compilation unit. 13466 * Parse the given source as a compilation unit.
13467 * 13467 *
13468 * @param source the source to be parsed 13468 * @param source the source to be parsed
13469 * @param errorCodes the error codes of the errors that are expected to be fou nd 13469 * @param errorCodes the error codes of the errors that are expected to be fou nd
13470 * @return the compilation unit that was parsed 13470 * @return the compilation unit that was parsed
13471 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 13471 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
13472 * not match those that are expected, or if the result would have be en `null` 13472 * not match those that are expected, or if the result would have be en `null`
13473 */ 13473 */
13474 CompilationUnit _parseDirectives(String source, 13474 CompilationUnit _parseDirectives(String source,
13475 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { 13475 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
13476 createParser(source); 13476 createParser(source);
13477 CompilationUnit unit = parser.parseDirectives2(); 13477 CompilationUnit unit = parser.parseDirectives2();
13478 expect(unit, isNotNull); 13478 expect(unit, isNotNull);
13479 expect(unit.declarations, hasLength(0)); 13479 expect(unit.declarations, hasLength(0));
13480 listener.assertErrorsWithCodes(errorCodes); 13480 listener.assertErrorsWithCodes(errorCodes);
13481 return unit; 13481 return unit;
13482 } 13482 }
13483 } 13483 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698