| OLD | NEW |
| 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 | 3 |
| 4 library engine.parser_test; | 4 library engine.parser_test; |
| 5 | 5 |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'package:analyzer-experimental/src/generated/java_core.dart'; | 7 import 'package:analyzer_experimental/src/generated/java_core.dart'; |
| 8 import 'package:analyzer-experimental/src/generated/java_engine.dart'; | 8 import 'package:analyzer_experimental/src/generated/java_engine.dart'; |
| 9 import 'package:analyzer-experimental/src/generated/java_junit.dart'; | 9 import 'package:analyzer_experimental/src/generated/java_junit.dart'; |
| 10 import 'package:analyzer-experimental/src/generated/source.dart'; | 10 import 'package:analyzer_experimental/src/generated/source.dart'; |
| 11 import 'package:analyzer-experimental/src/generated/error.dart'; | 11 import 'package:analyzer_experimental/src/generated/error.dart'; |
| 12 import 'package:analyzer-experimental/src/generated/scanner.dart'; | 12 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| 13 import 'package:analyzer-experimental/src/generated/ast.dart'; | 13 import 'package:analyzer_experimental/src/generated/ast.dart'; |
| 14 import 'package:analyzer-experimental/src/generated/parser.dart'; | 14 import 'package:analyzer_experimental/src/generated/parser.dart'; |
| 15 import 'package:analyzer-experimental/src/generated/utilities_dart.dart'; | 15 import 'package:analyzer_experimental/src/generated/utilities_dart.dart'; |
| 16 import 'package:unittest/unittest.dart' as _ut; | 16 import 'package:unittest/unittest.dart' as _ut; |
| 17 import 'test_support.dart'; | 17 import 'test_support.dart'; |
| 18 import 'scanner_test.dart' show TokenFactory; | 18 import 'scanner_test.dart' show TokenFactory; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * The class {@code SimpleParserTest} defines parser tests that test individual
parsing method. The | 21 * The class {@code SimpleParserTest} defines parser tests that test individual
parsing method. The |
| 22 * code fragments should be as minimal as possible in order to test the method,
but should not test | 22 * code fragments should be as minimal as possible in order to test the method,
but should not test |
| 23 * the interactions between the method under test and other methods. | 23 * the interactions between the method under test and other methods. |
| 24 * <p> | 24 * <p> |
| 25 * More complex tests should be defined in the class {@link ComplexParserTest}. | 25 * More complex tests should be defined in the class {@link ComplexParserTest}. |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 SimpleIdentifier identifier = ParserTestCase.parse6("parseArgument", lexeme,
[]); | 274 SimpleIdentifier identifier = ParserTestCase.parse6("parseArgument", lexeme,
[]); |
| 275 JUnitTestCase.assertEquals(lexeme, identifier.name); | 275 JUnitTestCase.assertEquals(lexeme, identifier.name); |
| 276 } | 276 } |
| 277 void test_parseArgumentDefinitionTest() { | 277 void test_parseArgumentDefinitionTest() { |
| 278 ArgumentDefinitionTest test = ParserTestCase.parse6("parseArgumentDefinition
Test", "?x", []); | 278 ArgumentDefinitionTest test = ParserTestCase.parse6("parseArgumentDefinition
Test", "?x", []); |
| 279 JUnitTestCase.assertNotNull(test.question); | 279 JUnitTestCase.assertNotNull(test.question); |
| 280 JUnitTestCase.assertNotNull(test.identifier); | 280 JUnitTestCase.assertNotNull(test.identifier); |
| 281 } | 281 } |
| 282 void test_parseArgumentList_empty() { | 282 void test_parseArgumentList_empty() { |
| 283 ArgumentList argumentList = ParserTestCase.parse6("parseArgumentList", "()",
[]); | 283 ArgumentList argumentList = ParserTestCase.parse6("parseArgumentList", "()",
[]); |
| 284 NodeList<Expression> arguments7 = argumentList.arguments; | 284 NodeList<Expression> arguments8 = argumentList.arguments; |
| 285 EngineTestCase.assertSize(0, arguments7); | 285 EngineTestCase.assertSize(0, arguments8); |
| 286 } | 286 } |
| 287 void test_parseArgumentList_mixed() { | 287 void test_parseArgumentList_mixed() { |
| 288 ArgumentList argumentList = ParserTestCase.parse6("parseArgumentList", "(w,
x, y: y, z: z)", []); | 288 ArgumentList argumentList = ParserTestCase.parse6("parseArgumentList", "(w,
x, y: y, z: z)", []); |
| 289 NodeList<Expression> arguments8 = argumentList.arguments; | 289 NodeList<Expression> arguments9 = argumentList.arguments; |
| 290 EngineTestCase.assertSize(4, arguments8); | 290 EngineTestCase.assertSize(4, arguments9); |
| 291 } | 291 } |
| 292 void test_parseArgumentList_noNamed() { | 292 void test_parseArgumentList_noNamed() { |
| 293 ArgumentList argumentList = ParserTestCase.parse6("parseArgumentList", "(x,
y, z)", []); | 293 ArgumentList argumentList = ParserTestCase.parse6("parseArgumentList", "(x,
y, z)", []); |
| 294 NodeList<Expression> arguments9 = argumentList.arguments; | 294 NodeList<Expression> arguments10 = argumentList.arguments; |
| 295 EngineTestCase.assertSize(3, arguments9); | 295 EngineTestCase.assertSize(3, arguments10); |
| 296 } | 296 } |
| 297 void test_parseArgumentList_onlyNamed() { | 297 void test_parseArgumentList_onlyNamed() { |
| 298 ArgumentList argumentList = ParserTestCase.parse6("parseArgumentList", "(x:
x, y: y)", []); | 298 ArgumentList argumentList = ParserTestCase.parse6("parseArgumentList", "(x:
x, y: y)", []); |
| 299 NodeList<Expression> arguments10 = argumentList.arguments; | 299 NodeList<Expression> arguments11 = argumentList.arguments; |
| 300 EngineTestCase.assertSize(2, arguments10); | 300 EngineTestCase.assertSize(2, arguments11); |
| 301 } | 301 } |
| 302 void test_parseAssertStatement() { | 302 void test_parseAssertStatement() { |
| 303 AssertStatement statement = ParserTestCase.parse6("parseAssertStatement", "a
ssert (x);", []); | 303 AssertStatement statement = ParserTestCase.parse6("parseAssertStatement", "a
ssert (x);", []); |
| 304 JUnitTestCase.assertNotNull(statement.keyword); | 304 JUnitTestCase.assertNotNull(statement.keyword); |
| 305 JUnitTestCase.assertNotNull(statement.leftParenthesis); | 305 JUnitTestCase.assertNotNull(statement.leftParenthesis); |
| 306 JUnitTestCase.assertNotNull(statement.condition); | 306 JUnitTestCase.assertNotNull(statement.condition); |
| 307 JUnitTestCase.assertNotNull(statement.rightParenthesis); | 307 JUnitTestCase.assertNotNull(statement.rightParenthesis); |
| 308 JUnitTestCase.assertNotNull(statement.semicolon); | 308 JUnitTestCase.assertNotNull(statement.semicolon); |
| 309 } | 309 } |
| 310 void test_parseAssignableExpression_expression_args_dot() { | 310 void test_parseAssignableExpression_expression_args_dot() { |
| (...skipping 3215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3526 } | 3526 } |
| 3527 /** | 3527 /** |
| 3528 * Invoke the method {@link Parser#isFunctionDeclaration()} with the parser se
t to the token | 3528 * Invoke the method {@link Parser#isFunctionDeclaration()} with the parser se
t to the token |
| 3529 * stream produced by scanning the given source. | 3529 * stream produced by scanning the given source. |
| 3530 * @param source the source to be scanned to produce the token stream being te
sted | 3530 * @param source the source to be scanned to produce the token stream being te
sted |
| 3531 * @return the result of invoking the method | 3531 * @return the result of invoking the method |
| 3532 * @throws Exception if the method could not be invoked or throws an exception | 3532 * @throws Exception if the method could not be invoked or throws an exception |
| 3533 */ | 3533 */ |
| 3534 bool isFunctionDeclaration(String source) { | 3534 bool isFunctionDeclaration(String source) { |
| 3535 GatheringErrorListener listener = new GatheringErrorListener(); | 3535 GatheringErrorListener listener = new GatheringErrorListener(); |
| 3536 return ParserTestCase.invokeParserMethod2("isFunctionDeclaration", source, l
istener); | 3536 return ParserTestCase.invokeParserMethod2("isFunctionDeclaration", source, l
istener) as bool; |
| 3537 } | 3537 } |
| 3538 /** | 3538 /** |
| 3539 * Invoke the method {@link Parser#isFunctionExpression()} with the parser set
to the token stream | 3539 * Invoke the method {@link Parser#isFunctionExpression()} with the parser set
to the token stream |
| 3540 * produced by scanning the given source. | 3540 * produced by scanning the given source. |
| 3541 * @param source the source to be scanned to produce the token stream being te
sted | 3541 * @param source the source to be scanned to produce the token stream being te
sted |
| 3542 * @return the result of invoking the method | 3542 * @return the result of invoking the method |
| 3543 * @throws Exception if the method could not be invoked or throws an exception | 3543 * @throws Exception if the method could not be invoked or throws an exception |
| 3544 */ | 3544 */ |
| 3545 bool isFunctionExpression(String source) { | 3545 bool isFunctionExpression(String source) { |
| 3546 GatheringErrorListener listener = new GatheringErrorListener(); | 3546 GatheringErrorListener listener = new GatheringErrorListener(); |
| 3547 StringScanner scanner = new StringScanner(null, source, listener); | 3547 StringScanner scanner = new StringScanner(null, source, listener); |
| 3548 Token tokenStream = scanner.tokenize(); | 3548 Token tokenStream = scanner.tokenize(); |
| 3549 Parser parser = new Parser(null, listener); | 3549 Parser parser = new Parser(null, listener); |
| 3550 return invokeParserMethodImpl(parser, "isFunctionExpression", <Object> [toke
nStream], tokenStream) as bool; | 3550 return invokeParserMethodImpl(parser, "isFunctionExpression", <Object> [toke
nStream], tokenStream) as bool; |
| 3551 } | 3551 } |
| 3552 /** | 3552 /** |
| 3553 * Invoke the method {@link Parser#isInitializedVariableDeclaration()} with th
e parser set to the | 3553 * Invoke the method {@link Parser#isInitializedVariableDeclaration()} with th
e parser set to the |
| 3554 * token stream produced by scanning the given source. | 3554 * token stream produced by scanning the given source. |
| 3555 * @param source the source to be scanned to produce the token stream being te
sted | 3555 * @param source the source to be scanned to produce the token stream being te
sted |
| 3556 * @return the result of invoking the method | 3556 * @return the result of invoking the method |
| 3557 * @throws Exception if the method could not be invoked or throws an exception | 3557 * @throws Exception if the method could not be invoked or throws an exception |
| 3558 */ | 3558 */ |
| 3559 bool isInitializedVariableDeclaration(String source) { | 3559 bool isInitializedVariableDeclaration(String source) { |
| 3560 GatheringErrorListener listener = new GatheringErrorListener(); | 3560 GatheringErrorListener listener = new GatheringErrorListener(); |
| 3561 return ParserTestCase.invokeParserMethod2("isInitializedVariableDeclaration"
, source, listener); | 3561 return ParserTestCase.invokeParserMethod2("isInitializedVariableDeclaration"
, source, listener) as bool; |
| 3562 } | 3562 } |
| 3563 /** | 3563 /** |
| 3564 * Invoke the method {@link Parser#isSwitchMember()} with the parser set to th
e token stream | 3564 * Invoke the method {@link Parser#isSwitchMember()} with the parser set to th
e token stream |
| 3565 * produced by scanning the given source. | 3565 * produced by scanning the given source. |
| 3566 * @param source the source to be scanned to produce the token stream being te
sted | 3566 * @param source the source to be scanned to produce the token stream being te
sted |
| 3567 * @return the result of invoking the method | 3567 * @return the result of invoking the method |
| 3568 * @throws Exception if the method could not be invoked or throws an exception | 3568 * @throws Exception if the method could not be invoked or throws an exception |
| 3569 */ | 3569 */ |
| 3570 bool isSwitchMember(String source) { | 3570 bool isSwitchMember(String source) { |
| 3571 GatheringErrorListener listener = new GatheringErrorListener(); | 3571 GatheringErrorListener listener = new GatheringErrorListener(); |
| 3572 return ParserTestCase.invokeParserMethod2("isSwitchMember", source, listener
); | 3572 return ParserTestCase.invokeParserMethod2("isSwitchMember", source, listener
) as bool; |
| 3573 } | 3573 } |
| 3574 /** | 3574 /** |
| 3575 * Invoke a "skip" method in {@link Parser}. The method is assumed to take a t
oken as it's | 3575 * Invoke a "skip" method in {@link Parser}. The method is assumed to take a t
oken as it's |
| 3576 * parameter and is given the first token in the scanned source. | 3576 * parameter and is given the first token in the scanned source. |
| 3577 * @param methodName the name of the method that should be invoked | 3577 * @param methodName the name of the method that should be invoked |
| 3578 * @param source the source to be processed by the method | 3578 * @param source the source to be processed by the method |
| 3579 * @return the result of invoking the method | 3579 * @return the result of invoking the method |
| 3580 * @throws Exception if the method could not be invoked or throws an exception | 3580 * @throws Exception if the method could not be invoked or throws an exception |
| 3581 * @throws AssertionFailedError if the result is {@code null} | 3581 * @throws AssertionFailedError if the result is {@code null} |
| 3582 */ | 3582 */ |
| (...skipping 2929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6512 EngineTestCase.assertInstanceOf(SimpleIdentifier, syntheticExpression); | 6512 EngineTestCase.assertInstanceOf(SimpleIdentifier, syntheticExpression); |
| 6513 JUnitTestCase.assertTrue(syntheticExpression.isSynthetic()); | 6513 JUnitTestCase.assertTrue(syntheticExpression.isSynthetic()); |
| 6514 } | 6514 } |
| 6515 void test_expressionList_multiple_start() { | 6515 void test_expressionList_multiple_start() { |
| 6516 List<Expression> result = ParserTestCase.parse6("parseExpressionList", "1, 2
, 3,", []); | 6516 List<Expression> result = ParserTestCase.parse6("parseExpressionList", "1, 2
, 3,", []); |
| 6517 EngineTestCase.assertSize(4, result); | 6517 EngineTestCase.assertSize(4, result); |
| 6518 Expression syntheticExpression = result[3]; | 6518 Expression syntheticExpression = result[3]; |
| 6519 EngineTestCase.assertInstanceOf(SimpleIdentifier, syntheticExpression); | 6519 EngineTestCase.assertInstanceOf(SimpleIdentifier, syntheticExpression); |
| 6520 JUnitTestCase.assertTrue(syntheticExpression.isSynthetic()); | 6520 JUnitTestCase.assertTrue(syntheticExpression.isSynthetic()); |
| 6521 } | 6521 } |
| 6522 void test_isExpression_noType() { |
| 6523 CompilationUnit unit = ParserTestCase.parseCompilationUnit("class Bar<T exte
nds Foo> {m(x){if (x is ) return;if (x is !)}}", [ParserErrorCode.MISSING_IDENTI
FIER, ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.MISSING_STATEMENT]); |
| 6524 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; |
| 6525 MethodDeclaration method = declaration.members[0] as MethodDeclaration; |
| 6526 BlockFunctionBody body5 = method.body as BlockFunctionBody; |
| 6527 IfStatement ifStatement = body5.block.statements[1] as IfStatement; |
| 6528 IsExpression expression = ifStatement.condition as IsExpression; |
| 6529 JUnitTestCase.assertNotNull(expression.expression); |
| 6530 JUnitTestCase.assertNotNull(expression.isOperator); |
| 6531 JUnitTestCase.assertNotNull(expression.notOperator); |
| 6532 TypeName type29 = expression.type; |
| 6533 JUnitTestCase.assertNotNull(type29); |
| 6534 JUnitTestCase.assertTrue(type29.name.isSynthetic()); |
| 6535 EngineTestCase.assertInstanceOf(EmptyStatement, ifStatement.thenStatement); |
| 6536 } |
| 6522 void test_logicalAndExpression_missing_LHS() { | 6537 void test_logicalAndExpression_missing_LHS() { |
| 6523 BinaryExpression expression = ParserTestCase.parseExpression("&& y", []); | 6538 BinaryExpression expression = ParserTestCase.parseExpression("&& y", []); |
| 6524 EngineTestCase.assertInstanceOf(SimpleIdentifier, expression.leftOperand); | 6539 EngineTestCase.assertInstanceOf(SimpleIdentifier, expression.leftOperand); |
| 6525 JUnitTestCase.assertTrue(expression.leftOperand.isSynthetic()); | 6540 JUnitTestCase.assertTrue(expression.leftOperand.isSynthetic()); |
| 6526 } | 6541 } |
| 6527 void test_logicalAndExpression_missing_LHS_RHS() { | 6542 void test_logicalAndExpression_missing_LHS_RHS() { |
| 6528 BinaryExpression expression = ParserTestCase.parseExpression("&&", []); | 6543 BinaryExpression expression = ParserTestCase.parseExpression("&&", []); |
| 6529 EngineTestCase.assertInstanceOf(SimpleIdentifier, expression.leftOperand); | 6544 EngineTestCase.assertInstanceOf(SimpleIdentifier, expression.leftOperand); |
| 6530 JUnitTestCase.assertTrue(expression.leftOperand.isSynthetic()); | 6545 JUnitTestCase.assertTrue(expression.leftOperand.isSynthetic()); |
| 6531 EngineTestCase.assertInstanceOf(SimpleIdentifier, expression.rightOperand); | 6546 EngineTestCase.assertInstanceOf(SimpleIdentifier, expression.rightOperand); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6850 runJUnitTest(__test, __test.test_expressionList_multiple_end); | 6865 runJUnitTest(__test, __test.test_expressionList_multiple_end); |
| 6851 }); | 6866 }); |
| 6852 _ut.test('test_expressionList_multiple_middle', () { | 6867 _ut.test('test_expressionList_multiple_middle', () { |
| 6853 final __test = new RecoveryParserTest(); | 6868 final __test = new RecoveryParserTest(); |
| 6854 runJUnitTest(__test, __test.test_expressionList_multiple_middle); | 6869 runJUnitTest(__test, __test.test_expressionList_multiple_middle); |
| 6855 }); | 6870 }); |
| 6856 _ut.test('test_expressionList_multiple_start', () { | 6871 _ut.test('test_expressionList_multiple_start', () { |
| 6857 final __test = new RecoveryParserTest(); | 6872 final __test = new RecoveryParserTest(); |
| 6858 runJUnitTest(__test, __test.test_expressionList_multiple_start); | 6873 runJUnitTest(__test, __test.test_expressionList_multiple_start); |
| 6859 }); | 6874 }); |
| 6875 _ut.test('test_isExpression_noType', () { |
| 6876 final __test = new RecoveryParserTest(); |
| 6877 runJUnitTest(__test, __test.test_isExpression_noType); |
| 6878 }); |
| 6860 _ut.test('test_logicalAndExpression_missing_LHS', () { | 6879 _ut.test('test_logicalAndExpression_missing_LHS', () { |
| 6861 final __test = new RecoveryParserTest(); | 6880 final __test = new RecoveryParserTest(); |
| 6862 runJUnitTest(__test, __test.test_logicalAndExpression_missing_LHS); | 6881 runJUnitTest(__test, __test.test_logicalAndExpression_missing_LHS); |
| 6863 }); | 6882 }); |
| 6864 _ut.test('test_logicalAndExpression_missing_LHS_RHS', () { | 6883 _ut.test('test_logicalAndExpression_missing_LHS_RHS', () { |
| 6865 final __test = new RecoveryParserTest(); | 6884 final __test = new RecoveryParserTest(); |
| 6866 runJUnitTest(__test, __test.test_logicalAndExpression_missing_LHS_RHS); | 6885 runJUnitTest(__test, __test.test_logicalAndExpression_missing_LHS_RHS); |
| 6867 }); | 6886 }); |
| 6868 _ut.test('test_logicalAndExpression_missing_RHS', () { | 6887 _ut.test('test_logicalAndExpression_missing_RHS', () { |
| 6869 final __test = new RecoveryParserTest(); | 6888 final __test = new RecoveryParserTest(); |
| (...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8313 'validateModifiersForTopLevelFunction_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelFunction(arg0)), | 8332 'validateModifiersForTopLevelFunction_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelFunction(arg0)), |
| 8314 'validateModifiersForTopLevelVariable_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelVariable(arg0)), | 8333 'validateModifiersForTopLevelVariable_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelVariable(arg0)), |
| 8315 'validateModifiersForTypedef_1': new MethodTrampoline(1, (Parser target, arg0)
=> target.validateModifiersForTypedef(arg0)),}; | 8334 'validateModifiersForTypedef_1': new MethodTrampoline(1, (Parser target, arg0)
=> target.validateModifiersForTypedef(arg0)),}; |
| 8316 | 8335 |
| 8317 | 8336 |
| 8318 Object invokeParserMethodImpl(Parser parser, String methodName, List<Object> obj
ects, Token tokenStream) { | 8337 Object invokeParserMethodImpl(Parser parser, String methodName, List<Object> obj
ects, Token tokenStream) { |
| 8319 parser.currentToken = tokenStream; | 8338 parser.currentToken = tokenStream; |
| 8320 MethodTrampoline method = _methodTable_Parser['${methodName}_${objects.length}
']; | 8339 MethodTrampoline method = _methodTable_Parser['${methodName}_${objects.length}
']; |
| 8321 return method.invoke(parser, objects); | 8340 return method.invoke(parser, objects); |
| 8322 } | 8341 } |
| OLD | NEW |