| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Test that implicitly bound closures work correctly |
| 6 |
| 7 class A { |
| 8 foo() => 499; |
| 9 fooo() => 4999; // Implicit closure class can be shared with foo. |
| 10 bar(x, [y = 8, z = 10]) => "1 $x $y $z"; |
| 11 gee(x, [y = 9, z = 11]) => "2 $x $y $z"; // Must not be shared with "bar". |
| 12 toto(x, [y = 8, z = 10]) => "3 $x $y $z"; // Could be shared with "bar". |
| 13 |
| 14 fisk(x, [y = 8, zz = 10]) => "4 $x $y $zz"; |
| 15 titi(x, [y = 8, zz = 77]) => "5 $x $y $zz"; // Could be shared with "fisk", |
| 16 // because default-val is never used. |
| 17 } |
| 18 |
| 19 class B { |
| 20 // All implicit closures of B can be shared with their equivalent functions |
| 21 // of A. |
| 22 foo() => 4990; |
| 23 fooo() => 49990; |
| 24 bar(x, [y = 8, z = 10]) => "1B $x $y $z"; |
| 25 gee(x, [y = 9, z = 11]) => "2B $x $y $z"; |
| 26 toto(x, [y = 8, z = 10]) => "3B $x $y $z"; |
| 27 fisk(x, [y = 8, zz = 10]) => "4B $x $y $zz"; |
| 28 titi(x, [y = 8, zz = 77]) => "5B $x $y $zz"; |
| 29 } |
| 30 |
| 31 |
| 32 tearOffFoo(o) => o.foo; |
| 33 tearOffFooo(o) => o.fooo; |
| 34 tearOffBar(o) => o.bar; |
| 35 tearOffGee(o) => o.gee; |
| 36 tearOffToto(o) => o.toto; |
| 37 tearOffFisk(o) => o.fisk; |
| 38 tearOffTiti(o) => o.titi; |
| 39 |
| 40 main() { |
| 41 var a = new A(); |
| 42 var b = new B(); |
| 43 Expect.equals(499, tearOffFoo(a)()); |
| 44 Expect.equals(4990, tearOffFoo(b)()); |
| 45 Expect.equals(4999, tearOffFooo(a)()); |
| 46 Expect.equals(49990, tearOffFooo(b)()); |
| 47 |
| 48 var barA = tearOffBar(a); |
| 49 var barB = tearOffBar(b); |
| 50 var geeA = tearOffGee(a); |
| 51 var geeB = tearOffGee(b); |
| 52 var totoA = tearOffToto(a); |
| 53 var totoB = tearOffToto(b); |
| 54 Expect.equals("1 33 8 10", barA(33)); |
| 55 Expect.equals("1B 33 8 10", barB(33)); |
| 56 Expect.equals("2 33 9 11", geeA(33)); |
| 57 Expect.equals("2B 33 9 11", geeB(33)); |
| 58 Expect.equals("3 33 8 10", totoA(33)); |
| 59 Expect.equals("3B 33 8 10", totoB(33)); |
| 60 |
| 61 Expect.equals("1 35 8 10", barA(35)); |
| 62 Expect.equals("1B 35 8 10", barB(35)); |
| 63 Expect.equals("2 35 9 11", geeA(35)); |
| 64 Expect.equals("2B 35 9 11", geeB(35)); |
| 65 Expect.equals("3 35 8 10", totoA(35)); |
| 66 Expect.equals("3B 35 8 10", totoB(35)); |
| 67 |
| 68 Expect.equals("1 35 8 77", barA(35, z: 77)); |
| 69 Expect.equals("1B 35 8 77", barB(35, z: 77)); |
| 70 Expect.equals("2 35 9 77", geeA(35, z: 77)); |
| 71 Expect.equals("2B 35 9 77", geeB(35, z: 77)); |
| 72 Expect.equals("3 35 8 77", totoA(35, z: 77)); |
| 73 Expect.equals("3B 35 8 77", totoB(35, z: 77)); |
| 74 |
| 75 Expect.equals("1 35 8 77", barA(35, z: 77)); |
| 76 Expect.equals("1B 35 8 77", barB(35, z: 77)); |
| 77 Expect.equals("2 35 9 77", geeA(35, z: 77)); |
| 78 Expect.equals("2B 35 9 77", geeB(35, z: 77)); |
| 79 Expect.equals("3 35 8 77", totoA(35, z: 77)); |
| 80 Expect.equals("3B 35 8 77", totoB(35, z: 77)); |
| 81 |
| 82 var fiskA = tearOffFisk(a); |
| 83 var fiskB = tearOffFisk(b); |
| 84 var titiA = tearOffTiti(a); |
| 85 var titiB = tearOffTiti(b); |
| 86 |
| 87 Expect.equals("4 311 8 987", fiskA(311, zz: 987)); |
| 88 Expect.equals("4B 311 8 987", fiskB(311, zz: 987)); |
| 89 Expect.equals("5 311 8 987", titiA(311, zz: 987)); |
| 90 Expect.equals("5B 311 8 987", titiB(311, zz: 987)); |
| 91 |
| 92 Expect.equals("4 311 765 987", fiskA(311, 765, 987)); |
| 93 Expect.equals("4B 311 765 987", fiskB(311, 765, 987)); |
| 94 Expect.equals("5 311 765 987", titiA(311, 765, 987)); |
| 95 Expect.equals("5B 311 765 987", titiB(311, 765, 987)); |
| 96 } |
| OLD | NEW |