| OLD | NEW |
| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.parser_test; | 8 library engine.parser_test; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/java_core.dart'; | 10 import 'package:analyzer/src/generated/java_core.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * The class `SimpleParserTest` defines parser tests that test individual parsin
g method. The | 26 * The class `SimpleParserTest` defines parser tests that test individual parsin
g method. The |
| 27 * code fragments should be as minimal as possible in order to test the method,
but should not test | 27 * code fragments should be as minimal as possible in order to test the method,
but should not test |
| 28 * the interactions between the method under test and other methods. | 28 * the interactions between the method under test and other methods. |
| 29 * | 29 * |
| 30 * More complex tests should be defined in the class [ComplexParserTest]. | 30 * More complex tests should be defined in the class [ComplexParserTest]. |
| 31 */ | 31 */ |
| 32 class SimpleParserTest extends ParserTestCase { | 32 class SimpleParserTest extends ParserTestCase { |
| 33 void fail_parseCommentReference_this() { | 33 void fail_parseCommentReference_this() { |
| 34 // This fails because we are returning null from the method and asserting th
at the return value |
| 35 // is not null. |
| 34 CommentReference reference = ParserTestCase.parse("parseCommentReference", <
Object> ["this", 5], ""); | 36 CommentReference reference = ParserTestCase.parse("parseCommentReference", <
Object> ["this", 5], ""); |
| 35 SimpleIdentifier identifier = EngineTestCase.assertInstanceOf(SimpleIdentifi
er, reference.identifier); | 37 SimpleIdentifier identifier = EngineTestCase.assertInstanceOf(SimpleIdentifi
er, reference.identifier); |
| 36 JUnitTestCase.assertNotNull(identifier.token); | 38 JUnitTestCase.assertNotNull(identifier.token); |
| 37 JUnitTestCase.assertEquals("a", identifier.name); | 39 JUnitTestCase.assertEquals("a", identifier.name); |
| 38 JUnitTestCase.assertEquals(5, identifier.offset); | 40 JUnitTestCase.assertEquals(5, identifier.offset); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void test_computeStringValue_emptyInterpolationPrefix() { | 43 void test_computeStringValue_emptyInterpolationPrefix() { |
| 42 JUnitTestCase.assertEquals("", computeStringValue("'''", true, false)); | 44 JUnitTestCase.assertEquals("", computeStringValue("'''", true, false)); |
| 43 } | 45 } |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 JUnitTestCase.assertNotNull(declaration.classKeyword); | 827 JUnitTestCase.assertNotNull(declaration.classKeyword); |
| 826 JUnitTestCase.assertNotNull(declaration.leftBracket); | 828 JUnitTestCase.assertNotNull(declaration.leftBracket); |
| 827 JUnitTestCase.assertNotNull(declaration.name); | 829 JUnitTestCase.assertNotNull(declaration.name); |
| 828 EngineTestCase.assertSize(0, declaration.members); | 830 EngineTestCase.assertSize(0, declaration.members); |
| 829 JUnitTestCase.assertNotNull(declaration.rightBracket); | 831 JUnitTestCase.assertNotNull(declaration.rightBracket); |
| 830 JUnitTestCase.assertNotNull(declaration.typeParameters); | 832 JUnitTestCase.assertNotNull(declaration.typeParameters); |
| 831 EngineTestCase.assertSize(1, declaration.typeParameters.typeParameters); | 833 EngineTestCase.assertSize(1, declaration.typeParameters.typeParameters); |
| 832 } | 834 } |
| 833 | 835 |
| 834 void test_parseClassMember_constructor_withInitializers() { | 836 void test_parseClassMember_constructor_withInitializers() { |
| 837 // TODO(brianwilkerson) Test other kinds of class members: fields, getters a
nd setters. |
| 835 ConstructorDeclaration constructor = ParserTestCase.parse("parseClassMember"
, <Object> ["C"], "C(_, _\$, this.__) : _a = _ + _\$ {}"); | 838 ConstructorDeclaration constructor = ParserTestCase.parse("parseClassMember"
, <Object> ["C"], "C(_, _\$, this.__) : _a = _ + _\$ {}"); |
| 836 JUnitTestCase.assertNotNull(constructor.body); | 839 JUnitTestCase.assertNotNull(constructor.body); |
| 837 JUnitTestCase.assertNotNull(constructor.separator); | 840 JUnitTestCase.assertNotNull(constructor.separator); |
| 838 JUnitTestCase.assertNull(constructor.externalKeyword); | 841 JUnitTestCase.assertNull(constructor.externalKeyword); |
| 839 JUnitTestCase.assertNull(constructor.constKeyword); | 842 JUnitTestCase.assertNull(constructor.constKeyword); |
| 840 JUnitTestCase.assertNull(constructor.factoryKeyword); | 843 JUnitTestCase.assertNull(constructor.factoryKeyword); |
| 841 JUnitTestCase.assertNull(constructor.name); | 844 JUnitTestCase.assertNull(constructor.name); |
| 842 JUnitTestCase.assertNotNull(constructor.parameters); | 845 JUnitTestCase.assertNotNull(constructor.parameters); |
| 843 JUnitTestCase.assertNull(constructor.period); | 846 JUnitTestCase.assertNull(constructor.period); |
| 844 JUnitTestCase.assertNotNull(constructor.returnType); | 847 JUnitTestCase.assertNotNull(constructor.returnType); |
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1958 | 1961 |
| 1959 void test_parseExportDirective_show_hide() { | 1962 void test_parseExportDirective_show_hide() { |
| 1960 ExportDirective directive = ParserTestCase.parse("parseExportDirective", <Ob
ject> [emptyCommentAndMetadata()], "export 'lib/lib.dart' show B hide A;"); | 1963 ExportDirective directive = ParserTestCase.parse("parseExportDirective", <Ob
ject> [emptyCommentAndMetadata()], "export 'lib/lib.dart' show B hide A;"); |
| 1961 JUnitTestCase.assertNotNull(directive.keyword); | 1964 JUnitTestCase.assertNotNull(directive.keyword); |
| 1962 JUnitTestCase.assertNotNull(directive.uri); | 1965 JUnitTestCase.assertNotNull(directive.uri); |
| 1963 EngineTestCase.assertSize(2, directive.combinators); | 1966 EngineTestCase.assertSize(2, directive.combinators); |
| 1964 JUnitTestCase.assertNotNull(directive.semicolon); | 1967 JUnitTestCase.assertNotNull(directive.semicolon); |
| 1965 } | 1968 } |
| 1966 | 1969 |
| 1967 void test_parseExpression_assign() { | 1970 void test_parseExpression_assign() { |
| 1971 // TODO(brianwilkerson) Implement more tests for this method. |
| 1968 AssignmentExpression expression = ParserTestCase.parse5("parseExpression", "
x = y", []); | 1972 AssignmentExpression expression = ParserTestCase.parse5("parseExpression", "
x = y", []); |
| 1969 JUnitTestCase.assertNotNull(expression.leftHandSide); | 1973 JUnitTestCase.assertNotNull(expression.leftHandSide); |
| 1970 JUnitTestCase.assertNotNull(expression.operator); | 1974 JUnitTestCase.assertNotNull(expression.operator); |
| 1971 JUnitTestCase.assertEquals(TokenType.EQ, expression.operator.type); | 1975 JUnitTestCase.assertEquals(TokenType.EQ, expression.operator.type); |
| 1972 JUnitTestCase.assertNotNull(expression.rightHandSide); | 1976 JUnitTestCase.assertNotNull(expression.rightHandSide); |
| 1973 } | 1977 } |
| 1974 | 1978 |
| 1975 void test_parseExpression_comparison() { | 1979 void test_parseExpression_comparison() { |
| 1976 BinaryExpression expression = ParserTestCase.parse5("parseExpression", "--a.
b == c", []); | 1980 BinaryExpression expression = ParserTestCase.parse5("parseExpression", "--a.
b == c", []); |
| 1977 JUnitTestCase.assertNotNull(expression.leftOperand); | 1981 JUnitTestCase.assertNotNull(expression.leftOperand); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2002 List<Expression> result = ParserTestCase.parse5("parseExpressionList", "1, 2
, 3", []); | 2006 List<Expression> result = ParserTestCase.parse5("parseExpressionList", "1, 2
, 3", []); |
| 2003 EngineTestCase.assertSize(3, result); | 2007 EngineTestCase.assertSize(3, result); |
| 2004 } | 2008 } |
| 2005 | 2009 |
| 2006 void test_parseExpressionList_single() { | 2010 void test_parseExpressionList_single() { |
| 2007 List<Expression> result = ParserTestCase.parse5("parseExpressionList", "1",
[]); | 2011 List<Expression> result = ParserTestCase.parse5("parseExpressionList", "1",
[]); |
| 2008 EngineTestCase.assertSize(1, result); | 2012 EngineTestCase.assertSize(1, result); |
| 2009 } | 2013 } |
| 2010 | 2014 |
| 2011 void test_parseExpressionWithoutCascade_assign() { | 2015 void test_parseExpressionWithoutCascade_assign() { |
| 2016 // TODO(brianwilkerson) Implement more tests for this method. |
| 2012 AssignmentExpression expression = ParserTestCase.parse5("parseExpressionWith
outCascade", "x = y", []); | 2017 AssignmentExpression expression = ParserTestCase.parse5("parseExpressionWith
outCascade", "x = y", []); |
| 2013 JUnitTestCase.assertNotNull(expression.leftHandSide); | 2018 JUnitTestCase.assertNotNull(expression.leftHandSide); |
| 2014 JUnitTestCase.assertNotNull(expression.operator); | 2019 JUnitTestCase.assertNotNull(expression.operator); |
| 2015 JUnitTestCase.assertEquals(TokenType.EQ, expression.operator.type); | 2020 JUnitTestCase.assertEquals(TokenType.EQ, expression.operator.type); |
| 2016 JUnitTestCase.assertNotNull(expression.rightHandSide); | 2021 JUnitTestCase.assertNotNull(expression.rightHandSide); |
| 2017 } | 2022 } |
| 2018 | 2023 |
| 2019 void test_parseExpressionWithoutCascade_comparison() { | 2024 void test_parseExpressionWithoutCascade_comparison() { |
| 2020 BinaryExpression expression = ParserTestCase.parse5("parseExpressionWithoutC
ascade", "--a.b == c", []); | 2025 BinaryExpression expression = ParserTestCase.parse5("parseExpressionWithoutC
ascade", "--a.b == c", []); |
| 2021 JUnitTestCase.assertNotNull(expression.leftOperand); | 2026 JUnitTestCase.assertNotNull(expression.leftOperand); |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3084 ExpressionStatement statement = ParserTestCase.parse5("parseNonLabeledStatem
ent", "const [1, 2];", []); | 3089 ExpressionStatement statement = ParserTestCase.parse5("parseNonLabeledStatem
ent", "const [1, 2];", []); |
| 3085 JUnitTestCase.assertNotNull(statement.expression); | 3090 JUnitTestCase.assertNotNull(statement.expression); |
| 3086 } | 3091 } |
| 3087 | 3092 |
| 3088 void test_parseNonLabeledStatement_const_map_empty() { | 3093 void test_parseNonLabeledStatement_const_map_empty() { |
| 3089 ExpressionStatement statement = ParserTestCase.parse5("parseNonLabeledStatem
ent", "const {};", []); | 3094 ExpressionStatement statement = ParserTestCase.parse5("parseNonLabeledStatem
ent", "const {};", []); |
| 3090 JUnitTestCase.assertNotNull(statement.expression); | 3095 JUnitTestCase.assertNotNull(statement.expression); |
| 3091 } | 3096 } |
| 3092 | 3097 |
| 3093 void test_parseNonLabeledStatement_const_map_nonEmpty() { | 3098 void test_parseNonLabeledStatement_const_map_nonEmpty() { |
| 3099 // TODO(brianwilkerson) Implement more tests for this method. |
| 3094 ExpressionStatement statement = ParserTestCase.parse5("parseNonLabeledStatem
ent", "const {'a' : 1};", []); | 3100 ExpressionStatement statement = ParserTestCase.parse5("parseNonLabeledStatem
ent", "const {'a' : 1};", []); |
| 3095 JUnitTestCase.assertNotNull(statement.expression); | 3101 JUnitTestCase.assertNotNull(statement.expression); |
| 3096 } | 3102 } |
| 3097 | 3103 |
| 3098 void test_parseNonLabeledStatement_const_object() { | 3104 void test_parseNonLabeledStatement_const_object() { |
| 3099 ExpressionStatement statement = ParserTestCase.parse5("parseNonLabeledStatem
ent", "const A();", []); | 3105 ExpressionStatement statement = ParserTestCase.parse5("parseNonLabeledStatem
ent", "const A();", []); |
| 3100 JUnitTestCase.assertNotNull(statement.expression); | 3106 JUnitTestCase.assertNotNull(statement.expression); |
| 3101 } | 3107 } |
| 3102 | 3108 |
| 3103 void test_parseNonLabeledStatement_const_object_named_typeParameters() { | 3109 void test_parseNonLabeledStatement_const_object_named_typeParameters() { |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3668 String lexeme = "foo"; | 3674 String lexeme = "foo"; |
| 3669 SimpleIdentifier identifier = ParserTestCase.parse5("parseSimpleIdentifier",
lexeme, []); | 3675 SimpleIdentifier identifier = ParserTestCase.parse5("parseSimpleIdentifier",
lexeme, []); |
| 3670 JUnitTestCase.assertNotNull(identifier.token); | 3676 JUnitTestCase.assertNotNull(identifier.token); |
| 3671 JUnitTestCase.assertEquals(lexeme, identifier.name); | 3677 JUnitTestCase.assertEquals(lexeme, identifier.name); |
| 3672 } | 3678 } |
| 3673 | 3679 |
| 3674 void test_parseSimpleIdentifier1_normalIdentifier() { | 3680 void test_parseSimpleIdentifier1_normalIdentifier() { |
| 3675 } | 3681 } |
| 3676 | 3682 |
| 3677 void test_parseStatement_functionDeclaration() { | 3683 void test_parseStatement_functionDeclaration() { |
| 3684 // TODO(brianwilkerson) Implement more tests for this method. |
| 3678 FunctionDeclarationStatement statement = ParserTestCase.parse5("parseStateme
nt", "int f(a, b) {};", []); | 3685 FunctionDeclarationStatement statement = ParserTestCase.parse5("parseStateme
nt", "int f(a, b) {};", []); |
| 3679 JUnitTestCase.assertNotNull(statement.functionDeclaration); | 3686 JUnitTestCase.assertNotNull(statement.functionDeclaration); |
| 3680 } | 3687 } |
| 3681 | 3688 |
| 3682 void test_parseStatement_mulipleLabels() { | 3689 void test_parseStatement_mulipleLabels() { |
| 3683 LabeledStatement statement = ParserTestCase.parse5("parseStatement", "l: m:
return x;", []); | 3690 LabeledStatement statement = ParserTestCase.parse5("parseStatement", "l: m:
return x;", []); |
| 3684 EngineTestCase.assertSize(2, statement.labels); | 3691 EngineTestCase.assertSize(2, statement.labels); |
| 3685 JUnitTestCase.assertNotNull(statement.statement); | 3692 JUnitTestCase.assertNotNull(statement.statement); |
| 3686 } | 3693 } |
| 3687 | 3694 |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4477 /** | 4484 /** |
| 4478 * Invoke the method [Parser#isFunctionExpression] with the parser set to the
token stream | 4485 * Invoke the method [Parser#isFunctionExpression] with the parser set to the
token stream |
| 4479 * produced by scanning the given source. | 4486 * produced by scanning the given source. |
| 4480 * | 4487 * |
| 4481 * @param source the source to be scanned to produce the token stream being te
sted | 4488 * @param source the source to be scanned to produce the token stream being te
sted |
| 4482 * @return the result of invoking the method | 4489 * @return the result of invoking the method |
| 4483 * @throws Exception if the method could not be invoked or throws an exception | 4490 * @throws Exception if the method could not be invoked or throws an exception |
| 4484 */ | 4491 */ |
| 4485 bool isFunctionExpression(String source) { | 4492 bool isFunctionExpression(String source) { |
| 4486 GatheringErrorListener listener = new GatheringErrorListener(); | 4493 GatheringErrorListener listener = new GatheringErrorListener(); |
| 4494 // |
| 4495 // Scan the source. |
| 4496 // |
| 4487 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); | 4497 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); |
| 4488 Token tokenStream = scanner.tokenize(); | 4498 Token tokenStream = scanner.tokenize(); |
| 4499 // |
| 4500 // Parse the source. |
| 4501 // |
| 4489 Parser parser = new Parser(null, listener); | 4502 Parser parser = new Parser(null, listener); |
| 4490 return invokeParserMethodImpl(parser, "isFunctionExpression", <Object> [toke
nStream], tokenStream) as bool; | 4503 return invokeParserMethodImpl(parser, "isFunctionExpression", <Object> [toke
nStream], tokenStream) as bool; |
| 4491 } | 4504 } |
| 4492 | 4505 |
| 4493 /** | 4506 /** |
| 4494 * Invoke the method [Parser#isInitializedVariableDeclaration] with the parser
set to the | 4507 * Invoke the method [Parser#isInitializedVariableDeclaration] with the parser
set to the |
| 4495 * token stream produced by scanning the given source. | 4508 * token stream produced by scanning the given source. |
| 4496 * | 4509 * |
| 4497 * @param source the source to be scanned to produce the token stream being te
sted | 4510 * @param source the source to be scanned to produce the token stream being te
sted |
| 4498 * @return the result of invoking the method | 4511 * @return the result of invoking the method |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4521 * parameter and is given the first token in the scanned source. | 4534 * parameter and is given the first token in the scanned source. |
| 4522 * | 4535 * |
| 4523 * @param methodName the name of the method that should be invoked | 4536 * @param methodName the name of the method that should be invoked |
| 4524 * @param source the source to be processed by the method | 4537 * @param source the source to be processed by the method |
| 4525 * @return the result of invoking the method | 4538 * @return the result of invoking the method |
| 4526 * @throws Exception if the method could not be invoked or throws an exception | 4539 * @throws Exception if the method could not be invoked or throws an exception |
| 4527 * @throws AssertionFailedError if the result is `null` | 4540 * @throws AssertionFailedError if the result is `null` |
| 4528 */ | 4541 */ |
| 4529 Token skip(String methodName, String source) { | 4542 Token skip(String methodName, String source) { |
| 4530 GatheringErrorListener listener = new GatheringErrorListener(); | 4543 GatheringErrorListener listener = new GatheringErrorListener(); |
| 4544 // |
| 4545 // Scan the source. |
| 4546 // |
| 4531 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); | 4547 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); |
| 4532 Token tokenStream = scanner.tokenize(); | 4548 Token tokenStream = scanner.tokenize(); |
| 4549 // |
| 4550 // Parse the source. |
| 4551 // |
| 4533 Parser parser = new Parser(null, listener); | 4552 Parser parser = new Parser(null, listener); |
| 4534 return invokeParserMethodImpl(parser, methodName, <Object> [tokenStream], to
kenStream) as Token; | 4553 return invokeParserMethodImpl(parser, methodName, <Object> [tokenStream], to
kenStream) as Token; |
| 4535 } | 4554 } |
| 4536 | 4555 |
| 4537 static dartSuite() { | 4556 static dartSuite() { |
| 4538 _ut.group('SimpleParserTest', () { | 4557 _ut.group('SimpleParserTest', () { |
| 4539 _ut.test('test_Parser', () { | 4558 _ut.test('test_Parser', () { |
| 4540 final __test = new SimpleParserTest(); | 4559 final __test = new SimpleParserTest(); |
| 4541 runJUnitTest(__test, __test.test_Parser); | 4560 runJUnitTest(__test, __test.test_Parser); |
| 4542 }); | 4561 }); |
| (...skipping 2225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6768 } | 6787 } |
| 6769 | 6788 |
| 6770 void test_additiveExpression_super() { | 6789 void test_additiveExpression_super() { |
| 6771 BinaryExpression expression = ParserTestCase.parseExpression("super + y - z"
, []); | 6790 BinaryExpression expression = ParserTestCase.parseExpression("super + y - z"
, []); |
| 6772 EngineTestCase.assertInstanceOf(BinaryExpression, expression.leftOperand); | 6791 EngineTestCase.assertInstanceOf(BinaryExpression, expression.leftOperand); |
| 6773 } | 6792 } |
| 6774 | 6793 |
| 6775 void test_assignableExpression_arguments_normal_chain() { | 6794 void test_assignableExpression_arguments_normal_chain() { |
| 6776 PropertyAccess propertyAccess1 = ParserTestCase.parseExpression("a(b)(c).d(e
).f", []); | 6795 PropertyAccess propertyAccess1 = ParserTestCase.parseExpression("a(b)(c).d(e
).f", []); |
| 6777 JUnitTestCase.assertEquals("f", propertyAccess1.propertyName.name); | 6796 JUnitTestCase.assertEquals("f", propertyAccess1.propertyName.name); |
| 6797 // |
| 6798 // a(b)(c).d(e) |
| 6799 // |
| 6778 MethodInvocation invocation2 = EngineTestCase.assertInstanceOf(MethodInvocat
ion, propertyAccess1.target); | 6800 MethodInvocation invocation2 = EngineTestCase.assertInstanceOf(MethodInvocat
ion, propertyAccess1.target); |
| 6779 JUnitTestCase.assertEquals("d", invocation2.methodName.name); | 6801 JUnitTestCase.assertEquals("d", invocation2.methodName.name); |
| 6780 ArgumentList argumentList2 = invocation2.argumentList; | 6802 ArgumentList argumentList2 = invocation2.argumentList; |
| 6781 JUnitTestCase.assertNotNull(argumentList2); | 6803 JUnitTestCase.assertNotNull(argumentList2); |
| 6782 EngineTestCase.assertSize(1, argumentList2.arguments); | 6804 EngineTestCase.assertSize(1, argumentList2.arguments); |
| 6805 // |
| 6806 // a(b)(c) |
| 6807 // |
| 6783 FunctionExpressionInvocation invocation3 = EngineTestCase.assertInstanceOf(F
unctionExpressionInvocation, invocation2.target); | 6808 FunctionExpressionInvocation invocation3 = EngineTestCase.assertInstanceOf(F
unctionExpressionInvocation, invocation2.target); |
| 6784 ArgumentList argumentList3 = invocation3.argumentList; | 6809 ArgumentList argumentList3 = invocation3.argumentList; |
| 6785 JUnitTestCase.assertNotNull(argumentList3); | 6810 JUnitTestCase.assertNotNull(argumentList3); |
| 6786 EngineTestCase.assertSize(1, argumentList3.arguments); | 6811 EngineTestCase.assertSize(1, argumentList3.arguments); |
| 6812 // |
| 6813 // a(b) |
| 6814 // |
| 6787 MethodInvocation invocation4 = EngineTestCase.assertInstanceOf(MethodInvocat
ion, invocation3.function); | 6815 MethodInvocation invocation4 = EngineTestCase.assertInstanceOf(MethodInvocat
ion, invocation3.function); |
| 6788 JUnitTestCase.assertEquals("a", invocation4.methodName.name); | 6816 JUnitTestCase.assertEquals("a", invocation4.methodName.name); |
| 6789 ArgumentList argumentList4 = invocation4.argumentList; | 6817 ArgumentList argumentList4 = invocation4.argumentList; |
| 6790 JUnitTestCase.assertNotNull(argumentList4); | 6818 JUnitTestCase.assertNotNull(argumentList4); |
| 6791 EngineTestCase.assertSize(1, argumentList4.arguments); | 6819 EngineTestCase.assertSize(1, argumentList4.arguments); |
| 6792 } | 6820 } |
| 6793 | 6821 |
| 6794 void test_assignmentExpression_compound() { | 6822 void test_assignmentExpression_compound() { |
| 6795 AssignmentExpression expression = ParserTestCase.parseExpression("x = y = 0"
, []); | 6823 AssignmentExpression expression = ParserTestCase.parseExpression("x = y = 0"
, []); |
| 6796 EngineTestCase.assertInstanceOf(SimpleIdentifier, expression.leftHandSide); | 6824 EngineTestCase.assertInstanceOf(SimpleIdentifier, expression.leftHandSide); |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7460 * @param methodName the name of the method that should be invoked | 7488 * @param methodName the name of the method that should be invoked |
| 7461 * @param objects the values of the arguments to the method | 7489 * @param objects the values of the arguments to the method |
| 7462 * @param source the source to be processed by the parse method | 7490 * @param source the source to be processed by the parse method |
| 7463 * @param listener the error listener that will be used for both scanning and
parsing | 7491 * @param listener the error listener that will be used for both scanning and
parsing |
| 7464 * @return the result of invoking the method | 7492 * @return the result of invoking the method |
| 7465 * @throws Exception if the method could not be invoked or throws an exception | 7493 * @throws Exception if the method could not be invoked or throws an exception |
| 7466 * @throws AssertionFailedError if the result is `null` or the errors produced
while | 7494 * @throws AssertionFailedError if the result is `null` or the errors produced
while |
| 7467 * scanning and parsing the source do not match the expected errors | 7495 * scanning and parsing the source do not match the expected errors |
| 7468 */ | 7496 */ |
| 7469 static Object invokeParserMethod(String methodName, List<Object> objects, Stri
ng source, GatheringErrorListener listener) { | 7497 static Object invokeParserMethod(String methodName, List<Object> objects, Stri
ng source, GatheringErrorListener listener) { |
| 7498 // |
| 7499 // Scan the source. |
| 7500 // |
| 7470 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); | 7501 Scanner scanner = new Scanner(null, new CharSequenceReader(new CharSequence(
source)), listener); |
| 7471 Token tokenStream = scanner.tokenize(); | 7502 Token tokenStream = scanner.tokenize(); |
| 7472 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 7503 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 7504 // |
| 7505 // Parse the source. |
| 7506 // |
| 7473 Parser parser = new Parser(null, listener); | 7507 Parser parser = new Parser(null, listener); |
| 7474 parser.parseFunctionBodies = _parseFunctionBodies; | 7508 parser.parseFunctionBodies = _parseFunctionBodies; |
| 7475 Object result = invokeParserMethodImpl(parser, methodName, objects, tokenStr
eam); | 7509 Object result = invokeParserMethodImpl(parser, methodName, objects, tokenStr
eam); |
| 7510 // |
| 7511 // Partially test the results. |
| 7512 // |
| 7476 if (!listener.hasErrors()) { | 7513 if (!listener.hasErrors()) { |
| 7477 JUnitTestCase.assertNotNull(result); | 7514 JUnitTestCase.assertNotNull(result); |
| 7478 } | 7515 } |
| 7479 return result; | 7516 return result; |
| 7480 } | 7517 } |
| 7481 | 7518 |
| 7482 /** | 7519 /** |
| 7483 * Invoke a method in [Parser]. The method is assumed to have no arguments. | 7520 * Invoke a method in [Parser]. The method is assumed to have no arguments. |
| 7484 * | 7521 * |
| 7485 * The given source is scanned and the parser is initialized to start with the
first token in the | 7522 * The given source is scanned and the parser is initialized to start with the
first token in the |
| (...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9175 _ut.test('test_typedef_eof', () { | 9212 _ut.test('test_typedef_eof', () { |
| 9176 final __test = new RecoveryParserTest(); | 9213 final __test = new RecoveryParserTest(); |
| 9177 runJUnitTest(__test, __test.test_typedef_eof); | 9214 runJUnitTest(__test, __test.test_typedef_eof); |
| 9178 }); | 9215 }); |
| 9179 }); | 9216 }); |
| 9180 } | 9217 } |
| 9181 } | 9218 } |
| 9182 | 9219 |
| 9183 class IncrementalParserTest extends EngineTestCase { | 9220 class IncrementalParserTest extends EngineTestCase { |
| 9184 void test_delete_everything() { | 9221 void test_delete_everything() { |
| 9222 // "f() => a + b;" |
| 9223 // "" |
| 9185 assertParse("", "f() => a + b;", "", ""); | 9224 assertParse("", "f() => a + b;", "", ""); |
| 9186 } | 9225 } |
| 9187 | 9226 |
| 9188 void test_delete_identifier_beginning() { | 9227 void test_delete_identifier_beginning() { |
| 9228 // "f() => abs + b;" |
| 9229 // "f() => s + b;" |
| 9189 assertParse("f() => ", "ab", "", "s + b;"); | 9230 assertParse("f() => ", "ab", "", "s + b;"); |
| 9190 } | 9231 } |
| 9191 | 9232 |
| 9192 void test_delete_identifier_end() { | 9233 void test_delete_identifier_end() { |
| 9234 // "f() => abs + b;" |
| 9235 // "f() => a + b;" |
| 9193 assertParse("f() => a", "bs", "", " + b;"); | 9236 assertParse("f() => a", "bs", "", " + b;"); |
| 9194 } | 9237 } |
| 9195 | 9238 |
| 9196 void test_delete_identifier_middle() { | 9239 void test_delete_identifier_middle() { |
| 9240 // "f() => abs + b;" |
| 9241 // "f() => as + b;" |
| 9197 assertParse("f() => a", "b", "", "s + b;"); | 9242 assertParse("f() => a", "b", "", "s + b;"); |
| 9198 } | 9243 } |
| 9199 | 9244 |
| 9200 void test_delete_mergeTokens() { | 9245 void test_delete_mergeTokens() { |
| 9246 // "f() => a + b + c;" |
| 9247 // "f() => ac;" |
| 9201 assertParse("f() => a", " + b + ", "", "c;"); | 9248 assertParse("f() => a", " + b + ", "", "c;"); |
| 9202 } | 9249 } |
| 9203 | 9250 |
| 9204 void test_insert_afterIdentifier1() { | 9251 void test_insert_afterIdentifier1() { |
| 9252 // "f() => a + b;" |
| 9253 // "f() => abs + b;" |
| 9205 assertParse("f() => a", "", "bs", " + b;"); | 9254 assertParse("f() => a", "", "bs", " + b;"); |
| 9206 } | 9255 } |
| 9207 | 9256 |
| 9208 void test_insert_afterIdentifier2() { | 9257 void test_insert_afterIdentifier2() { |
| 9258 // "f() => a + b;" |
| 9259 // "f() => a + bar;" |
| 9209 assertParse("f() => a + b", "", "ar", ";"); | 9260 assertParse("f() => a + b", "", "ar", ";"); |
| 9210 } | 9261 } |
| 9211 | 9262 |
| 9212 void test_insert_beforeIdentifier1() { | 9263 void test_insert_beforeIdentifier1() { |
| 9264 // "f() => a + b;" |
| 9265 // "f() => xa + b;" |
| 9213 assertParse("f() => ", "", "x", "a + b;"); | 9266 assertParse("f() => ", "", "x", "a + b;"); |
| 9214 } | 9267 } |
| 9215 | 9268 |
| 9216 void test_insert_beforeIdentifier2() { | 9269 void test_insert_beforeIdentifier2() { |
| 9270 // "f() => a + b;" |
| 9271 // "f() => a + xb;" |
| 9217 assertParse("f() => a + ", "", "x", "b;"); | 9272 assertParse("f() => a + ", "", "x", "b;"); |
| 9218 } | 9273 } |
| 9219 | 9274 |
| 9220 void test_insert_convertOneFunctionToTwo() { | 9275 void test_insert_convertOneFunctionToTwo() { |
| 9276 // "f() {}" |
| 9277 // "f() => 0; g() {}" |
| 9221 assertParse("f()", "", " => 0; g()", " {}"); | 9278 assertParse("f()", "", " => 0; g()", " {}"); |
| 9222 } | 9279 } |
| 9223 | 9280 |
| 9224 void test_insert_end() { | 9281 void test_insert_end() { |
| 9282 // "class A {}" |
| 9283 // "class A {} class B {}" |
| 9225 assertParse("class A {}", "", " class B {}", ""); | 9284 assertParse("class A {}", "", " class B {}", ""); |
| 9226 } | 9285 } |
| 9227 | 9286 |
| 9228 void test_insert_insideIdentifier() { | 9287 void test_insert_insideIdentifier() { |
| 9288 // "f() => cob;" |
| 9289 // "f() => cow.b;" |
| 9229 assertParse("f() => co", "", "w.", "b;"); | 9290 assertParse("f() => co", "", "w.", "b;"); |
| 9230 } | 9291 } |
| 9231 | 9292 |
| 9232 void test_insert_newIdentifier1() { | 9293 void test_insert_newIdentifier1() { |
| 9294 // "f() => a; c;" |
| 9295 // "f() => a; b c;" |
| 9233 assertParse("f() => a;", "", " b", " c;"); | 9296 assertParse("f() => a;", "", " b", " c;"); |
| 9234 } | 9297 } |
| 9235 | 9298 |
| 9236 void test_insert_newIdentifier2() { | 9299 void test_insert_newIdentifier2() { |
| 9300 // "f() => a; c;" |
| 9301 // "f() => a;b c;" |
| 9237 assertParse("f() => a;", "", "b", " c;"); | 9302 assertParse("f() => a;", "", "b", " c;"); |
| 9238 } | 9303 } |
| 9239 | 9304 |
| 9240 void test_insert_newIdentifier3() { | 9305 void test_insert_newIdentifier3() { |
| 9306 // "/** A simple function. */ f() => a; c;" |
| 9307 // "/** A simple function. */ f() => a; b c;" |
| 9241 assertParse("/** A simple function. */ f() => a;", "", " b", " c;"); | 9308 assertParse("/** A simple function. */ f() => a;", "", " b", " c;"); |
| 9242 } | 9309 } |
| 9243 | 9310 |
| 9244 void test_insert_newIdentifier4() { | 9311 void test_insert_newIdentifier4() { |
| 9312 // "/** An [A]. */ class A {} class B { m() { return 1; } }" |
| 9313 // "/** An [A]. */ class A {} class B { m() { return 1 + 2; } }" |
| 9245 assertParse("/** An [A]. */ class A {} class B { m() { return 1", "", " + 2"
, "; } }"); | 9314 assertParse("/** An [A]. */ class A {} class B { m() { return 1", "", " + 2"
, "; } }"); |
| 9246 } | 9315 } |
| 9247 | 9316 |
| 9248 void test_insert_period() { | 9317 void test_insert_period() { |
| 9318 // "f() => a + b;" |
| 9319 // "f() => a + b.;" |
| 9249 assertParse("f() => a + b", "", ".", ";"); | 9320 assertParse("f() => a + b", "", ".", ";"); |
| 9250 } | 9321 } |
| 9251 | 9322 |
| 9252 void test_insert_period_betweenIdentifiers1() { | 9323 void test_insert_period_betweenIdentifiers1() { |
| 9324 // "f() => a b;" |
| 9325 // "f() => a. b;" |
| 9253 assertParse("f() => a", "", ".", " b;"); | 9326 assertParse("f() => a", "", ".", " b;"); |
| 9254 } | 9327 } |
| 9255 | 9328 |
| 9256 void test_insert_period_betweenIdentifiers2() { | 9329 void test_insert_period_betweenIdentifiers2() { |
| 9330 // "f() => a b;" |
| 9331 // "f() => a .b;" |
| 9257 assertParse("f() => a ", "", ".", "b;"); | 9332 assertParse("f() => a ", "", ".", "b;"); |
| 9258 } | 9333 } |
| 9259 | 9334 |
| 9260 void test_insert_period_betweenIdentifiers3() { | 9335 void test_insert_period_betweenIdentifiers3() { |
| 9336 // "f() => a b;" |
| 9337 // "f() => a . b;" |
| 9261 assertParse("f() => a ", "", ".", " b;"); | 9338 assertParse("f() => a ", "", ".", " b;"); |
| 9262 } | 9339 } |
| 9263 | 9340 |
| 9264 void test_insert_period_insideExistingIdentifier() { | 9341 void test_insert_period_insideExistingIdentifier() { |
| 9342 // "f() => ab;" |
| 9343 // "f() => a.b;" |
| 9265 assertParse("f() => a", "", ".", "b;"); | 9344 assertParse("f() => a", "", ".", "b;"); |
| 9266 } | 9345 } |
| 9267 | 9346 |
| 9268 void test_insert_periodAndIdentifier() { | 9347 void test_insert_periodAndIdentifier() { |
| 9348 // "f() => a + b;" |
| 9349 // "f() => a + b.x;" |
| 9269 assertParse("f() => a + b", "", ".x", ";"); | 9350 assertParse("f() => a + b", "", ".x", ";"); |
| 9270 } | 9351 } |
| 9271 | 9352 |
| 9272 void test_insert_simpleToComplexExression() { | 9353 void test_insert_simpleToComplexExression() { |
| 9354 // "/** An [A]. */ class A {} class B { m() => 1; }" |
| 9355 // "/** An [A]. */ class A {} class B { m() => 1 + 2; }" |
| 9273 assertParse("/** An [A]. */ class A {} class B { m() => 1", "", " + 2", "; }
"); | 9356 assertParse("/** An [A]. */ class A {} class B { m() => 1", "", " + 2", "; }
"); |
| 9274 } | 9357 } |
| 9275 | 9358 |
| 9276 void test_insert_whitespace_end() { | 9359 void test_insert_whitespace_end() { |
| 9360 // "f() => a + b;" |
| 9361 // "f() => a + b; " |
| 9277 assertParse("f() => a + b;", "", " ", ""); | 9362 assertParse("f() => a + b;", "", " ", ""); |
| 9278 } | 9363 } |
| 9279 | 9364 |
| 9280 void test_insert_whitespace_end_multiple() { | 9365 void test_insert_whitespace_end_multiple() { |
| 9366 // "f() => a + b;" |
| 9367 // "f() => a + b; " |
| 9281 assertParse("f() => a + b;", "", " ", ""); | 9368 assertParse("f() => a + b;", "", " ", ""); |
| 9282 } | 9369 } |
| 9283 | 9370 |
| 9284 void test_insert_whitespace_middle() { | 9371 void test_insert_whitespace_middle() { |
| 9372 // "f() => a + b;" |
| 9373 // "f() => a + b;" |
| 9285 assertParse("f() => a", "", " ", " + b;"); | 9374 assertParse("f() => a", "", " ", " + b;"); |
| 9286 } | 9375 } |
| 9287 | 9376 |
| 9288 void test_replace_identifier_beginning() { | 9377 void test_replace_identifier_beginning() { |
| 9378 // "f() => bell + b;" |
| 9379 // "f() => fell + b;" |
| 9289 assertParse("f() => ", "b", "f", "ell + b;"); | 9380 assertParse("f() => ", "b", "f", "ell + b;"); |
| 9290 } | 9381 } |
| 9291 | 9382 |
| 9292 void test_replace_identifier_end() { | 9383 void test_replace_identifier_end() { |
| 9384 // "f() => bell + b;" |
| 9385 // "f() => belt + b;" |
| 9293 assertParse("f() => bel", "l", "t", " + b;"); | 9386 assertParse("f() => bel", "l", "t", " + b;"); |
| 9294 } | 9387 } |
| 9295 | 9388 |
| 9296 void test_replace_identifier_middle() { | 9389 void test_replace_identifier_middle() { |
| 9390 // "f() => first + b;" |
| 9391 // "f() => frost + b;" |
| 9297 assertParse("f() => f", "ir", "ro", "st + b;"); | 9392 assertParse("f() => f", "ir", "ro", "st + b;"); |
| 9298 } | 9393 } |
| 9299 | 9394 |
| 9300 void test_replace_multiple_partialFirstAndLast() { | 9395 void test_replace_multiple_partialFirstAndLast() { |
| 9396 // "f() => aa + bb;" |
| 9397 // "f() => ab * ab;" |
| 9301 assertParse("f() => a", "a + b", "b * a", "b;"); | 9398 assertParse("f() => a", "a + b", "b * a", "b;"); |
| 9302 } | 9399 } |
| 9303 | 9400 |
| 9304 void test_replace_operator_oneForMany() { | 9401 void test_replace_operator_oneForMany() { |
| 9402 // "f() => a + b;" |
| 9403 // "f() => a * c - b;" |
| 9305 assertParse("f() => a ", "+", "* c -", " b;"); | 9404 assertParse("f() => a ", "+", "* c -", " b;"); |
| 9306 } | 9405 } |
| 9307 | 9406 |
| 9308 void test_replace_operator_oneForOne() { | 9407 void test_replace_operator_oneForOne() { |
| 9408 // "f() => a + b;" |
| 9409 // "f() => a * b;" |
| 9309 assertParse("f() => a ", "+", "*", " b;"); | 9410 assertParse("f() => a ", "+", "*", " b;"); |
| 9310 } | 9411 } |
| 9311 | 9412 |
| 9312 /** | 9413 /** |
| 9313 * Given a description of the original and modified contents, perform an incre
mental scan of the | 9414 * Given a description of the original and modified contents, perform an incre
mental scan of the |
| 9314 * two pieces of text. | 9415 * two pieces of text. |
| 9315 * | 9416 * |
| 9316 * @param prefix the unchanged text before the edit region | 9417 * @param prefix the unchanged text before the edit region |
| 9317 * @param removed the text that was removed from the original contents | 9418 * @param removed the text that was removed from the original contents |
| 9318 * @param added the text that was added to the modified contents | 9419 * @param added the text that was added to the modified contents |
| 9319 * @param suffix the unchanged text after the edit region | 9420 * @param suffix the unchanged text after the edit region |
| 9320 */ | 9421 */ |
| 9321 void assertParse(String prefix, String removed, String added, String suffix) { | 9422 void assertParse(String prefix, String removed, String added, String suffix) { |
| 9423 // |
| 9424 // Compute the information needed to perform the test. |
| 9425 // |
| 9322 String originalContents = "${prefix}${removed}${suffix}"; | 9426 String originalContents = "${prefix}${removed}${suffix}"; |
| 9323 String modifiedContents = "${prefix}${added}${suffix}"; | 9427 String modifiedContents = "${prefix}${added}${suffix}"; |
| 9324 int replaceStart = prefix.length; | 9428 int replaceStart = prefix.length; |
| 9325 Source source = new TestSource(); | 9429 Source source = new TestSource(); |
| 9430 // |
| 9431 // Parse the original contents. |
| 9432 // |
| 9326 GatheringErrorListener originalListener = new GatheringErrorListener(); | 9433 GatheringErrorListener originalListener = new GatheringErrorListener(); |
| 9327 Scanner originalScanner = new Scanner(source, new CharSequenceReader(new Cha
rSequence(originalContents)), originalListener); | 9434 Scanner originalScanner = new Scanner(source, new CharSequenceReader(new Cha
rSequence(originalContents)), originalListener); |
| 9328 Token originalTokens = originalScanner.tokenize(); | 9435 Token originalTokens = originalScanner.tokenize(); |
| 9329 JUnitTestCase.assertNotNull(originalTokens); | 9436 JUnitTestCase.assertNotNull(originalTokens); |
| 9330 Parser originalParser = new Parser(source, originalListener); | 9437 Parser originalParser = new Parser(source, originalListener); |
| 9331 CompilationUnit originalUnit = originalParser.parseCompilationUnit(originalT
okens); | 9438 CompilationUnit originalUnit = originalParser.parseCompilationUnit(originalT
okens); |
| 9332 JUnitTestCase.assertNotNull(originalUnit); | 9439 JUnitTestCase.assertNotNull(originalUnit); |
| 9440 // |
| 9441 // Parse the modified contents. |
| 9442 // |
| 9333 GatheringErrorListener modifiedListener = new GatheringErrorListener(); | 9443 GatheringErrorListener modifiedListener = new GatheringErrorListener(); |
| 9334 Scanner modifiedScanner = new Scanner(source, new CharSequenceReader(new Cha
rSequence(modifiedContents)), modifiedListener); | 9444 Scanner modifiedScanner = new Scanner(source, new CharSequenceReader(new Cha
rSequence(modifiedContents)), modifiedListener); |
| 9335 Token modifiedTokens = modifiedScanner.tokenize(); | 9445 Token modifiedTokens = modifiedScanner.tokenize(); |
| 9336 JUnitTestCase.assertNotNull(modifiedTokens); | 9446 JUnitTestCase.assertNotNull(modifiedTokens); |
| 9337 Parser modifiedParser = new Parser(source, modifiedListener); | 9447 Parser modifiedParser = new Parser(source, modifiedListener); |
| 9338 CompilationUnit modifiedUnit = modifiedParser.parseCompilationUnit(modifiedT
okens); | 9448 CompilationUnit modifiedUnit = modifiedParser.parseCompilationUnit(modifiedT
okens); |
| 9339 JUnitTestCase.assertNotNull(modifiedUnit); | 9449 JUnitTestCase.assertNotNull(modifiedUnit); |
| 9450 // |
| 9451 // Incrementally parse the modified contents. |
| 9452 // |
| 9340 GatheringErrorListener incrementalListener = new GatheringErrorListener(); | 9453 GatheringErrorListener incrementalListener = new GatheringErrorListener(); |
| 9341 IncrementalScanner incrementalScanner = new IncrementalScanner(source, new C
harSequenceReader(new CharSequence(modifiedContents)), incrementalListener); | 9454 IncrementalScanner incrementalScanner = new IncrementalScanner(source, new C
harSequenceReader(new CharSequence(modifiedContents)), incrementalListener); |
| 9342 Token incrementalTokens = incrementalScanner.rescan(originalTokens, replaceS
tart, removed.length, added.length); | 9455 Token incrementalTokens = incrementalScanner.rescan(originalTokens, replaceS
tart, removed.length, added.length); |
| 9343 JUnitTestCase.assertNotNull(incrementalTokens); | 9456 JUnitTestCase.assertNotNull(incrementalTokens); |
| 9344 IncrementalParser incrementalParser = new IncrementalParser(source, incremen
talScanner.tokenMap, incrementalListener); | 9457 IncrementalParser incrementalParser = new IncrementalParser(source, incremen
talScanner.tokenMap, incrementalListener); |
| 9345 CompilationUnit incrementalUnit = incrementalParser.reparse(originalUnit, in
crementalScanner.leftToken, incrementalScanner.rightToken, replaceStart, prefix.
length + removed.length); | 9458 CompilationUnit incrementalUnit = incrementalParser.reparse(originalUnit, in
crementalScanner.leftToken, incrementalScanner.rightToken, replaceStart, prefix.
length + removed.length); |
| 9346 JUnitTestCase.assertNotNull(incrementalUnit); | 9459 JUnitTestCase.assertNotNull(incrementalUnit); |
| 9460 // |
| 9461 // Validate that the results of the incremental parse are the same as the fu
ll parse of the |
| 9462 // modified source. |
| 9463 // |
| 9347 JUnitTestCase.assertTrue(ASTComparator.equals4(modifiedUnit, incrementalUnit
)); | 9464 JUnitTestCase.assertTrue(ASTComparator.equals4(modifiedUnit, incrementalUnit
)); |
| 9348 } | 9465 } |
| 9349 | 9466 |
| 9350 static dartSuite() { | 9467 static dartSuite() { |
| 9351 _ut.group('IncrementalParserTest', () { | 9468 _ut.group('IncrementalParserTest', () { |
| 9352 _ut.test('test_delete_everything', () { | 9469 _ut.test('test_delete_everything', () { |
| 9353 final __test = new IncrementalParserTest(); | 9470 final __test = new IncrementalParserTest(); |
| 9354 runJUnitTest(__test, __test.test_delete_everything); | 9471 runJUnitTest(__test, __test.test_delete_everything); |
| 9355 }); | 9472 }); |
| 9356 _ut.test('test_delete_identifier_beginning', () { | 9473 _ut.test('test_delete_identifier_beginning', () { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9480 }); | 9597 }); |
| 9481 } | 9598 } |
| 9482 } | 9599 } |
| 9483 | 9600 |
| 9484 /** | 9601 /** |
| 9485 * The class `ErrorParserTest` defines parser tests that test the parsing of cod
e to ensure | 9602 * The class `ErrorParserTest` defines parser tests that test the parsing of cod
e to ensure |
| 9486 * that errors are correctly reported, and in some cases, not reported. | 9603 * that errors are correctly reported, and in some cases, not reported. |
| 9487 */ | 9604 */ |
| 9488 class ErrorParserTest extends ParserTestCase { | 9605 class ErrorParserTest extends ParserTestCase { |
| 9489 void fail_expectedListOrMapLiteral() { | 9606 void fail_expectedListOrMapLiteral() { |
| 9607 // It isn't clear that this test can ever pass. The parser is currently crea
te a synthetic list |
| 9608 // literal in this case, but isSynthetic() isn't overridden for ListLiteral.
The problem is that |
| 9609 // the synthetic list literals that are being created are not always zero le
ngth (because they |
| 9610 // could have type parameters), which violates the contract of isSynthetic()
. |
| 9490 TypedLiteral literal = ParserTestCase.parse4("parseListOrMapLiteral", <Objec
t> [null], "1", [ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL]); | 9611 TypedLiteral literal = ParserTestCase.parse4("parseListOrMapLiteral", <Objec
t> [null], "1", [ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL]); |
| 9491 JUnitTestCase.assertTrue(literal.isSynthetic); | 9612 JUnitTestCase.assertTrue(literal.isSynthetic); |
| 9492 } | 9613 } |
| 9493 | 9614 |
| 9494 void fail_illegalAssignmentToNonAssignable_superAssigned() { | 9615 void fail_illegalAssignmentToNonAssignable_superAssigned() { |
| 9616 // TODO(brianwilkerson) When this test starts to pass, remove the test |
| 9617 // test_illegalAssignmentToNonAssignable_superAssigned. |
| 9495 ParserTestCase.parseExpression("super = x;", [ParserErrorCode.ILLEGAL_ASSIGN
MENT_TO_NON_ASSIGNABLE]); | 9618 ParserTestCase.parseExpression("super = x;", [ParserErrorCode.ILLEGAL_ASSIGN
MENT_TO_NON_ASSIGNABLE]); |
| 9496 } | 9619 } |
| 9497 | 9620 |
| 9498 void fail_invalidCommentReference__new_nonIdentifier() { | 9621 void fail_invalidCommentReference__new_nonIdentifier() { |
| 9622 // This test fails because the method parseCommentReference returns null. |
| 9499 ParserTestCase.parse4("parseCommentReference", <Object> ["new 42", 0], "", [
ParserErrorCode.INVALID_COMMENT_REFERENCE]); | 9623 ParserTestCase.parse4("parseCommentReference", <Object> ["new 42", 0], "", [
ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
| 9500 } | 9624 } |
| 9501 | 9625 |
| 9502 void fail_invalidCommentReference__new_tooMuch() { | 9626 void fail_invalidCommentReference__new_tooMuch() { |
| 9503 ParserTestCase.parse4("parseCommentReference", <Object> ["new a.b.c.d", 0],
"", [ParserErrorCode.INVALID_COMMENT_REFERENCE]); | 9627 ParserTestCase.parse4("parseCommentReference", <Object> ["new a.b.c.d", 0],
"", [ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
| 9504 } | 9628 } |
| 9505 | 9629 |
| 9506 void fail_invalidCommentReference__nonNew_nonIdentifier() { | 9630 void fail_invalidCommentReference__nonNew_nonIdentifier() { |
| 9631 // This test fails because the method parseCommentReference returns null. |
| 9507 ParserTestCase.parse4("parseCommentReference", <Object> ["42", 0], "", [Pars
erErrorCode.INVALID_COMMENT_REFERENCE]); | 9632 ParserTestCase.parse4("parseCommentReference", <Object> ["42", 0], "", [Pars
erErrorCode.INVALID_COMMENT_REFERENCE]); |
| 9508 } | 9633 } |
| 9509 | 9634 |
| 9510 void fail_invalidCommentReference__nonNew_tooMuch() { | 9635 void fail_invalidCommentReference__nonNew_tooMuch() { |
| 9511 ParserTestCase.parse4("parseCommentReference", <Object> ["a.b.c.d", 0], "",
[ParserErrorCode.INVALID_COMMENT_REFERENCE]); | 9636 ParserTestCase.parse4("parseCommentReference", <Object> ["a.b.c.d", 0], "",
[ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
| 9512 } | 9637 } |
| 9513 | 9638 |
| 9514 void fail_missingClosingParenthesis() { | 9639 void fail_missingClosingParenthesis() { |
| 9640 // It is possible that it is not possible to generate this error (that it's
being reported in |
| 9641 // code that cannot actually be reached), but that hasn't been proven yet. |
| 9515 ParserTestCase.parse5("parseFormalParameterList", "(int a, int b ;", [Parser
ErrorCode.MISSING_CLOSING_PARENTHESIS]); | 9642 ParserTestCase.parse5("parseFormalParameterList", "(int a, int b ;", [Parser
ErrorCode.MISSING_CLOSING_PARENTHESIS]); |
| 9516 } | 9643 } |
| 9517 | 9644 |
| 9518 void fail_missingFunctionParameters_local_nonVoid_block() { | 9645 void fail_missingFunctionParameters_local_nonVoid_block() { |
| 9646 // The parser does not recognize this as a function declaration, so it tries
to parse it as an |
| 9647 // expression statement. It isn't clear what the best error message is in th
is case. |
| 9519 ParserTestCase.parseStatement("int f { return x;}", [ParserErrorCode.MISSING
_FUNCTION_PARAMETERS]); | 9648 ParserTestCase.parseStatement("int f { return x;}", [ParserErrorCode.MISSING
_FUNCTION_PARAMETERS]); |
| 9520 } | 9649 } |
| 9521 | 9650 |
| 9522 void fail_missingFunctionParameters_local_nonVoid_expression() { | 9651 void fail_missingFunctionParameters_local_nonVoid_expression() { |
| 9652 // The parser does not recognize this as a function declaration, so it tries
to parse it as an |
| 9653 // expression statement. It isn't clear what the best error message is in th
is case. |
| 9523 ParserTestCase.parseStatement("int f => x;", [ParserErrorCode.MISSING_FUNCTI
ON_PARAMETERS]); | 9654 ParserTestCase.parseStatement("int f => x;", [ParserErrorCode.MISSING_FUNCTI
ON_PARAMETERS]); |
| 9524 } | 9655 } |
| 9525 | 9656 |
| 9526 void fail_namedFunctionExpression() { | 9657 void fail_namedFunctionExpression() { |
| 9527 Expression expression = ParserTestCase.parse5("parsePrimaryExpression", "f()
{}", [ParserErrorCode.NAMED_FUNCTION_EXPRESSION]); | 9658 Expression expression = ParserTestCase.parse5("parsePrimaryExpression", "f()
{}", [ParserErrorCode.NAMED_FUNCTION_EXPRESSION]); |
| 9528 EngineTestCase.assertInstanceOf(FunctionExpression, expression); | 9659 EngineTestCase.assertInstanceOf(FunctionExpression, expression); |
| 9529 } | 9660 } |
| 9530 | 9661 |
| 9531 void fail_unexpectedToken_invalidPostfixExpression() { | 9662 void fail_unexpectedToken_invalidPostfixExpression() { |
| 9663 // Note: this might not be the right error to produce, but some error should
be produced |
| 9532 ParserTestCase.parseExpression("f()++", [ParserErrorCode.UNEXPECTED_TOKEN]); | 9664 ParserTestCase.parseExpression("f()++", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 9533 } | 9665 } |
| 9534 | 9666 |
| 9535 void fail_varAndType_local() { | 9667 void fail_varAndType_local() { |
| 9668 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but t
his would be a |
| 9669 // better error message. |
| 9536 ParserTestCase.parseStatement("var int x;", [ParserErrorCode.VAR_AND_TYPE]); | 9670 ParserTestCase.parseStatement("var int x;", [ParserErrorCode.VAR_AND_TYPE]); |
| 9537 } | 9671 } |
| 9538 | 9672 |
| 9539 void fail_varAndType_parameter() { | 9673 void fail_varAndType_parameter() { |
| 9674 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but t
his would be a |
| 9675 // better error message. |
| 9540 ParserTestCase.parse5("parseFormalParameterList", "(var int x)", [ParserErro
rCode.VAR_AND_TYPE]); | 9676 ParserTestCase.parse5("parseFormalParameterList", "(var int x)", [ParserErro
rCode.VAR_AND_TYPE]); |
| 9541 } | 9677 } |
| 9542 | 9678 |
| 9543 void test_abstractClassMember_constructor() { | 9679 void test_abstractClassMember_constructor() { |
| 9544 ParserTestCase.parse4("parseClassMember", <Object> ["C"], "abstract C.c();",
[ParserErrorCode.ABSTRACT_CLASS_MEMBER]); | 9680 ParserTestCase.parse4("parseClassMember", <Object> ["C"], "abstract C.c();",
[ParserErrorCode.ABSTRACT_CLASS_MEMBER]); |
| 9545 } | 9681 } |
| 9546 | 9682 |
| 9547 void test_abstractClassMember_field() { | 9683 void test_abstractClassMember_field() { |
| 9548 ParserTestCase.parse4("parseClassMember", <Object> ["C"], "abstract C f;", [
ParserErrorCode.ABSTRACT_CLASS_MEMBER]); | 9684 ParserTestCase.parse4("parseClassMember", <Object> ["C"], "abstract C f;", [
ParserErrorCode.ABSTRACT_CLASS_MEMBER]); |
| 9549 } | 9685 } |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9944 | 10080 |
| 9945 void test_getterInFunction_expression() { | 10081 void test_getterInFunction_expression() { |
| 9946 ParserTestCase.parseStatement("get x => _x;", [ParserErrorCode.GETTER_IN_FUN
CTION]); | 10082 ParserTestCase.parseStatement("get x => _x;", [ParserErrorCode.GETTER_IN_FUN
CTION]); |
| 9947 } | 10083 } |
| 9948 | 10084 |
| 9949 void test_getterWithParameters() { | 10085 void test_getterWithParameters() { |
| 9950 ParserTestCase.parse4("parseClassMember", <Object> ["C"], "int get x() {}",
[ParserErrorCode.GETTER_WITH_PARAMETERS]); | 10086 ParserTestCase.parse4("parseClassMember", <Object> ["C"], "int get x() {}",
[ParserErrorCode.GETTER_WITH_PARAMETERS]); |
| 9951 } | 10087 } |
| 9952 | 10088 |
| 9953 void test_illegalAssignmentToNonAssignable_superAssigned() { | 10089 void test_illegalAssignmentToNonAssignable_superAssigned() { |
| 10090 // TODO(brianwilkerson) When the test fail_illegalAssignmentToNonAssignable_
superAssigned starts |
| 10091 // to pass, remove this test (there should only be one error generated, but
we're keeping this |
| 10092 // test until that time so that we can catch other forms of regressions). |
| 9954 ParserTestCase.parseExpression("super = x;", [ | 10093 ParserTestCase.parseExpression("super = x;", [ |
| 9955 ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, | 10094 ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, |
| 9956 ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); | 10095 ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
| 9957 } | 10096 } |
| 9958 | 10097 |
| 9959 void test_implementsBeforeExtends() { | 10098 void test_implementsBeforeExtends() { |
| 9960 ParserTestCase.parseCompilationUnit("class A implements B extends C {}", [Pa
rserErrorCode.IMPLEMENTS_BEFORE_EXTENDS]); | 10099 ParserTestCase.parseCompilationUnit("class A implements B extends C {}", [Pa
rserErrorCode.IMPLEMENTS_BEFORE_EXTENDS]); |
| 9961 } | 10100 } |
| 9962 | 10101 |
| 9963 void test_implementsBeforeWith() { | 10102 void test_implementsBeforeWith() { |
| (...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11670 'validateModifiersForTopLevelFunction_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelFunction(arg0)), | 11809 'validateModifiersForTopLevelFunction_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelFunction(arg0)), |
| 11671 'validateModifiersForTopLevelVariable_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelVariable(arg0)), | 11810 'validateModifiersForTopLevelVariable_1': new MethodTrampoline(1, (Parser targ
et, arg0) => target.validateModifiersForTopLevelVariable(arg0)), |
| 11672 'validateModifiersForTypedef_1': new MethodTrampoline(1, (Parser target, arg0)
=> target.validateModifiersForTypedef(arg0)),}; | 11811 'validateModifiersForTypedef_1': new MethodTrampoline(1, (Parser target, arg0)
=> target.validateModifiersForTypedef(arg0)),}; |
| 11673 | 11812 |
| 11674 | 11813 |
| 11675 Object invokeParserMethodImpl(Parser parser, String methodName, List<Object> obj
ects, Token tokenStream) { | 11814 Object invokeParserMethodImpl(Parser parser, String methodName, List<Object> obj
ects, Token tokenStream) { |
| 11676 parser.currentToken = tokenStream; | 11815 parser.currentToken = tokenStream; |
| 11677 MethodTrampoline method = _methodTable_Parser['${methodName}_${objects.length}
']; | 11816 MethodTrampoline method = _methodTable_Parser['${methodName}_${objects.length}
']; |
| 11678 return method.invoke(parser, objects); | 11817 return method.invoke(parser, objects); |
| 11679 } | 11818 } |
| OLD | NEW |