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

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

Issue 8506019: Convert top level factory into method, issue 345 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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
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 b7b0f41a1d5155ca8e38afc2ed341f665ee05a1b..7f9b9ba0cb2dd734c7420f46680301fff11f5520 100644
--- a/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java
+++ b/compiler/javatests/com/google/dart/compiler/parser/NegativeParserTest.java
@@ -5,6 +5,8 @@
package com.google.dart.compiler.parser;
import com.google.dart.compiler.CompilerTestCase;
+import com.google.dart.compiler.ast.DartIdentifier;
+import com.google.dart.compiler.ast.DartMethodDefinition;
import com.google.dart.compiler.ast.DartUnit;
/**
@@ -70,4 +72,42 @@ public class NegativeParserTest extends CompilerTestCase {
""),
unit.toSource());
}
+
+ /**
+ * Language specification requires that factory should be declared in class. However declaring
+ * factory on top level should not cause exceptions in compiler. To ensure this we parse top level
+ * factory into normal {@link DartMethodDefinition}.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=345
+ */
+ public void test_badTopLevelFactory() {
+ DartUnit unit =
+ parseSourceUnitErrors(
+ "factory foo() {}",
+ ParserErrorCode.DISALLOWED_FACTORY_KEYWORD.getMessage(), 1, 1);
+ DartMethodDefinition factory = (DartMethodDefinition) unit.getTopLevelNodes().get(0);
+ assertNotNull(factory);
+ // this factory has name, which is allowed for normal method
+ assertEquals(true, factory.getName() instanceof DartIdentifier);
+ assertEquals("foo", ((DartIdentifier) factory.getName()).getTargetName());
+ }
+
+ /**
+ * Language specification requires that factory should be declared in class. However declaring
+ * factory on top level should not cause exceptions in compiler. To ensure this we parse top level
+ * factory into normal {@link DartMethodDefinition}.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=345
+ */
+ public void test_badTopLevelFactory_withTypeParameters() {
+ DartUnit unit =
+ parseSourceUnitErrors(
+ "factory foo<T>() {}",
+ ParserErrorCode.DISALLOWED_FACTORY_KEYWORD.getMessage(), 1, 1);
+ DartMethodDefinition factory = (DartMethodDefinition) unit.getTopLevelNodes().get(0);
+ assertNotNull(factory);
+ // normal method requires name, so we provide some name
+ assertEquals(true, factory.getName() instanceof DartIdentifier);
+ assertEquals("foo<T>", ((DartIdentifier) factory.getName()).getTargetName());
+ }
}

Powered by Google App Engine
This is Rietveld 408576698