Chromium Code Reviews| Index: compiler/javatests/com/google/dart/compiler/parser/ParserRecoveryTest.java |
| diff --git a/compiler/javatests/com/google/dart/compiler/parser/ParserRecoveryTest.java b/compiler/javatests/com/google/dart/compiler/parser/ParserRecoveryTest.java |
| index f53e5597467a61e0370f554185fbe1ffd1c5332d..f9686910bc4fb0ab3efe8b9a88bfb3dea817edd7 100644 |
| --- a/compiler/javatests/com/google/dart/compiler/parser/ParserRecoveryTest.java |
| +++ b/compiler/javatests/com/google/dart/compiler/parser/ParserRecoveryTest.java |
| @@ -5,11 +5,17 @@ |
| package com.google.dart.compiler.parser; |
| import com.google.common.base.Joiner; |
| +import com.google.dart.compiler.ast.DartBinaryExpression; |
| import com.google.dart.compiler.ast.DartClass; |
| import com.google.dart.compiler.ast.DartFieldDefinition; |
| +import com.google.dart.compiler.ast.DartForStatement; |
| +import com.google.dart.compiler.ast.DartFunctionTypeAlias; |
| import com.google.dart.compiler.ast.DartIdentifier; |
| import com.google.dart.compiler.ast.DartMethodDefinition; |
| +import com.google.dart.compiler.ast.DartPropertyAccess; |
| import com.google.dart.compiler.ast.DartUnit; |
| +import com.google.dart.compiler.ast.DartVariable; |
| +import com.google.dart.compiler.ast.DartVariableStatement; |
| public class ParserRecoveryTest extends AbstractParserTest { |
| @@ -17,7 +23,7 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| public void testStringsErrors() { |
| // Implemented elsewhere |
| } |
| - |
| + |
| public void testVarOnMethodDefinition() { |
| // This syntax is illegal, and should produce errors, but since it is a common error, |
| // we want to make sure it produce a valid AST for editor users |
| @@ -37,9 +43,9 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| assertEquals("f2", ((DartIdentifier)(f2.getName())).getName()); |
| // Make sure that parsing continue |
| DartMethodDefinition f3 = (DartMethodDefinition)(A.getMembers().get(1)); |
| - assertEquals("f3", ((DartIdentifier)(f3.getName())).getName()); |
| + assertEquals("f3", ((DartIdentifier)(f3.getName())).getName()); |
| } |
| - |
| + |
| public void testFinalOnMethodDefinition() { |
| // This syntax is illegal, and should produce errors, but since it is a common error, |
| // we want to make sure it produce a valid AST for editor users |
| @@ -62,9 +68,9 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| DartMethodDefinition f3 = (DartMethodDefinition)(A.getMembers().get(1)); |
| assertEquals("f3", ((DartIdentifier)(f3.getName())).getName()); |
| DartMethodDefinition f4 = (DartMethodDefinition)(A.getMembers().get(2)); |
| - assertEquals("f4", ((DartIdentifier)(f4.getName())).getName()); |
| + assertEquals("f4", ((DartIdentifier)(f4.getName())).getName()); |
| } |
| - |
| + |
| public void testRecoverToTopLevel1() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_recover_to_toplevel1.dart", |
| Joiner.on("\n").join( |
| @@ -104,8 +110,8 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| assertEquals("B", B.getName().getName()); |
| DartFieldDefinition B_b = (DartFieldDefinition)B.getMembers().get(0); |
| assertEquals("b", B_b.getFields().get(0).getName().getName()); |
| - } |
| - |
| + } |
| + |
| public void testRecoverToTopLevel3() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_recover_to_toplevel3.dart", |
| Joiner.on("\n").join( |
| @@ -125,8 +131,8 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| assertEquals("B", B.getName().getName()); |
| DartFieldDefinition B_b = (DartFieldDefinition)B.getMembers().get(0); |
| assertEquals("b", B_b.getFields().get(0).getName().getName()); |
| - } |
| - |
| + } |
| + |
| public void testRecoverToTopLevel4() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_recover_to_toplevel4.dart", |
| Joiner.on("\n").join( |
| @@ -146,8 +152,8 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| assertEquals("B", B.getName().getName()); |
| DartFieldDefinition B_b = (DartFieldDefinition)B.getMembers().get(0); |
| assertEquals("b", B_b.getFields().get(0).getName().getName()); |
| - } |
| - |
| + } |
| + |
| public void testRecoverToTopLevel5() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_recover_to_toplevel5.dart", |
| Joiner.on("\n").join( |
| @@ -167,8 +173,8 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| assertEquals("B", B.getName().getName()); |
| DartFieldDefinition B_b = (DartFieldDefinition)B.getMembers().get(0); |
| assertEquals("b", B_b.getFields().get(0).getName().getName()); |
| - } |
| - |
| + } |
| + |
| public void testRecoverToTopLevel6() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_recover_to_toplevel6.dart", |
| Joiner.on("\n").join( |
| @@ -188,8 +194,8 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| assertEquals("B", B.getName().getName()); |
| DartFieldDefinition B_b = (DartFieldDefinition)B.getMembers().get(0); |
| assertEquals("b", B_b.getFields().get(0).getName().getName()); |
| - } |
| - |
| + } |
| + |
| public void testRecoverToTopLevel7() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_recover_to_toplevel7.dart", |
| Joiner.on("\n").join( |
| @@ -209,8 +215,8 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| assertEquals("B", B.getName().getName()); |
| DartFieldDefinition B_b = (DartFieldDefinition)B.getMembers().get(0); |
| assertEquals("b", B_b.getFields().get(0).getName().getName()); |
| - } |
| - |
| + } |
| + |
| public void testRecoverToTopLevel8() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_recover_to_toplevel8.dart", |
| Joiner.on("\n").join( |
| @@ -232,8 +238,8 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| assertEquals("B", B.getName().getName()); |
| DartFieldDefinition B_b = (DartFieldDefinition)B.getMembers().get(0); |
| assertEquals("b", B_b.getFields().get(0).getName().getName()); |
| - } |
| - |
| + } |
| + |
| public void testReservedWordClass() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_reserved_word_class", |
| Joiner.on("\n").join( |
| @@ -247,21 +253,21 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| assertEquals("foo", foo.getName().getName()); |
| DartMethodDefinition mainMethod = (DartMethodDefinition)unit.getTopLevelNodes().get(1); |
| assertEquals("main", ((DartIdentifier)mainMethod.getName()).getName()); |
| - // The recovery on 'int class' closes the main method, assuming int class = 10 is a |
| + // The recovery on 'int class' closes the main method, assuming int class = 10 is a |
| // new toplevel so 'print' ends up as a bogus top level node. |
| DartClass bar = (DartClass)unit.getTopLevelNodes().get(3); |
| - assertEquals("bar", bar.getName().getName()); |
| + assertEquals("bar", bar.getName().getName()); |
| } |
| - |
| + |
| public void testBadOperatorRecovery() { |
| DartUnit unit = parseUnit("phony_bad_operator_recovery", |
| Joiner.on("\n").join( |
| "class foo {", |
| " operator / (arg) {}", |
| - " operator /= (arg) {}", |
| + " operator /= (arg) {}", |
| " operator ][ (arg) {}", |
| " operator === (arg) {}", |
| - " operator + (arg) {}", |
| + " operator + (arg) {}", |
| "}"), |
| ParserErrorCode.OPERATOR_IS_NOT_USER_DEFINABLE, 3, 12, |
| ParserErrorCode.OPERATOR_IS_NOT_USER_DEFINABLE, 4, 12, |
| @@ -275,11 +281,11 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| DartMethodDefinition opNonsense = (DartMethodDefinition)foo.getMembers().get(2); |
| assertEquals("][", ((DartIdentifier)opNonsense.getName()).getName()); |
| DartMethodDefinition opEquiv = (DartMethodDefinition)foo.getMembers().get(3); |
| - assertEquals("===", ((DartIdentifier)opEquiv.getName()).getName()); |
| + assertEquals("===", ((DartIdentifier)opEquiv.getName()).getName()); |
| DartMethodDefinition opPlus = (DartMethodDefinition)foo.getMembers().get(4); |
| assertEquals("+", ((DartIdentifier)opPlus.getName()).getName()); |
| } |
| - |
| + |
| public void testPropertyAccessInArgumentListRecovery1() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access1.dart", |
| Joiner.on("\n").join( |
| @@ -293,7 +299,7 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2); |
| assertEquals("after", after.getFields().get(0).getName().getName()); |
| } |
| - |
| + |
| public void testPropertyAccessInArgumentListRecovery2() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access2.dart", |
| Joiner.on("\n").join( |
| @@ -307,7 +313,7 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2); |
| assertEquals("after", after.getFields().get(0).getName().getName()); |
| } |
| - |
| + |
| public void testPropertyAccessInArgumentListRecovery3() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access3.dart", |
| Joiner.on("\n").join( |
| @@ -321,7 +327,7 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2); |
| assertEquals("after", after.getFields().get(0).getName().getName()); |
| } |
| - |
| + |
| public void testPropertyAccessInArgumentListRecovery4() { |
| DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access4.dart", |
| Joiner.on("\n").join( |
| @@ -335,4 +341,153 @@ public class ParserRecoveryTest extends AbstractParserTest { |
| DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2); |
| assertEquals("after", after.getFields().get(0).getName().getName()); |
| } |
| + |
| + public void testPropertyAccessInInitializerListRecovery1() { |
|
zundel
2012/04/07 13:28:02
this wan't broken before, I just added a test.
|
| + DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access1.dart", |
| + Joiner.on("\n").join( |
| + "class A {", |
| + " var before;", |
| + " A() : before = foo. ;", |
| + " var after;", |
| + "}")); |
| + DartClass A = (DartClass)unit.getTopLevelNodes().get(0); |
| + DartFieldDefinition before = (DartFieldDefinition)A.getMembers().get(0); |
| + assertEquals("before", before.getFields().get(0).getName().getName()); |
| + DartMethodDefinition bad = (DartMethodDefinition)A.getMembers().get(1); |
| + assertEquals("A", ((DartIdentifier)bad.getName()).getName()); |
| + DartFieldDefinition after = (DartFieldDefinition)A.getMembers().get(2); |
| + assertEquals("after", after.getFields().get(0).getName().getName()); |
| + } |
| + |
| + public void testPropertyAccessInFormalParameterList1() { |
| + DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access_parameter1.dart", |
| + Joiner.on("\n").join( |
| + "var before;", |
| + "typedef void bad(bar.);", |
| + "var after;")); |
| + DartFieldDefinition before = (DartFieldDefinition)unit.getTopLevelNodes().get(0); |
| + assertEquals("before", before.getFields().get(0).getName().getName()); |
| + DartFunctionTypeAlias bad = (DartFunctionTypeAlias)unit.getTopLevelNodes().get(1); |
| + assertEquals("bad", bad.getName().getName()); |
| + DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2); |
| + assertEquals("after", after.getFields().get(0).getName().getName()); |
| + } |
| + |
| + public void testPropertyAccessInFormalParameterList2() { |
| + DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access_parameter2.dart", |
| + Joiner.on("\n").join( |
| + "var before;", |
| + "typedef void bad(bar.,baz);", |
| + "var after;")); |
| + DartFieldDefinition before = (DartFieldDefinition)unit.getTopLevelNodes().get(0); |
| + assertEquals("before", before.getFields().get(0).getName().getName()); |
| + DartFunctionTypeAlias bad = (DartFunctionTypeAlias)unit.getTopLevelNodes().get(1); |
| + assertEquals("bad", bad.getName().getName()); |
| + DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2); |
| + assertEquals("after", after.getFields().get(0).getName().getName()); |
| + } |
| + |
| + public void testPropertyAccessInFormalParameterList3() { |
| + DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access_parameter3.dart", |
| + Joiner.on("\n").join( |
| + "var before;", |
| + "typedef void bad(foo, [bar.]);", // incomplete property access |
| + "var after;")); |
| + DartFieldDefinition before = (DartFieldDefinition)unit.getTopLevelNodes().get(0); |
| + assertEquals("before", before.getFields().get(0).getName().getName()); |
| + DartFunctionTypeAlias bad = (DartFunctionTypeAlias)unit.getTopLevelNodes().get(1); |
| + assertEquals("bad", bad.getName().getName()); |
| + DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2); |
| + assertEquals("after", after.getFields().get(0).getName().getName()); |
| + } |
| + |
| + public void testPropertyAccessInFormalParameterList4() { |
| + DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access_parameter4.dart", |
| + Joiner.on("\n").join( |
| + "var before;", |
| + "typedef void bad(int bar.);", // a property access is not valid here |
| + "var after;")); |
| + DartFieldDefinition before = (DartFieldDefinition)unit.getTopLevelNodes().get(0); |
| + assertEquals("before", before.getFields().get(0).getName().getName()); |
| + DartFunctionTypeAlias bad = (DartFunctionTypeAlias)unit.getTopLevelNodes().get(1); |
| + assertEquals("bad", bad.getName().getName()); |
| + DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2); |
| + assertEquals("after", after.getFields().get(0).getName().getName()); |
| + } |
| + |
| + public void testPropertyAccessInFormalParameterList5() { |
| + DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access_parameter5.dart", |
| + Joiner.on("\n").join( |
| + "var before;", |
| + "var bad = (bar.) {};", // incomplete property access |
| + "var after;")); |
| + DartFieldDefinition before = (DartFieldDefinition)unit.getTopLevelNodes().get(0); |
| + assertEquals("before", before.getFields().get(0).getName().getName()); |
| + DartFieldDefinition bad = (DartFieldDefinition)unit.getTopLevelNodes().get(1); |
| + assertEquals("bad", bad.getFields().get(0).getName().getName()); |
| + DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2); |
| + assertEquals("after", after.getFields().get(0).getName().getName()); |
| + } |
| + |
| + public void testPropertyAccessInFormalParameterList6() { |
| + DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access_parameter6.dart", |
| + Joiner.on("\n").join( |
| + "var before;", |
| + "void bad(foo.);", // incomplete property access |
| + "var after;")); |
| + DartFieldDefinition before = (DartFieldDefinition)unit.getTopLevelNodes().get(0); |
| + assertEquals("before", before.getFields().get(0).getName().getName()); |
| + DartMethodDefinition bad = (DartMethodDefinition)unit.getTopLevelNodes().get(1); |
| + assertEquals("bad", ((DartIdentifier)bad.getName()).getName()); |
| + DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2); |
| + assertEquals("after", after.getFields().get(0).getName().getName()); |
| + } |
| + |
| + public void testPropertyAccessInExpressionList1() { |
|
zundel
2012/04/07 13:28:02
This test was fixed by the @Terminals annotation o
|
| + DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access_expression_list1.dart", |
| + Joiner.on("\n").join( |
| + "method() {", |
| + " var before;", |
| + " for (var i=0;i < 2;before, foo.,after) {}", |
| + " var after;", |
| + "}")); |
| + DartMethodDefinition method = (DartMethodDefinition) unit.getTopLevelNodes().get(0); |
| + DartVariable before = ((DartVariableStatement) method.getFunction().getBody().getStatements() |
| + .get(0)).getVariables().get(0); |
| + assertEquals("before", before.getName().getName()); |
| + DartForStatement forStatement = (DartForStatement) method.getFunction().getBody() |
| + .getStatements().get(1); |
| + DartBinaryExpression increment = (DartBinaryExpression) forStatement.getIncrement(); |
| + DartBinaryExpression i1 = (DartBinaryExpression) increment.getArg1(); |
| + DartIdentifier beforeIdent = (DartIdentifier) i1.getArg1(); |
| + assertEquals("before", beforeIdent.getName()); |
| + DartPropertyAccess foo = (DartPropertyAccess) i1.getArg2(); |
| + assertEquals("foo", ((DartIdentifier) foo.getQualifier()).getName()); |
| + DartIdentifier afterIdent = (DartIdentifier) increment.getArg2(); |
| + assertEquals("after", afterIdent.getName()); |
| + DartVariable after = ((DartVariableStatement) method.getFunction().getBody().getStatements() |
| + .get(2)).getVariables().get(0); |
| + assertEquals("after", after.getName().getName()); |
| + } |
| + |
| + public void testPropertyAccessInExpressionList2() { |
| + DartUnit unit = parseUnitUnspecifiedErrors("phony_property_access_expression_list2.dart", |
| + Joiner.on("\n").join( |
| + "method() {", |
| + " var before;", |
| + " for (var i=0;i < 2; foo.) {}", |
| + " var after;", |
| + "}")); |
| + DartMethodDefinition method = (DartMethodDefinition) unit.getTopLevelNodes().get(0); |
| + DartVariable before = ((DartVariableStatement) method.getFunction().getBody().getStatements() |
| + .get(0)).getVariables().get(0); |
| + assertEquals("before", before.getName().getName()); |
| + DartForStatement forStatement = (DartForStatement) method.getFunction().getBody() |
| + .getStatements().get(1); |
| + DartPropertyAccess foo = (DartPropertyAccess) forStatement.getIncrement(); |
| + assertEquals("foo", ((DartIdentifier) foo.getQualifier()).getName()); |
| + DartVariable after = ((DartVariableStatement) method.getFunction().getBody().getStatements() |
| + .get(2)).getVariables().get(0); |
| + assertEquals("after", after.getName().getName()); |
| + } |
| } |