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

Unified Diff: tests/language/closure7_test.dart

Issue 10448025: Canonicalize bound closures for non-optional-arg methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 7 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 | « lib/compiler/implementation/emitter.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/closure7_test.dart
diff --git a/tests/language/closure7_test.dart b/tests/language/closure7_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b50e40996399bead2e773c726fd79fb6d5668c91
--- /dev/null
+++ b/tests/language/closure7_test.dart
@@ -0,0 +1,96 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test that implicitly bound closures work correctly
+
+class A {
+ foo() => 499;
+ fooo() => 4999; // Implicit closure class can be shared with foo.
+ bar(x, [y = 8, z = 10]) => "1 $x $y $z";
+ gee(x, [y = 9, z = 11]) => "2 $x $y $z"; // Must not be shared with "bar".
+ toto(x, [y = 8, z = 10]) => "3 $x $y $z"; // Could be shared with "bar".
+
+ fisk(x, [y = 8, zz = 10]) => "4 $x $y $zz";
+ titi(x, [y = 8, zz = 77]) => "5 $x $y $zz"; // Could be shared with "fisk",
+ // because default-val is never used.
+}
+
+class B {
+ // All implicit closures of B can be shared with their equivalent functions
+ // of A.
+ foo() => 4990;
+ fooo() => 49990;
+ bar(x, [y = 8, z = 10]) => "1B $x $y $z";
+ gee(x, [y = 9, z = 11]) => "2B $x $y $z";
+ toto(x, [y = 8, z = 10]) => "3B $x $y $z";
+ fisk(x, [y = 8, zz = 10]) => "4B $x $y $zz";
+ titi(x, [y = 8, zz = 77]) => "5B $x $y $zz";
+}
+
+
+tearOffFoo(o) => o.foo;
+tearOffFooo(o) => o.fooo;
+tearOffBar(o) => o.bar;
+tearOffGee(o) => o.gee;
+tearOffToto(o) => o.toto;
+tearOffFisk(o) => o.fisk;
+tearOffTiti(o) => o.titi;
+
+main() {
+ var a = new A();
+ var b = new B();
+ Expect.equals(499, tearOffFoo(a)());
+ Expect.equals(4990, tearOffFoo(b)());
+ Expect.equals(4999, tearOffFooo(a)());
+ Expect.equals(49990, tearOffFooo(b)());
+
+ var barA = tearOffBar(a);
+ var barB = tearOffBar(b);
+ var geeA = tearOffGee(a);
+ var geeB = tearOffGee(b);
+ var totoA = tearOffToto(a);
+ var totoB = tearOffToto(b);
+ Expect.equals("1 33 8 10", barA(33));
+ Expect.equals("1B 33 8 10", barB(33));
+ Expect.equals("2 33 9 11", geeA(33));
+ Expect.equals("2B 33 9 11", geeB(33));
+ Expect.equals("3 33 8 10", totoA(33));
+ Expect.equals("3B 33 8 10", totoB(33));
+
+ Expect.equals("1 35 8 10", barA(35));
+ Expect.equals("1B 35 8 10", barB(35));
+ Expect.equals("2 35 9 11", geeA(35));
+ Expect.equals("2B 35 9 11", geeB(35));
+ Expect.equals("3 35 8 10", totoA(35));
+ Expect.equals("3B 35 8 10", totoB(35));
+
+ Expect.equals("1 35 8 77", barA(35, z: 77));
+ Expect.equals("1B 35 8 77", barB(35, z: 77));
+ Expect.equals("2 35 9 77", geeA(35, z: 77));
+ Expect.equals("2B 35 9 77", geeB(35, z: 77));
+ Expect.equals("3 35 8 77", totoA(35, z: 77));
+ Expect.equals("3B 35 8 77", totoB(35, z: 77));
+
+ Expect.equals("1 35 8 77", barA(35, z: 77));
+ Expect.equals("1B 35 8 77", barB(35, z: 77));
+ Expect.equals("2 35 9 77", geeA(35, z: 77));
+ Expect.equals("2B 35 9 77", geeB(35, z: 77));
+ Expect.equals("3 35 8 77", totoA(35, z: 77));
+ Expect.equals("3B 35 8 77", totoB(35, z: 77));
+
+ var fiskA = tearOffFisk(a);
+ var fiskB = tearOffFisk(b);
+ var titiA = tearOffTiti(a);
+ var titiB = tearOffTiti(b);
+
+ Expect.equals("4 311 8 987", fiskA(311, zz: 987));
+ Expect.equals("4B 311 8 987", fiskB(311, zz: 987));
+ Expect.equals("5 311 8 987", titiA(311, zz: 987));
+ Expect.equals("5B 311 8 987", titiB(311, zz: 987));
+
+ Expect.equals("4 311 765 987", fiskA(311, 765, 987));
+ Expect.equals("4B 311 765 987", fiskB(311, 765, 987));
+ Expect.equals("5 311 765 987", titiA(311, 765, 987));
+ Expect.equals("5B 311 765 987", titiB(311, 765, 987));
+}
« no previous file with comments | « lib/compiler/implementation/emitter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698