| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 package com.google.dart.compiler.parser; | 5 package com.google.dart.compiler.parser; |
| 6 | 6 |
| 7 import com.google.common.base.Joiner; | 7 import com.google.common.base.Joiner; |
| 8 import com.google.dart.compiler.DartCompilerListener; | 8 import com.google.dart.compiler.DartCompilerListener; |
| 9 import com.google.dart.compiler.DartSourceTest; | 9 import com.google.dart.compiler.DartSourceTest; |
| 10 import com.google.dart.compiler.ast.DartArrayLiteral; | 10 import com.google.dart.compiler.ast.DartArrayLiteral; |
| 11 import com.google.dart.compiler.ast.DartBinaryExpression; | 11 import com.google.dart.compiler.ast.DartBinaryExpression; |
| 12 import com.google.dart.compiler.ast.DartClass; | 12 import com.google.dart.compiler.ast.DartClass; |
| 13 import com.google.dart.compiler.ast.DartExprStmt; | 13 import com.google.dart.compiler.ast.DartExprStmt; |
| 14 import com.google.dart.compiler.ast.DartExpression; | 14 import com.google.dart.compiler.ast.DartExpression; |
| 15 import com.google.dart.compiler.ast.DartField; | 15 import com.google.dart.compiler.ast.DartField; |
| 16 import com.google.dart.compiler.ast.DartFieldDefinition; | 16 import com.google.dart.compiler.ast.DartFieldDefinition; |
| 17 import com.google.dart.compiler.ast.DartIdentifier; | 17 import com.google.dart.compiler.ast.DartIdentifier; |
| 18 import com.google.dart.compiler.ast.DartIntegerLiteral; | 18 import com.google.dart.compiler.ast.DartIntegerLiteral; |
| 19 import com.google.dart.compiler.ast.DartMapLiteral; | 19 import com.google.dart.compiler.ast.DartMapLiteral; |
| 20 import com.google.dart.compiler.ast.DartMethodDefinition; | 20 import com.google.dart.compiler.ast.DartMethodDefinition; |
| 21 import com.google.dart.compiler.ast.DartNode; | 21 import com.google.dart.compiler.ast.DartNode; |
| 22 import com.google.dart.compiler.ast.DartPropertyAccess; | 22 import com.google.dart.compiler.ast.DartPropertyAccess; |
| 23 import com.google.dart.compiler.ast.DartReturnStatement; |
| 23 import com.google.dart.compiler.ast.DartStatement; | 24 import com.google.dart.compiler.ast.DartStatement; |
| 24 import com.google.dart.compiler.ast.DartStringInterpolation; | 25 import com.google.dart.compiler.ast.DartStringInterpolation; |
| 25 import com.google.dart.compiler.ast.DartStringLiteral; | 26 import com.google.dart.compiler.ast.DartStringLiteral; |
| 26 import com.google.dart.compiler.ast.DartTryStatement; | 27 import com.google.dart.compiler.ast.DartTryStatement; |
| 27 import com.google.dart.compiler.ast.DartTypeExpression; | 28 import com.google.dart.compiler.ast.DartTypeExpression; |
| 28 import com.google.dart.compiler.ast.DartTypeNode; | 29 import com.google.dart.compiler.ast.DartTypeNode; |
| 30 import com.google.dart.compiler.ast.DartUnaryExpression; |
| 29 import com.google.dart.compiler.ast.DartUnit; | 31 import com.google.dart.compiler.ast.DartUnit; |
| 30 import com.google.dart.compiler.ast.DartVariableStatement; | 32 import com.google.dart.compiler.ast.DartVariableStatement; |
| 31 | 33 |
| 32 import java.util.List; | 34 import java.util.List; |
| 33 | 35 |
| 34 public class SyntaxTest extends AbstractParserTest { | 36 public class SyntaxTest extends AbstractParserTest { |
| 35 | 37 |
| 36 /** | 38 /** |
| 37 * There was bug when "identA.identB" always considered as constructor declara
tion. But it can be | 39 * There was bug when "identA.identB" always considered as constructor declara
tion. But it can be |
| 38 * constructor only if "identA" is name of enclosing class. | 40 * constructor only if "identA" is name of enclosing class. |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 DartMethodDefinition F_negate = (DartMethodDefinition)F.getMembers().get(0); | 431 DartMethodDefinition F_negate = (DartMethodDefinition)F.getMembers().get(0); |
| 430 assertEquals("negate", ((DartIdentifier)F_negate.getName()).getName()); | 432 assertEquals("negate", ((DartIdentifier)F_negate.getName()).getName()); |
| 431 DartMethodDefinition F_plus = (DartMethodDefinition)F.getMembers().get(1); | 433 DartMethodDefinition F_plus = (DartMethodDefinition)F.getMembers().get(1); |
| 432 assertEquals("+", ((DartIdentifier)F_plus.getName()).getName()); | 434 assertEquals("+", ((DartIdentifier)F_plus.getName()).getName()); |
| 433 DartMethodDefinition F_access = (DartMethodDefinition)F.getMembers().get(2); | 435 DartMethodDefinition F_access = (DartMethodDefinition)F.getMembers().get(2); |
| 434 assertEquals("[]", ((DartIdentifier)F_access.getName()).getName()); | 436 assertEquals("[]", ((DartIdentifier)F_access.getName()).getName()); |
| 435 DartMethodDefinition F_access_assign = (DartMethodDefinition)F.getMembers().
get(3); | 437 DartMethodDefinition F_access_assign = (DartMethodDefinition)F.getMembers().
get(3); |
| 436 assertEquals("[]=", ((DartIdentifier)F_access_assign.getName()).getName()); | 438 assertEquals("[]=", ((DartIdentifier)F_access_assign.getName()).getName()); |
| 437 } | 439 } |
| 438 | 440 |
| 441 public void test_super_operator() { |
| 442 DartUnit unit = parseUnit("phony_super.dart", Joiner.on("\n").join( |
| 443 "class A {", |
| 444 " void m() {", |
| 445 " --super;", |
| 446 " }", |
| 447 "}")); |
| 448 List<DartNode> nodes = unit.getTopLevelNodes(); |
| 449 assertEquals(1, nodes.size()); |
| 450 DartClass A = (DartClass) nodes.get(0); |
| 451 DartMethodDefinition m = (DartMethodDefinition) A.getMembers().get(0); |
| 452 DartExprStmt statement = (DartExprStmt) m.getFunction().getBody().getStateme
nts().get(0); |
| 453 DartUnaryExpression value = (DartUnaryExpression) statement.getExpression(); |
| 454 assertEquals(Token.SUB, value.getOperator()); |
| 455 DartUnaryExpression inner = (DartUnaryExpression) value.getArg(); |
| 456 assertEquals(Token.SUB, inner.getOperator()); |
| 457 } |
| 458 |
| 439 /** | 459 /** |
| 440 * Typedef and interface are top level keywords that are also valid as identif
iers. | 460 * Typedef and interface are top level keywords that are also valid as identif
iers. |
| 441 * | 461 * |
| 442 * This test helps insure that the error recovery logic in the parser that det
ects | 462 * This test helps insure that the error recovery logic in the parser that det
ects |
| 443 * top level keywords out of place doesn't break this functionality. | 463 * top level keywords out of place doesn't break this functionality. |
| 444 */ | 464 */ |
| 445 public void testTopLevelKeywordsAsIdent() { | 465 public void testTopLevelKeywordsAsIdent() { |
| 446 parseUnit("phony_pseudokeyword_methods.dart", | 466 parseUnit("phony_pseudokeyword_methods.dart", |
| 447 Joiner.on("\n").join( | 467 Joiner.on("\n").join( |
| 448 "var interface;", | 468 "var interface;", |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 parseUnit("phony_bogus_escaped_newline.dart", | 586 parseUnit("phony_bogus_escaped_newline.dart", |
| 567 Joiner.on("\n").join( | 587 Joiner.on("\n").join( |
| 568 "class A {", | 588 "class A {", |
| 569 " var foo = \"not really multiline\\\n", | 589 " var foo = \"not really multiline\\\n", |
| 570 "\";", | 590 "\";", |
| 571 "}"), | 591 "}"), |
| 572 ParserErrorCode.UNEXPECTED_TOKEN, 2, 13, | 592 ParserErrorCode.UNEXPECTED_TOKEN, 2, 13, |
| 573 ParserErrorCode.EXPECTED_TOKEN, 4, 1); | 593 ParserErrorCode.EXPECTED_TOKEN, 4, 1); |
| 574 } | 594 } |
| 575 } | 595 } |
| OLD | NEW |