Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Unified Diff: compiler/javatests/com/google/dart/compiler/parser/ParserRecoveryTest.java

Issue 10019010: Adds more parser recovery to '#' directives (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiler/java/com/google/dart/compiler/parser/ParserErrorCode.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 73fc7771cfe9cf41eb5067a00210c2d3d943d047..d36239a6de9026d8ce07d5fc3ec525eb939108ed 100644
--- a/compiler/javatests/com/google/dart/compiler/parser/ParserRecoveryTest.java
+++ b/compiler/javatests/com/google/dart/compiler/parser/ParserRecoveryTest.java
@@ -13,9 +13,12 @@ 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.DartImportDirective;
+import com.google.dart.compiler.ast.DartLibraryDirective;
import com.google.dart.compiler.ast.DartMapLiteral;
import com.google.dart.compiler.ast.DartMethodDefinition;
import com.google.dart.compiler.ast.DartPropertyAccess;
+import com.google.dart.compiler.ast.DartSourceDirective;
import com.google.dart.compiler.ast.DartUnit;
import com.google.dart.compiler.ast.DartUnqualifiedInvocation;
import com.google.dart.compiler.ast.DartVariable;
@@ -701,4 +704,79 @@ assertEquals("foo", ((DartIdentifier)prop.getQualifier()).getName());
DartFieldDefinition after = (DartFieldDefinition)unit.getTopLevelNodes().get(2);
assertEquals("after", after.getFields().get(0).getName().getName());
}
+
+ public void testRecoveryDirective1() {
+ DartUnit unit = parseUnit("phony_recovery_directive1.dart",
+ Joiner.on("\n").join(
+ "#library('a');",
+ "#library('b');"),
+ ParserErrorCode.DIRECTIVE_OUT_OF_ORDER, 2, 1,
+ ParserErrorCode.ONLY_ONE_LIBRARY_DIRECTIVE, 2, 14);
+ DartLibraryDirective a = (DartLibraryDirective)unit.getDirectives().get(0);
+ assertEquals("a", a.getName().getValue());
+ DartLibraryDirective b = (DartLibraryDirective)unit.getDirectives().get(1);
+ assertEquals("b", b.getName().getValue());
+ }
+
+ public void testRecoveryDirective2() {
+ DartUnit unit = parseUnit("phony_recovery_directive2.dart",
+ Joiner.on("\n").join(
+ "#import('a');",
+ "#library('b');"),
+ ParserErrorCode.DIRECTIVE_OUT_OF_ORDER, 2, 1);
+ DartImportDirective a = (DartImportDirective)unit.getDirectives().get(0);
+ assertEquals("a", a.getLibraryUri().getValue());
+ DartLibraryDirective b = (DartLibraryDirective)unit.getDirectives().get(1);
+ assertEquals("b", b.getName().getValue());
+ }
+
+ public void testRecoveryDirective3() {
+ DartUnit unit = parseUnit("phony_recovery_directive3.dart",
+ Joiner.on("\n").join(
+ "#source('a');",
+ "#import('b');"),
+ ParserErrorCode.DIRECTIVE_OUT_OF_ORDER, 2, 1);
+ DartSourceDirective a = (DartSourceDirective)unit.getDirectives().get(0);
+ assertEquals("a", a.getSourceUri().getValue());
+ DartImportDirective b = (DartImportDirective)unit.getDirectives().get(1);
+ assertEquals("b", b.getLibraryUri().getValue());
+ }
+
+ public void testRecoveryDirective4() {
+ DartUnit unit = parseUnit("phony_recovery_directive4.dart",
+ Joiner.on("\n").join(
+ "#import('a')", // missing semicolon
+ "#import('b');"),
+ ParserErrorCode.EXPECTED_TOKEN, 2, 1);
+ DartImportDirective a = (DartImportDirective)unit.getDirectives().get(0);
+ assertEquals("a", a.getLibraryUri().getValue());
+ DartImportDirective b = (DartImportDirective)unit.getDirectives().get(1);
+ assertEquals("b", b.getLibraryUri().getValue());
+ }
+
+ public void testRecoveryDirective5() {
+ DartUnit unit = parseUnit("phony_recovery_directive5.dart",
+ Joiner.on("\n").join(
+ "#import('a'", // missing paren and semicolon
+ "#import('b');"),
+ ParserErrorCode.EXPECTED_TOKEN, 1, 9,
+ ParserErrorCode.EXPECTED_TOKEN, 2, 1);
+ DartImportDirective a = (DartImportDirective)unit.getDirectives().get(0);
+ assertEquals("a", a.getLibraryUri().getValue());
+ DartImportDirective b = (DartImportDirective)unit.getDirectives().get(1);
+ assertEquals("b", b.getLibraryUri().getValue());
+ }
+
+ public void testRecoveryDirective6() {
+ DartUnit unit = parseUnit("phony_recovery_directive6.dart",
+ Joiner.on("\n").join(
+ "#import('a'", // missing paren and semicolon
+ "class b {}"),
+ ParserErrorCode.EXPECTED_TOKEN, 1, 9,
+ ParserErrorCode.EXPECTED_TOKEN, 2, 1);
+ DartImportDirective a = (DartImportDirective)unit.getDirectives().get(0);
+ assertEquals("a", a.getLibraryUri().getValue());
+ DartClass b = (DartClass)unit.getTopLevelNodes().get(0);
+ assertEquals("b", b.getClassName());
+ }
}
« no previous file with comments | « compiler/java/com/google/dart/compiler/parser/ParserErrorCode.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698