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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java

Issue 10828355: Issue 4289. Test that arguments are bound to positional, optional and named parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Prepare for making optional parameter not named Created 8 years, 4 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
Index: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
index 6095fbf5e636233a1c524235490c43a3662962c4..4420195574616e50ee7d84042451dead52b713b8 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -3588,6 +3588,109 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
errEx(TypeErrorCode.USE_ASSIGNMENT_ON_SETTER, 5, 5, 12),
errEx(TypeErrorCode.USE_ASSIGNMENT_ON_SETTER, 10, 5, 12));
}
+
+ private abstract static class ArgumentsBindingTester {
+ static List<DartExpression> arguments;
+ void doTest(DartUnit unit) {
+ unit.accept(new ASTVisitor<Void>() {
+ int invocationIndex = 0;
+ @Override
+ public Void visitUnqualifiedInvocation(DartUnqualifiedInvocation node) {
+ arguments = node.getArguments();
+ checkArgs(invocationIndex++);
+ return super.visitUnqualifiedInvocation(node);
+ }
+ });
+ }
+ abstract void checkArgs(int invocationIndex);
+ void assertId(int index, Object expected) {
+ DartExpression argument = arguments.get(index);
+ assertEquals(expected, argument.getInvocationParameterId());
+ }
+ }
+
+ public void test_formalParameters_positional_optional() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "method(var a, var b, [var c = 3, var d = 4]) {}",
+ "main() {",
+ " method(10, 20);",
+ " method(10, 20, 30);",
+ " method(10, 20, 30, 40);",
+ "}");
+ assertErrors(libraryResult.getErrors());
+ DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName());
+ new ArgumentsBindingTester() {
+ @Override
+ void checkArgs(int invocationIndex) {
+ switch (invocationIndex) {
+ case 0: {
+ assertId(0, Integer.valueOf(0));
+ assertId(1, Integer.valueOf(1));
+ break;
+ }
+ case 1: {
+ assertId(0, Integer.valueOf(0));
+ assertId(1, Integer.valueOf(1));
+ assertId(2, Integer.valueOf(2));
+ break;
+ }
+ case 3: {
+ assertId(0, Integer.valueOf(0));
+ assertId(1, Integer.valueOf(1));
+ assertId(2, Integer.valueOf(2));
+ assertId(3, Integer.valueOf(3));
+ break;
+ }
+ }
+ }
+ }.doTest(unit);
+ }
+
+ public void test_formalParameters_positional_named() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "method(var a, var b, {var c : 3, var d : 4}) {}",
+ "main() {",
+ " method(10, 20);",
+ " method(10, 20, c: 30);",
+ " method(10, 20, d: 40);",
+ " method(10, 20, d: 40, c: 30);",
+ "}");
+ assertErrors(libraryResult.getErrors());
+ DartUnit unit = libraryResult.getLibraryUnitResult().getUnit(getName());
+ new ArgumentsBindingTester() {
+ @Override
+ void checkArgs(int invocationIndex) {
+ switch (invocationIndex) {
+ case 0: {
+ assertId(0, Integer.valueOf(0));
+ assertId(1, Integer.valueOf(1));
+ break;
+ }
+ case 1: {
+ assertId(0, Integer.valueOf(0));
+ assertId(1, Integer.valueOf(1));
+ assertId(2, "c");
+ break;
+ }
+ case 2: {
+ assertId(0, Integer.valueOf(0));
+ assertId(1, Integer.valueOf(1));
+ assertId(2, "d");
+ break;
+ }
+ case 3: {
+ assertId(0, Integer.valueOf(0));
+ assertId(1, Integer.valueOf(1));
+ assertId(2, "d");
+ assertId(3, "c");
+ break;
+ }
+ }
+ }
+ }.doTest(unit);
+ }
private static <T extends DartNode> T findNode(
AnalyzeLibraryResult libraryResult,

Powered by Google App Engine
This is Rietveld 408576698