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

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

Issue 16256021: Remove trailing spaces in analyzer_experimental (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3
4 library engine.parser_test; 3 library engine.parser_test;
5
6 import 'dart:collection'; 4 import 'dart:collection';
7 import 'package:analyzer_experimental/src/generated/java_core.dart'; 5 import 'package:analyzer_experimental/src/generated/java_core.dart';
8 import 'package:analyzer_experimental/src/generated/java_engine.dart'; 6 import 'package:analyzer_experimental/src/generated/java_engine.dart';
9 import 'package:analyzer_experimental/src/generated/java_junit.dart'; 7 import 'package:analyzer_experimental/src/generated/java_junit.dart';
10 import 'package:analyzer_experimental/src/generated/source.dart'; 8 import 'package:analyzer_experimental/src/generated/source.dart';
11 import 'package:analyzer_experimental/src/generated/error.dart'; 9 import 'package:analyzer_experimental/src/generated/error.dart';
12 import 'package:analyzer_experimental/src/generated/scanner.dart'; 10 import 'package:analyzer_experimental/src/generated/scanner.dart';
13 import 'package:analyzer_experimental/src/generated/ast.dart'; 11 import 'package:analyzer_experimental/src/generated/ast.dart';
14 import 'package:analyzer_experimental/src/generated/parser.dart'; 12 import 'package:analyzer_experimental/src/generated/parser.dart';
15 import 'package:analyzer_experimental/src/generated/utilities_dart.dart'; 13 import 'package:analyzer_experimental/src/generated/utilities_dart.dart';
16 import 'package:unittest/unittest.dart' as _ut; 14 import 'package:unittest/unittest.dart' as _ut;
17 import 'test_support.dart'; 15 import 'test_support.dart';
18 import 'scanner_test.dart' show TokenFactory; 16 import 'scanner_test.dart' show TokenFactory;
19 import 'ast_test.dart' show ASTFactory; 17 import 'ast_test.dart' show ASTFactory;
20
21
22 /** 18 /**
23 * The class {@code SimpleParserTest} defines parser tests that test individual parsing method. The 19 * The class {@code SimpleParserTest} defines parser tests that test individual parsing method. The
24 * code fragments should be as minimal as possible in order to test the method, but should not test 20 * code fragments should be as minimal as possible in order to test the method, but should not test
25 * the interactions between the method under test and other methods. 21 * the interactions between the method under test and other methods.
26 * <p> 22 * <p>
27 * More complex tests should be defined in the class {@link ComplexParserTest}. 23 * More complex tests should be defined in the class {@link ComplexParserTest}.
28 */ 24 */
29 class SimpleParserTest extends ParserTestCase { 25 class SimpleParserTest extends ParserTestCase {
30 void fail_parseCommentReference_this() { 26 void fail_parseCommentReference_this() {
31 CommentReference reference = ParserTestCase.parse("parseCommentReference", < Object> ["this", 5], ""); 27 CommentReference reference = ParserTestCase.parse("parseCommentReference", < Object> ["this", 5], "");
(...skipping 3631 matching lines...) Expand 10 before | Expand all | Expand 10 after
3663 void test_skipTypeName_parameterized() { 3659 void test_skipTypeName_parameterized() {
3664 Token following = skip("skipTypeName", "C<E<F<G>>> +"); 3660 Token following = skip("skipTypeName", "C<E<F<G>>> +");
3665 JUnitTestCase.assertNotNull(following); 3661 JUnitTestCase.assertNotNull(following);
3666 JUnitTestCase.assertEquals(TokenType.PLUS, following.type); 3662 JUnitTestCase.assertEquals(TokenType.PLUS, following.type);
3667 } 3663 }
3668 void test_skipTypeName_simple() { 3664 void test_skipTypeName_simple() {
3669 Token following = skip("skipTypeName", "C +"); 3665 Token following = skip("skipTypeName", "C +");
3670 JUnitTestCase.assertNotNull(following); 3666 JUnitTestCase.assertNotNull(following);
3671 JUnitTestCase.assertEquals(TokenType.PLUS, following.type); 3667 JUnitTestCase.assertEquals(TokenType.PLUS, following.type);
3672 } 3668 }
3673 3669
3674 /** 3670 /**
3675 * Invoke the method {@link Parser#computeStringValue(String)} with the given argument. 3671 * Invoke the method {@link Parser#computeStringValue(String)} with the given argument.
3676 * @param lexeme the argument to the method 3672 * @param lexeme the argument to the method
3677 * @return the result of invoking the method 3673 * @return the result of invoking the method
3678 * @throws Exception if the method could not be invoked or throws an exception 3674 * @throws Exception if the method could not be invoked or throws an exception
3679 */ 3675 */
3680 String computeStringValue(String lexeme) { 3676 String computeStringValue(String lexeme) {
3681 AnalysisErrorListener listener = new AnalysisErrorListener_20(); 3677 AnalysisErrorListener listener = new AnalysisErrorListener_20();
3682 Parser parser = new Parser(null, listener); 3678 Parser parser = new Parser(null, listener);
3683 return invokeParserMethodImpl(parser, "computeStringValue", <Object> [lexeme ], null) as String; 3679 return invokeParserMethodImpl(parser, "computeStringValue", <Object> [lexeme ], null) as String;
3684 } 3680 }
3685 3681
3686 /** 3682 /**
3687 * Invoke the method {@link Parser#createSyntheticIdentifier()} with the parse r set to the token 3683 * Invoke the method {@link Parser#createSyntheticIdentifier()} with the parse r set to the token
3688 * stream produced by scanning the given source. 3684 * stream produced by scanning the given source.
3689 * @param source the source to be scanned to produce the token stream being te sted 3685 * @param source the source to be scanned to produce the token stream being te sted
3690 * @return the result of invoking the method 3686 * @return the result of invoking the method
3691 * @throws Exception if the method could not be invoked or throws an exception 3687 * @throws Exception if the method could not be invoked or throws an exception
3692 */ 3688 */
3693 SimpleIdentifier createSyntheticIdentifier() { 3689 SimpleIdentifier createSyntheticIdentifier() {
3694 GatheringErrorListener listener = new GatheringErrorListener(); 3690 GatheringErrorListener listener = new GatheringErrorListener();
3695 return ParserTestCase.invokeParserMethod2("createSyntheticIdentifier", "", l istener); 3691 return ParserTestCase.invokeParserMethod2("createSyntheticIdentifier", "", l istener);
3696 } 3692 }
3697 3693
3698 /** 3694 /**
3699 * Invoke the method {@link Parser#createSyntheticIdentifier()} with the parse r set to the token 3695 * Invoke the method {@link Parser#createSyntheticIdentifier()} with the parse r set to the token
3700 * stream produced by scanning the given source. 3696 * stream produced by scanning the given source.
3701 * @param source the source to be scanned to produce the token stream being te sted 3697 * @param source the source to be scanned to produce the token stream being te sted
3702 * @return the result of invoking the method 3698 * @return the result of invoking the method
3703 * @throws Exception if the method could not be invoked or throws an exception 3699 * @throws Exception if the method could not be invoked or throws an exception
3704 */ 3700 */
3705 SimpleStringLiteral createSyntheticStringLiteral() { 3701 SimpleStringLiteral createSyntheticStringLiteral() {
3706 GatheringErrorListener listener = new GatheringErrorListener(); 3702 GatheringErrorListener listener = new GatheringErrorListener();
3707 return ParserTestCase.invokeParserMethod2("createSyntheticStringLiteral", "" , listener); 3703 return ParserTestCase.invokeParserMethod2("createSyntheticStringLiteral", "" , listener);
3708 } 3704 }
3709 3705
3710 /** 3706 /**
3711 * Invoke the method {@link Parser#isFunctionDeclaration()} with the parser se t to the token 3707 * Invoke the method {@link Parser#isFunctionDeclaration()} with the parser se t to the token
3712 * stream produced by scanning the given source. 3708 * stream produced by scanning the given source.
3713 * @param source the source to be scanned to produce the token stream being te sted 3709 * @param source the source to be scanned to produce the token stream being te sted
3714 * @return the result of invoking the method 3710 * @return the result of invoking the method
3715 * @throws Exception if the method could not be invoked or throws an exception 3711 * @throws Exception if the method could not be invoked or throws an exception
3716 */ 3712 */
3717 bool isFunctionDeclaration(String source) { 3713 bool isFunctionDeclaration(String source) {
3718 GatheringErrorListener listener = new GatheringErrorListener(); 3714 GatheringErrorListener listener = new GatheringErrorListener();
3719 return ParserTestCase.invokeParserMethod2("isFunctionDeclaration", source, l istener) as bool; 3715 return ParserTestCase.invokeParserMethod2("isFunctionDeclaration", source, l istener) as bool;
3720 } 3716 }
3721 3717
3722 /** 3718 /**
3723 * Invoke the method {@link Parser#isFunctionExpression()} with the parser set to the token stream 3719 * Invoke the method {@link Parser#isFunctionExpression()} with the parser set to the token stream
3724 * produced by scanning the given source. 3720 * produced by scanning the given source.
3725 * @param source the source to be scanned to produce the token stream being te sted 3721 * @param source the source to be scanned to produce the token stream being te sted
3726 * @return the result of invoking the method 3722 * @return the result of invoking the method
3727 * @throws Exception if the method could not be invoked or throws an exception 3723 * @throws Exception if the method could not be invoked or throws an exception
3728 */ 3724 */
3729 bool isFunctionExpression(String source) { 3725 bool isFunctionExpression(String source) {
3730 GatheringErrorListener listener = new GatheringErrorListener(); 3726 GatheringErrorListener listener = new GatheringErrorListener();
3731 StringScanner scanner = new StringScanner(null, source, listener); 3727 StringScanner scanner = new StringScanner(null, source, listener);
3732 Token tokenStream = scanner.tokenize(); 3728 Token tokenStream = scanner.tokenize();
3733 Parser parser = new Parser(null, listener); 3729 Parser parser = new Parser(null, listener);
3734 return invokeParserMethodImpl(parser, "isFunctionExpression", <Object> [toke nStream], tokenStream) as bool; 3730 return invokeParserMethodImpl(parser, "isFunctionExpression", <Object> [toke nStream], tokenStream) as bool;
3735 } 3731 }
3736 3732
3737 /** 3733 /**
3738 * Invoke the method {@link Parser#isInitializedVariableDeclaration()} with th e parser set to the 3734 * Invoke the method {@link Parser#isInitializedVariableDeclaration()} with th e parser set to the
3739 * token stream produced by scanning the given source. 3735 * token stream produced by scanning the given source.
3740 * @param source the source to be scanned to produce the token stream being te sted 3736 * @param source the source to be scanned to produce the token stream being te sted
3741 * @return the result of invoking the method 3737 * @return the result of invoking the method
3742 * @throws Exception if the method could not be invoked or throws an exception 3738 * @throws Exception if the method could not be invoked or throws an exception
3743 */ 3739 */
3744 bool isInitializedVariableDeclaration(String source) { 3740 bool isInitializedVariableDeclaration(String source) {
3745 GatheringErrorListener listener = new GatheringErrorListener(); 3741 GatheringErrorListener listener = new GatheringErrorListener();
3746 return ParserTestCase.invokeParserMethod2("isInitializedVariableDeclaration" , source, listener) as bool; 3742 return ParserTestCase.invokeParserMethod2("isInitializedVariableDeclaration" , source, listener) as bool;
3747 } 3743 }
3748 3744
3749 /** 3745 /**
3750 * Invoke the method {@link Parser#isSwitchMember()} with the parser set to th e token stream 3746 * Invoke the method {@link Parser#isSwitchMember()} with the parser set to th e token stream
3751 * produced by scanning the given source. 3747 * produced by scanning the given source.
3752 * @param source the source to be scanned to produce the token stream being te sted 3748 * @param source the source to be scanned to produce the token stream being te sted
3753 * @return the result of invoking the method 3749 * @return the result of invoking the method
3754 * @throws Exception if the method could not be invoked or throws an exception 3750 * @throws Exception if the method could not be invoked or throws an exception
3755 */ 3751 */
3756 bool isSwitchMember(String source) { 3752 bool isSwitchMember(String source) {
3757 GatheringErrorListener listener = new GatheringErrorListener(); 3753 GatheringErrorListener listener = new GatheringErrorListener();
3758 return ParserTestCase.invokeParserMethod2("isSwitchMember", source, listener ) as bool; 3754 return ParserTestCase.invokeParserMethod2("isSwitchMember", source, listener ) as bool;
3759 } 3755 }
3760 3756
3761 /** 3757 /**
3762 * Invoke a "skip" method in {@link Parser}. The method is assumed to take a t oken as it's 3758 * Invoke a "skip" method in {@link Parser}. The method is assumed to take a t oken as it's
3763 * parameter and is given the first token in the scanned source. 3759 * parameter and is given the first token in the scanned source.
3764 * @param methodName the name of the method that should be invoked 3760 * @param methodName the name of the method that should be invoked
3765 * @param source the source to be processed by the method 3761 * @param source the source to be processed by the method
3766 * @return the result of invoking the method 3762 * @return the result of invoking the method
3767 * @throws Exception if the method could not be invoked or throws an exception 3763 * @throws Exception if the method could not be invoked or throws an exception
3768 * @throws AssertionFailedError if the result is {@code null} 3764 * @throws AssertionFailedError if the result is {@code null}
3769 */ 3765 */
3770 Token skip(String methodName, String source) { 3766 Token skip(String methodName, String source) {
(...skipping 2078 matching lines...) Expand 10 before | Expand all | Expand 10 after
5849 runJUnitTest(__test, __test.test_skipTypeName_simple); 5845 runJUnitTest(__test, __test.test_skipTypeName_simple);
5850 }); 5846 });
5851 }); 5847 });
5852 } 5848 }
5853 } 5849 }
5854 class AnalysisErrorListener_20 implements AnalysisErrorListener { 5850 class AnalysisErrorListener_20 implements AnalysisErrorListener {
5855 void onError(AnalysisError event) { 5851 void onError(AnalysisError event) {
5856 JUnitTestCase.fail("Unexpected compilation error: ${event.message} (${event. offset}, ${event.length})"); 5852 JUnitTestCase.fail("Unexpected compilation error: ${event.message} (${event. offset}, ${event.length})");
5857 } 5853 }
5858 } 5854 }
5859
5860 /** 5855 /**
5861 * The class {@code ComplexParserTest} defines parser tests that test the parsin g of more complex 5856 * The class {@code ComplexParserTest} defines parser tests that test the parsin g of more complex
5862 * code fragments or the interactions between multiple parsing methods. For exam ple, tests to ensure 5857 * code fragments or the interactions between multiple parsing methods. For exam ple, tests to ensure
5863 * that the precedence of operations is being handled correctly should be define d in this class. 5858 * that the precedence of operations is being handled correctly should be define d in this class.
5864 * <p> 5859 * <p>
5865 * Simpler tests should be defined in the class {@link SimpleParserTest}. 5860 * Simpler tests should be defined in the class {@link SimpleParserTest}.
5866 */ 5861 */
5867 class ComplexParserTest extends ParserTestCase { 5862 class ComplexParserTest extends ParserTestCase {
5868 void test_additiveExpression_normal() { 5863 void test_additiveExpression_normal() {
5869 BinaryExpression expression = ParserTestCase.parseExpression("x + y - z", [] ); 5864 BinaryExpression expression = ParserTestCase.parseExpression("x + y - z", [] );
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
6260 final __test = new ComplexParserTest(); 6255 final __test = new ComplexParserTest();
6261 runJUnitTest(__test, __test.test_shiftExpression_precedence_additive_rig ht); 6256 runJUnitTest(__test, __test.test_shiftExpression_precedence_additive_rig ht);
6262 }); 6257 });
6263 _ut.test('test_shiftExpression_super', () { 6258 _ut.test('test_shiftExpression_super', () {
6264 final __test = new ComplexParserTest(); 6259 final __test = new ComplexParserTest();
6265 runJUnitTest(__test, __test.test_shiftExpression_super); 6260 runJUnitTest(__test, __test.test_shiftExpression_super);
6266 }); 6261 });
6267 }); 6262 });
6268 } 6263 }
6269 } 6264 }
6270
6271 /** 6265 /**
6272 * Instances of the class {@code ASTValidator} are used to validate the correct construction of an 6266 * Instances of the class {@code ASTValidator} are used to validate the correct construction of an
6273 * AST structure. 6267 * AST structure.
6274 */ 6268 */
6275 class ASTValidator extends GeneralizingASTVisitor<Object> { 6269 class ASTValidator extends GeneralizingASTVisitor<Object> {
6276 6270
6277 /** 6271 /**
6278 * A list containing the errors found while traversing the AST structure. 6272 * A list containing the errors found while traversing the AST structure.
6279 */ 6273 */
6280 List<String> _errors = new List<String>(); 6274 List<String> _errors = new List<String>();
6281 6275
6282 /** 6276 /**
6283 * Assert that no errors were found while traversing any of the AST structures that have been 6277 * Assert that no errors were found while traversing any of the AST structures that have been
6284 * visited. 6278 * visited.
6285 */ 6279 */
6286 void assertValid() { 6280 void assertValid() {
6287 if (!_errors.isEmpty) { 6281 if (!_errors.isEmpty) {
6288 JavaStringBuilder builder = new JavaStringBuilder(); 6282 JavaStringBuilder builder = new JavaStringBuilder();
6289 builder.append("Invalid AST structure:"); 6283 builder.append("Invalid AST structure:");
6290 for (String message in _errors) { 6284 for (String message in _errors) {
6291 builder.append("\r\n "); 6285 builder.append("\r\n ");
6292 builder.append(message); 6286 builder.append(message);
6293 } 6287 }
6294 JUnitTestCase.fail(builder.toString()); 6288 JUnitTestCase.fail(builder.toString());
6295 } 6289 }
6296 } 6290 }
6297 Object visitNode(ASTNode node) { 6291 Object visitNode(ASTNode node) {
6298 validate(node); 6292 validate(node);
6299 return super.visitNode(node); 6293 return super.visitNode(node);
6300 } 6294 }
6301 6295
6302 /** 6296 /**
6303 * Validate that the given AST node is correctly constructed. 6297 * Validate that the given AST node is correctly constructed.
6304 * @param node the AST node being validated 6298 * @param node the AST node being validated
6305 */ 6299 */
6306 void validate(ASTNode node) { 6300 void validate(ASTNode node) {
6307 ASTNode parent2 = node.parent; 6301 ASTNode parent2 = node.parent;
6308 if (node is CompilationUnit) { 6302 if (node is CompilationUnit) {
6309 if (parent2 != null) { 6303 if (parent2 != null) {
6310 _errors.add("Compilation units should not have a parent"); 6304 _errors.add("Compilation units should not have a parent");
6311 } 6305 }
(...skipping 20 matching lines...) Expand all
6332 if (nodeStart < parentStart) { 6326 if (nodeStart < parentStart) {
6333 _errors.add("Invalid source start (${nodeStart}) for ${node.runtimeType. toString()} inside ${parent2.runtimeType.toString()} (${parentStart})"); 6327 _errors.add("Invalid source start (${nodeStart}) for ${node.runtimeType. toString()} inside ${parent2.runtimeType.toString()} (${parentStart})");
6334 } 6328 }
6335 if (nodeEnd > parentEnd) { 6329 if (nodeEnd > parentEnd) {
6336 _errors.add("Invalid source end (${nodeEnd}) for ${node.runtimeType.toSt ring()} inside ${parent2.runtimeType.toString()} (${parentStart})"); 6330 _errors.add("Invalid source end (${nodeEnd}) for ${node.runtimeType.toSt ring()} inside ${parent2.runtimeType.toString()} (${parentStart})");
6337 } 6331 }
6338 } 6332 }
6339 } 6333 }
6340 } 6334 }
6341 class ParserTestCase extends EngineTestCase { 6335 class ParserTestCase extends EngineTestCase {
6342 6336
6343 /** 6337 /**
6344 * An empty array of objects used as arguments to zero-argument methods. 6338 * An empty array of objects used as arguments to zero-argument methods.
6345 */ 6339 */
6346 static List<Object> _EMPTY_ARGUMENTS = new List<Object>(0); 6340 static List<Object> _EMPTY_ARGUMENTS = new List<Object>(0);
6347 6341
6348 /** 6342 /**
6349 * Invoke a parse method in {@link Parser}. The method is assumed to have the given number and 6343 * Invoke a parse method in {@link Parser}. The method is assumed to have the given number and
6350 * type of parameters and will be invoked with the given arguments. 6344 * type of parameters and will be invoked with the given arguments.
6351 * <p> 6345 * <p>
6352 * The given source is scanned and the parser is initialized to start with the first token in the 6346 * The given source is scanned and the parser is initialized to start with the first token in the
6353 * source before the parse method is invoked. 6347 * source before the parse method is invoked.
6354 * @param methodName the name of the parse method that should be invoked to pa rse the source 6348 * @param methodName the name of the parse method that should be invoked to pa rse the source
6355 * @param objects the values of the arguments to the method 6349 * @param objects the values of the arguments to the method
6356 * @param source the source to be parsed by the parse method 6350 * @param source the source to be parsed by the parse method
6357 * @return the result of invoking the method 6351 * @return the result of invoking the method
6358 * @throws Exception if the method could not be invoked or throws an exception 6352 * @throws Exception if the method could not be invoked or throws an exception
6359 * @throws AssertionFailedError if the result is {@code null} or if any errors are produced 6353 * @throws AssertionFailedError if the result is {@code null} or if any errors are produced
6360 */ 6354 */
6361 static Object parse(String methodName, List<Object> objects, String source) => parse3(methodName, objects, source, new List<AnalysisError>(0)); 6355 static Object parse(String methodName, List<Object> objects, String source) => parse3(methodName, objects, source, new List<AnalysisError>(0));
6362 6356
6363 /** 6357 /**
6364 * Invoke a parse method in {@link Parser}. The method is assumed to have the given number and 6358 * Invoke a parse method in {@link Parser}. The method is assumed to have the given number and
6365 * type of parameters and will be invoked with the given arguments. 6359 * type of parameters and will be invoked with the given arguments.
6366 * <p> 6360 * <p>
6367 * The given source is scanned and the parser is initialized to start with the first token in the 6361 * The given source is scanned and the parser is initialized to start with the first token in the
6368 * source before the parse method is invoked. 6362 * source before the parse method is invoked.
6369 * @param methodName the name of the parse method that should be invoked to pa rse the source 6363 * @param methodName the name of the parse method that should be invoked to pa rse the source
6370 * @param objects the values of the arguments to the method 6364 * @param objects the values of the arguments to the method
6371 * @param source the source to be parsed by the parse method 6365 * @param source the source to be parsed by the parse method
6372 * @param errorCodes the error codes of the errors that should be generated 6366 * @param errorCodes the error codes of the errors that should be generated
6373 * @return the result of invoking the method 6367 * @return the result of invoking the method
6374 * @throws Exception if the method could not be invoked or throws an exception 6368 * @throws Exception if the method could not be invoked or throws an exception
6375 * @throws AssertionFailedError if the result is {@code null} or the errors pr oduced while 6369 * @throws AssertionFailedError if the result is {@code null} or the errors pr oduced while
6376 * scanning and parsing the source do not match the expected errors 6370 * scanning and parsing the source do not match the expected errors
6377 */ 6371 */
6378 static Object parse3(String methodName, List<Object> objects, String source, L ist<AnalysisError> errors) { 6372 static Object parse3(String methodName, List<Object> objects, String source, L ist<AnalysisError> errors) {
6379 GatheringErrorListener listener = new GatheringErrorListener(); 6373 GatheringErrorListener listener = new GatheringErrorListener();
6380 Object result = invokeParserMethod(methodName, objects, source, listener); 6374 Object result = invokeParserMethod(methodName, objects, source, listener);
6381 listener.assertErrors(errors); 6375 listener.assertErrors(errors);
6382 return result; 6376 return result;
6383 } 6377 }
6384 6378
6385 /** 6379 /**
6386 * Invoke a parse method in {@link Parser}. The method is assumed to have the given number and 6380 * Invoke a parse method in {@link Parser}. The method is assumed to have the given number and
6387 * type of parameters and will be invoked with the given arguments. 6381 * type of parameters and will be invoked with the given arguments.
6388 * <p> 6382 * <p>
6389 * The given source is scanned and the parser is initialized to start with the first token in the 6383 * The given source is scanned and the parser is initialized to start with the first token in the
6390 * source before the parse method is invoked. 6384 * source before the parse method is invoked.
6391 * @param methodName the name of the parse method that should be invoked to pa rse the source 6385 * @param methodName the name of the parse method that should be invoked to pa rse the source
6392 * @param objects the values of the arguments to the method 6386 * @param objects the values of the arguments to the method
6393 * @param source the source to be parsed by the parse method 6387 * @param source the source to be parsed by the parse method
6394 * @param errorCodes the error codes of the errors that should be generated 6388 * @param errorCodes the error codes of the errors that should be generated
6395 * @return the result of invoking the method 6389 * @return the result of invoking the method
6396 * @throws Exception if the method could not be invoked or throws an exception 6390 * @throws Exception if the method could not be invoked or throws an exception
6397 * @throws AssertionFailedError if the result is {@code null} or the errors pr oduced while 6391 * @throws AssertionFailedError if the result is {@code null} or the errors pr oduced while
6398 * scanning and parsing the source do not match the expected errors 6392 * scanning and parsing the source do not match the expected errors
6399 */ 6393 */
6400 static Object parse4(String methodName, List<Object> objects, String source, L ist<ErrorCode> errorCodes) { 6394 static Object parse4(String methodName, List<Object> objects, String source, L ist<ErrorCode> errorCodes) {
6401 GatheringErrorListener listener = new GatheringErrorListener(); 6395 GatheringErrorListener listener = new GatheringErrorListener();
6402 Object result = invokeParserMethod(methodName, objects, source, listener); 6396 Object result = invokeParserMethod(methodName, objects, source, listener);
6403 listener.assertErrors2(errorCodes); 6397 listener.assertErrors2(errorCodes);
6404 return result; 6398 return result;
6405 } 6399 }
6406 6400
6407 /** 6401 /**
6408 * Invoke a parse method in {@link Parser}. The method is assumed to have no a rguments. 6402 * Invoke a parse method in {@link Parser}. The method is assumed to have no a rguments.
6409 * <p> 6403 * <p>
6410 * The given source is scanned and the parser is initialized to start with the first token in the 6404 * The given source is scanned and the parser is initialized to start with the first token in the
6411 * source before the parse method is invoked. 6405 * source before the parse method is invoked.
6412 * @param methodName the name of the parse method that should be invoked to pa rse the source 6406 * @param methodName the name of the parse method that should be invoked to pa rse the source
6413 * @param source the source to be parsed by the parse method 6407 * @param source the source to be parsed by the parse method
6414 * @param errorCodes the error codes of the errors that should be generated 6408 * @param errorCodes the error codes of the errors that should be generated
6415 * @return the result of invoking the method 6409 * @return the result of invoking the method
6416 * @throws Exception if the method could not be invoked or throws an exception 6410 * @throws Exception if the method could not be invoked or throws an exception
6417 * @throws AssertionFailedError if the result is {@code null} or the errors pr oduced while 6411 * @throws AssertionFailedError if the result is {@code null} or the errors pr oduced while
6418 * scanning and parsing the source do not match the expected errors 6412 * scanning and parsing the source do not match the expected errors
6419 */ 6413 */
6420 static Object parse5(String methodName, String source, List<ErrorCode> errorCo des) => parse4(methodName, _EMPTY_ARGUMENTS, source, errorCodes); 6414 static Object parse5(String methodName, String source, List<ErrorCode> errorCo des) => parse4(methodName, _EMPTY_ARGUMENTS, source, errorCodes);
6421 6415
6422 /** 6416 /**
6423 * Parse the given source as a compilation unit. 6417 * Parse the given source as a compilation unit.
6424 * @param source the source to be parsed 6418 * @param source the source to be parsed
6425 * @param errorCodes the error codes of the errors that are expected to be fou nd 6419 * @param errorCodes the error codes of the errors that are expected to be fou nd
6426 * @return the compilation unit that was parsed 6420 * @return the compilation unit that was parsed
6427 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 6421 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
6428 * not match those that are expected, or if the result would have been {@code null} 6422 * not match those that are expected, or if the result would have been {@code null}
6429 */ 6423 */
6430 static CompilationUnit parseCompilationUnit(String source, List<ErrorCode> err orCodes) { 6424 static CompilationUnit parseCompilationUnit(String source, List<ErrorCode> err orCodes) {
6431 GatheringErrorListener listener = new GatheringErrorListener(); 6425 GatheringErrorListener listener = new GatheringErrorListener();
6432 StringScanner scanner = new StringScanner(null, source, listener); 6426 StringScanner scanner = new StringScanner(null, source, listener);
6433 listener.setLineInfo(new TestSource(), scanner.lineStarts); 6427 listener.setLineInfo(new TestSource(), scanner.lineStarts);
6434 Token token = scanner.tokenize(); 6428 Token token = scanner.tokenize();
6435 Parser parser = new Parser(null, listener); 6429 Parser parser = new Parser(null, listener);
6436 CompilationUnit unit = parser.parseCompilationUnit(token); 6430 CompilationUnit unit = parser.parseCompilationUnit(token);
6437 JUnitTestCase.assertNotNull(unit); 6431 JUnitTestCase.assertNotNull(unit);
6438 listener.assertErrors2(errorCodes); 6432 listener.assertErrors2(errorCodes);
6439 return unit; 6433 return unit;
6440 } 6434 }
6441 6435
6442 /** 6436 /**
6443 * Parse the given source as an expression. 6437 * Parse the given source as an expression.
6444 * @param source the source to be parsed 6438 * @param source the source to be parsed
6445 * @param errorCodes the error codes of the errors that are expected to be fou nd 6439 * @param errorCodes the error codes of the errors that are expected to be fou nd
6446 * @return the expression that was parsed 6440 * @return the expression that was parsed
6447 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 6441 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
6448 * not match those that are expected, or if the result would have been {@code null} 6442 * not match those that are expected, or if the result would have been {@code null}
6449 */ 6443 */
6450 static Expression parseExpression(String source, List<ErrorCode> errorCodes) { 6444 static Expression parseExpression(String source, List<ErrorCode> errorCodes) {
6451 GatheringErrorListener listener = new GatheringErrorListener(); 6445 GatheringErrorListener listener = new GatheringErrorListener();
6452 StringScanner scanner = new StringScanner(null, source, listener); 6446 StringScanner scanner = new StringScanner(null, source, listener);
6453 listener.setLineInfo(new TestSource(), scanner.lineStarts); 6447 listener.setLineInfo(new TestSource(), scanner.lineStarts);
6454 Token token = scanner.tokenize(); 6448 Token token = scanner.tokenize();
6455 Parser parser = new Parser(null, listener); 6449 Parser parser = new Parser(null, listener);
6456 Expression expression = parser.parseExpression(token); 6450 Expression expression = parser.parseExpression(token);
6457 JUnitTestCase.assertNotNull(expression); 6451 JUnitTestCase.assertNotNull(expression);
6458 listener.assertErrors2(errorCodes); 6452 listener.assertErrors2(errorCodes);
6459 return expression as Expression; 6453 return expression as Expression;
6460 } 6454 }
6461 6455
6462 /** 6456 /**
6463 * Parse the given source as a statement. 6457 * Parse the given source as a statement.
6464 * @param source the source to be parsed 6458 * @param source the source to be parsed
6465 * @param errorCodes the error codes of the errors that are expected to be fou nd 6459 * @param errorCodes the error codes of the errors that are expected to be fou nd
6466 * @return the statement that was parsed 6460 * @return the statement that was parsed
6467 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 6461 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
6468 * not match those that are expected, or if the result would have been {@code null} 6462 * not match those that are expected, or if the result would have been {@code null}
6469 */ 6463 */
6470 static Statement parseStatement(String source, List<ErrorCode> errorCodes) { 6464 static Statement parseStatement(String source, List<ErrorCode> errorCodes) {
6471 GatheringErrorListener listener = new GatheringErrorListener(); 6465 GatheringErrorListener listener = new GatheringErrorListener();
6472 StringScanner scanner = new StringScanner(null, source, listener); 6466 StringScanner scanner = new StringScanner(null, source, listener);
6473 listener.setLineInfo(new TestSource(), scanner.lineStarts); 6467 listener.setLineInfo(new TestSource(), scanner.lineStarts);
6474 Token token = scanner.tokenize(); 6468 Token token = scanner.tokenize();
6475 Parser parser = new Parser(null, listener); 6469 Parser parser = new Parser(null, listener);
6476 Statement statement = parser.parseStatement(token); 6470 Statement statement = parser.parseStatement(token);
6477 JUnitTestCase.assertNotNull(statement); 6471 JUnitTestCase.assertNotNull(statement);
6478 listener.assertErrors2(errorCodes); 6472 listener.assertErrors2(errorCodes);
6479 return statement as Statement; 6473 return statement as Statement;
6480 } 6474 }
6481 6475
6482 /** 6476 /**
6483 * Parse the given source as a sequence of statements. 6477 * Parse the given source as a sequence of statements.
6484 * @param source the source to be parsed 6478 * @param source the source to be parsed
6485 * @param expectedCount the number of statements that are expected 6479 * @param expectedCount the number of statements that are expected
6486 * @param errorCodes the error codes of the errors that are expected to be fou nd 6480 * @param errorCodes the error codes of the errors that are expected to be fou nd
6487 * @return the statements that were parsed 6481 * @return the statements that were parsed
6488 * @throws Exception if the source could not be parsed, if the number of state ments does not match 6482 * @throws Exception if the source could not be parsed, if the number of state ments does not match
6489 * the expected count, if the compilation errors in the source do not match th ose that 6483 * the expected count, if the compilation errors in the source do not match th ose that
6490 * are expected, or if the result would have been {@code null} 6484 * are expected, or if the result would have been {@code null}
6491 */ 6485 */
6492 static List<Statement> parseStatements(String source, int expectedCount, List< ErrorCode> errorCodes) { 6486 static List<Statement> parseStatements(String source, int expectedCount, List< ErrorCode> errorCodes) {
6493 GatheringErrorListener listener = new GatheringErrorListener(); 6487 GatheringErrorListener listener = new GatheringErrorListener();
6494 StringScanner scanner = new StringScanner(null, source, listener); 6488 StringScanner scanner = new StringScanner(null, source, listener);
6495 listener.setLineInfo(new TestSource(), scanner.lineStarts); 6489 listener.setLineInfo(new TestSource(), scanner.lineStarts);
6496 Token token = scanner.tokenize(); 6490 Token token = scanner.tokenize();
6497 Parser parser = new Parser(null, listener); 6491 Parser parser = new Parser(null, listener);
6498 List<Statement> statements = parser.parseStatements(token); 6492 List<Statement> statements = parser.parseStatements(token);
6499 EngineTestCase.assertSize(expectedCount, statements); 6493 EngineTestCase.assertSize(expectedCount, statements);
6500 listener.assertErrors2(errorCodes); 6494 listener.assertErrors2(errorCodes);
6501 return statements; 6495 return statements;
6502 } 6496 }
6503 6497
6504 /** 6498 /**
6505 * Invoke a method in {@link Parser}. The method is assumed to have the given number and type of 6499 * Invoke a method in {@link Parser}. The method is assumed to have the given number and type of
6506 * parameters and will be invoked with the given arguments. 6500 * parameters and will be invoked with the given arguments.
6507 * <p> 6501 * <p>
6508 * The given source is scanned and the parser is initialized to start with the first token in the 6502 * The given source is scanned and the parser is initialized to start with the first token in the
6509 * source before the method is invoked. 6503 * source before the method is invoked.
6510 * @param methodName the name of the method that should be invoked 6504 * @param methodName the name of the method that should be invoked
6511 * @param objects the values of the arguments to the method 6505 * @param objects the values of the arguments to the method
6512 * @param source the source to be processed by the parse method 6506 * @param source the source to be processed by the parse method
6513 * @param listener the error listener that will be used for both scanning and parsing 6507 * @param listener the error listener that will be used for both scanning and parsing
6514 * @return the result of invoking the method 6508 * @return the result of invoking the method
6515 * @throws Exception if the method could not be invoked or throws an exception 6509 * @throws Exception if the method could not be invoked or throws an exception
6516 * @throws AssertionFailedError if the result is {@code null} or the errors pr oduced while 6510 * @throws AssertionFailedError if the result is {@code null} or the errors pr oduced while
6517 * scanning and parsing the source do not match the expected errors 6511 * scanning and parsing the source do not match the expected errors
6518 */ 6512 */
6519 static Object invokeParserMethod(String methodName, List<Object> objects, Stri ng source, GatheringErrorListener listener) { 6513 static Object invokeParserMethod(String methodName, List<Object> objects, Stri ng source, GatheringErrorListener listener) {
6520 StringScanner scanner = new StringScanner(null, source, listener); 6514 StringScanner scanner = new StringScanner(null, source, listener);
6521 Token tokenStream = scanner.tokenize(); 6515 Token tokenStream = scanner.tokenize();
6522 listener.setLineInfo(new TestSource(), scanner.lineStarts); 6516 listener.setLineInfo(new TestSource(), scanner.lineStarts);
6523 Parser parser = new Parser(null, listener); 6517 Parser parser = new Parser(null, listener);
6524 Object result = invokeParserMethodImpl(parser, methodName, objects, tokenStr eam); 6518 Object result = invokeParserMethodImpl(parser, methodName, objects, tokenStr eam);
6525 if (!listener.hasErrors()) { 6519 if (!listener.hasErrors()) {
6526 JUnitTestCase.assertNotNull(result); 6520 JUnitTestCase.assertNotNull(result);
6527 } 6521 }
6528 return result as Object; 6522 return result as Object;
6529 } 6523 }
6530 6524
6531 /** 6525 /**
6532 * Invoke a method in {@link Parser}. The method is assumed to have no argumen ts. 6526 * Invoke a method in {@link Parser}. The method is assumed to have no argumen ts.
6533 * <p> 6527 * <p>
6534 * The given source is scanned and the parser is initialized to start with the first token in the 6528 * The given source is scanned and the parser is initialized to start with the first token in the
6535 * source before the method is invoked. 6529 * source before the method is invoked.
6536 * @param methodName the name of the method that should be invoked 6530 * @param methodName the name of the method that should be invoked
6537 * @param source the source to be processed by the parse method 6531 * @param source the source to be processed by the parse method
6538 * @param listener the error listener that will be used for both scanning and parsing 6532 * @param listener the error listener that will be used for both scanning and parsing
6539 * @return the result of invoking the method 6533 * @return the result of invoking the method
6540 * @throws Exception if the method could not be invoked or throws an exception 6534 * @throws Exception if the method could not be invoked or throws an exception
6541 * @throws AssertionFailedError if the result is {@code null} or the errors pr oduced while 6535 * @throws AssertionFailedError if the result is {@code null} or the errors pr oduced while
6542 * scanning and parsing the source do not match the expected errors 6536 * scanning and parsing the source do not match the expected errors
6543 */ 6537 */
6544 static Object invokeParserMethod2(String methodName, String source, GatheringE rrorListener listener) => invokeParserMethod(methodName, _EMPTY_ARGUMENTS, sourc e, listener); 6538 static Object invokeParserMethod2(String methodName, String source, GatheringE rrorListener listener) => invokeParserMethod(methodName, _EMPTY_ARGUMENTS, sourc e, listener);
6545 6539
6546 /** 6540 /**
6547 * Return a CommentAndMetadata object with the given values that can be used f or testing. 6541 * Return a CommentAndMetadata object with the given values that can be used f or testing.
6548 * @param comment the comment to be wrapped in the object 6542 * @param comment the comment to be wrapped in the object
6549 * @param annotations the annotations to be wrapped in the object 6543 * @param annotations the annotations to be wrapped in the object
6550 * @return a CommentAndMetadata object that can be used for testing 6544 * @return a CommentAndMetadata object that can be used for testing
6551 */ 6545 */
6552 CommentAndMetadata commentAndMetadata(Comment comment, List<Annotation> annota tions) { 6546 CommentAndMetadata commentAndMetadata(Comment comment, List<Annotation> annota tions) {
6553 List<Annotation> metadata = new List<Annotation>(); 6547 List<Annotation> metadata = new List<Annotation>();
6554 for (Annotation annotation in annotations) { 6548 for (Annotation annotation in annotations) {
6555 metadata.add(annotation); 6549 metadata.add(annotation);
6556 } 6550 }
6557 return new CommentAndMetadata(comment, metadata); 6551 return new CommentAndMetadata(comment, metadata);
6558 } 6552 }
6559 6553
6560 /** 6554 /**
6561 * Return an empty CommentAndMetadata object that can be used for testing. 6555 * Return an empty CommentAndMetadata object that can be used for testing.
6562 * @return an empty CommentAndMetadata object that can be used for testing 6556 * @return an empty CommentAndMetadata object that can be used for testing
6563 */ 6557 */
6564 CommentAndMetadata emptyCommentAndMetadata() => new CommentAndMetadata(null, n ew List<Annotation>()); 6558 CommentAndMetadata emptyCommentAndMetadata() => new CommentAndMetadata(null, n ew List<Annotation>());
6565 static dartSuite() { 6559 static dartSuite() {
6566 _ut.group('ParserTestCase', () { 6560 _ut.group('ParserTestCase', () {
6567 }); 6561 });
6568 } 6562 }
6569 } 6563 }
6570
6571 /** 6564 /**
6572 * The class {@code RecoveryParserTest} defines parser tests that test the parsi ng of invalid code 6565 * The class {@code RecoveryParserTest} defines parser tests that test the parsi ng of invalid code
6573 * sequences to ensure that the correct recovery steps are taken in the parser. 6566 * sequences to ensure that the correct recovery steps are taken in the parser.
6574 */ 6567 */
6575 class RecoveryParserTest extends ParserTestCase { 6568 class RecoveryParserTest extends ParserTestCase {
6576 void fail_incompleteReturnType() { 6569 void fail_incompleteReturnType() {
6577 ParserTestCase.parseCompilationUnit(EngineTestCase.createSource(["Map<Symbol , convertStringToSymbolMap(Map<String, dynamic> map) {", " if (map == null) ret urn null;", " Map<Symbol, dynamic> result = new Map<Symbol, dynamic>();", " ma p.forEach((name, value) {", " result[new Symbol(name)] = value;", " });", " return result;", "}"]), []); 6570 ParserTestCase.parseCompilationUnit(EngineTestCase.createSource(["Map<Symbol , convertStringToSymbolMap(Map<String, dynamic> map) {", " if (map == null) ret urn null;", " Map<Symbol, dynamic> result = new Map<Symbol, dynamic>();", " ma p.forEach((name, value) {", " result[new Symbol(name)] = value;", " });", " return result;", "}"]), []);
6578 } 6571 }
6579 void test_additiveExpression_missing_LHS() { 6572 void test_additiveExpression_missing_LHS() {
6580 BinaryExpression expression = ParserTestCase.parseExpression("+ y", [ParserE rrorCode.MISSING_IDENTIFIER]); 6573 BinaryExpression expression = ParserTestCase.parseExpression("+ y", [ParserE rrorCode.MISSING_IDENTIFIER]);
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
7281 final __test = new RecoveryParserTest(); 7274 final __test = new RecoveryParserTest();
7282 runJUnitTest(__test, __test.test_shiftExpression_super); 7275 runJUnitTest(__test, __test.test_shiftExpression_super);
7283 }); 7276 });
7284 _ut.test('test_typedef_eof', () { 7277 _ut.test('test_typedef_eof', () {
7285 final __test = new RecoveryParserTest(); 7278 final __test = new RecoveryParserTest();
7286 runJUnitTest(__test, __test.test_typedef_eof); 7279 runJUnitTest(__test, __test.test_typedef_eof);
7287 }); 7280 });
7288 }); 7281 });
7289 } 7282 }
7290 } 7283 }
7291
7292 /** 7284 /**
7293 * The class {@code ErrorParserTest} defines parser tests that test the parsing of code to ensure 7285 * The class {@code ErrorParserTest} defines parser tests that test the parsing of code to ensure
7294 * that errors are correctly reported, and in some cases, not reported. 7286 * that errors are correctly reported, and in some cases, not reported.
7295 */ 7287 */
7296 class ErrorParserTest extends ParserTestCase { 7288 class ErrorParserTest extends ParserTestCase {
7297 void fail_expectedListOrMapLiteral() { 7289 void fail_expectedListOrMapLiteral() {
7298 TypedLiteral literal = ParserTestCase.parse4("parseListOrMapLiteral", <Objec t> [null], "1", [ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL]); 7290 TypedLiteral literal = ParserTestCase.parse4("parseListOrMapLiteral", <Objec t> [null], "1", [ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL]);
7299 JUnitTestCase.assertTrue(literal.isSynthetic()); 7291 JUnitTestCase.assertTrue(literal.isSynthetic());
7300 } 7292 }
7301 void fail_illegalAssignmentToNonAssignable_superAssigned() { 7293 void fail_illegalAssignmentToNonAssignable_superAssigned() {
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after
8859 'validateModifiersForTopLevelFunction_1': new MethodTrampoline(1, (Parser targ et, arg0) => target.validateModifiersForTopLevelFunction(arg0)), 8851 'validateModifiersForTopLevelFunction_1': new MethodTrampoline(1, (Parser targ et, arg0) => target.validateModifiersForTopLevelFunction(arg0)),
8860 'validateModifiersForTopLevelVariable_1': new MethodTrampoline(1, (Parser targ et, arg0) => target.validateModifiersForTopLevelVariable(arg0)), 8852 'validateModifiersForTopLevelVariable_1': new MethodTrampoline(1, (Parser targ et, arg0) => target.validateModifiersForTopLevelVariable(arg0)),
8861 'validateModifiersForTypedef_1': new MethodTrampoline(1, (Parser target, arg0) => target.validateModifiersForTypedef(arg0)),}; 8853 'validateModifiersForTypedef_1': new MethodTrampoline(1, (Parser target, arg0) => target.validateModifiersForTypedef(arg0)),};
8862 8854
8863 8855
8864 Object invokeParserMethodImpl(Parser parser, String methodName, List<Object> obj ects, Token tokenStream) { 8856 Object invokeParserMethodImpl(Parser parser, String methodName, List<Object> obj ects, Token tokenStream) {
8865 parser.currentToken = tokenStream; 8857 parser.currentToken = tokenStream;
8866 MethodTrampoline method = _methodTable_Parser['${methodName}_${objects.length} ']; 8858 MethodTrampoline method = _methodTable_Parser['${methodName}_${objects.length} '];
8867 return method.invoke(parser, objects); 8859 return method.invoke(parser, objects);
8868 } 8860 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698