Chromium Code Reviews| Index: compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java |
| diff --git a/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java b/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java |
| index 3d9c29875980546823eb6a4cb7b266e076b3b8d1..7a5cfd603de2c474327045fb8720b651cf2fdbba 100644 |
| --- a/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java |
| +++ b/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java |
| @@ -458,4 +458,85 @@ public class NegativeParserTest extends CompilerTestCase { |
| ""), |
| errEx(ParserErrorCode.NO_UNARY_PLUS_OPERATOR, 6, 9, 1)); |
| } |
| + |
| + public void test_functionDeclaration_noName() { |
| + parseExpectErrors( |
| + Joiner.on("\n").join( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "foo() {", |
| + " (p){}", // declaration of function as statement, should have name |
| + "}", |
| + ""), |
| + errEx(ParserErrorCode.MISSING_FUNCTION_NAME, 3, 3, 5)); |
|
zundel
2012/01/26 18:26:36
I think this is actaully legal code.
Section 1.8 o
|
| + } |
| + |
| + /** |
| + * Separate test for invocation of function literal which has both return type and name. |
| + */ |
| + public void test_invokeFunctionLiteral_returnType_name() { |
| + DartParserRunner parserRunner = |
| + parseExpectErrors(Joiner.on("\n").join( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "topLevelFunctionWithVeryLongNameToForceLineWrapping() {", |
| + " int f(p){}(0);", // invocation of function literal in statement, has type and name |
| + "}", |
| + "")); |
| + assertEquals( |
| + makeCode( |
| + "// unit " + getName(), |
| + "", |
| + "topLevelFunctionWithVeryLongNameToForceLineWrapping() {", |
| + " int f(p) {", |
| + " }(0);", |
| + "}"), |
| + parserRunner.getDartUnit().toSource()); |
| + } |
| + |
| + /** |
| + * Test with variants of function declarations and function literal invocations. |
| + */ |
| + public void test_functionDeclaration_functionLiteral() { |
| + DartParserRunner parserRunner = |
| + parseExpectErrors(Joiner.on("\n").join( |
| + "// filler filler filler filler filler filler filler filler filler filler", |
| + "foo() {", |
| + " f0(p){}", // declaration of function as statement |
| + " int f1(p){}", // declaration of function as statement, has type |
| + " var res = (p){}(1);", // invocation of function literal in assignment |
| + " (p){}(2);", // invocation of function literal in statement, no name |
| + " f2(p){}(3);", // invocation of function literal in statement, has name |
| + " f3(p) => 4;", // function with => arrow ends with ';' |
| + " (5);", // this is separate statement, not invocation of previous function |
| + " join(promises, (p) => 6);", // function with => arrow as argument |
| + " join(promises, (p) {return 7;});", // function with block as argument |
| + "}", |
| + "")); |
| + assertEquals( |
| + makeCode( |
| + "// unit " + getName(), |
| + "", |
| + "foo() {", |
| + " f0(p) {", |
| + " };", |
| + " int f1(p) {", |
| + " };", |
| + " var res = (p) {", |
| + " }(1);", |
| + " (p) {", |
| + " }(2);", |
| + " f2(p) {", |
| + " }(3);", |
| + " f3(p) {", |
| + " return 4;", |
| + " };", |
| + " (5);", |
| + " join(promises, (p) {", |
| + " return 6;", |
| + " });", |
| + " join(promises, (p) {", |
| + " return 7;", |
| + " });", |
| + "}"), |
| + parserRunner.getDartUnit().toSource()); |
| + } |
| } |