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

Side by Side Diff: tests/language_2/closure7_test.dart

Issue 2997723002: Revert "Migrating a block of dart 2:" (Closed)
Patch Set: Created 3 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 unified diff | Download patch
« no previous file with comments | « tests/language_2/closure6_test.dart ('k') | tests/language_2/closure8_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 import "package:expect/expect.dart";
6
7 // Test that implicitly bound closures work correctly
8
9 class A {
10 foo() => 499;
11 fooo() => 4999; // Implicit closure class can be shared with foo.
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".
14 toto(x, {y: 8, z: 10}) => "3 $x $y $z"; // Could be shared with "bar".
15
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",
18 // because default-val is never used.
19 }
20
21 class B {
22 // All implicit closures of B can be shared with their equivalent functions
23 // of A.
24 foo() => 4990;
25 fooo() => 49990;
26 bar(x, {y: 8, z: 10}) => "1B $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";
29 fisk(x, {y: 8, zz: 10}) => "4B $x $y $zz";
30 titi(x, {y: 8, zz: 77}) => "5B $x $y $zz";
31 }
32
33 tearOffFoo(o) => o.foo;
34 tearOffFooo(o) => o.fooo;
35 tearOffBar(o) => o.bar;
36 tearOffGee(o) => o.gee;
37 tearOffToto(o) => o.toto;
38 tearOffFisk(o) => o.fisk;
39 tearOffTiti(o) => o.titi;
40
41 main() {
42 var a = new A();
43 var b = new B();
44 Expect.equals(499, tearOffFoo(a)());
45 Expect.equals(4990, tearOffFoo(b)());
46 Expect.equals(4999, tearOffFooo(a)());
47 Expect.equals(49990, tearOffFooo(b)());
48
49 var barA = tearOffBar(a);
50 var barB = tearOffBar(b);
51 var geeA = tearOffGee(a);
52 var geeB = tearOffGee(b);
53 var totoA = tearOffToto(a);
54 var totoB = tearOffToto(b);
55 Expect.equals("1 33 8 10", barA(33));
56 Expect.equals("1B 33 8 10", barB(33));
57 Expect.equals("2 33 9 11", geeA(33));
58 Expect.equals("2B 33 9 11", geeB(33));
59 Expect.equals("3 33 8 10", totoA(33));
60 Expect.equals("3B 33 8 10", totoB(33));
61
62 Expect.equals("1 35 8 10", barA(35));
63 Expect.equals("1B 35 8 10", barB(35));
64 Expect.equals("2 35 9 11", geeA(35));
65 Expect.equals("2B 35 9 11", geeB(35));
66 Expect.equals("3 35 8 10", totoA(35));
67 Expect.equals("3B 35 8 10", totoB(35));
68
69 Expect.equals("1 35 8 77", barA(35, z: 77));
70 Expect.equals("1B 35 8 77", barB(35, z: 77));
71 Expect.equals("2 35 9 77", geeA(35, z: 77));
72 Expect.equals("2B 35 9 77", geeB(35, z: 77));
73 Expect.equals("3 35 8 77", totoA(35, z: 77));
74 Expect.equals("3B 35 8 77", totoB(35, z: 77));
75
76 Expect.equals("1 35 8 77", barA(35, z: 77));
77 Expect.equals("1B 35 8 77", barB(35, z: 77));
78 Expect.equals("2 35 9 77", geeA(35, z: 77));
79 Expect.equals("2B 35 9 77", geeB(35, z: 77));
80 Expect.equals("3 35 8 77", totoA(35, z: 77));
81 Expect.equals("3B 35 8 77", totoB(35, z: 77));
82
83 var fiskA = tearOffFisk(a);
84 var fiskB = tearOffFisk(b);
85 var titiA = tearOffTiti(a);
86 var titiB = tearOffTiti(b);
87
88 Expect.equals("4 311 8 987", fiskA(311, zz: 987));
89 Expect.equals("4B 311 8 987", fiskB(311, zz: 987));
90 Expect.equals("5 311 8 987", titiA(311, zz: 987));
91 Expect.equals("5B 311 8 987", titiB(311, zz: 987));
92
93 Expect.equals("4 311 765 987", fiskA(311, y: 765, zz: 987));
94 Expect.equals("4B 311 765 987", fiskB(311, y: 765, zz: 987));
95 Expect.equals("5 311 765 987", titiA(311, y: 765, zz: 987));
96 Expect.equals("5B 311 765 987", titiB(311, y: 765, zz: 987));
97 }
OLDNEW
« no previous file with comments | « tests/language_2/closure6_test.dart ('k') | tests/language_2/closure8_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698