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