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

Side by Side Diff: tests/compiler/dart2js_extra/closure_capture4_test.dart

Issue 437193002: Remove function names on function expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove TODO Created 6 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 | Annotate | Revision Log
OLDNEW
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 closure0() { 7 closure0() {
8 var input = [1, 2, 3]; 8 var input = [1, 2, 3];
9 var fs = []; 9 var fs = [];
10 for (var x in input) { 10 for (var x in input) {
11 fs.add(fun() { return x; }); 11 fs.add(() { return x; });
12 } 12 }
13 Expect.equals(3, fs.length); 13 Expect.equals(3, fs.length);
14 Expect.equals(1, fs[0]()); 14 Expect.equals(1, fs[0]());
15 Expect.equals(2, fs[1]()); 15 Expect.equals(2, fs[1]());
16 Expect.equals(3, fs[2]()); 16 Expect.equals(3, fs[2]());
17 } 17 }
18 18
19 closure1() { 19 closure1() {
20 var input = [1, 2, 3]; 20 var input = [1, 2, 3];
21 var fs = []; 21 var fs = [];
22 for (var x in input) { 22 for (var x in input) {
23 fs.add(fun() { return x; }); 23 fs.add(() { return x; });
24 x++; 24 x++;
25 } 25 }
26 Expect.equals(3, fs.length); 26 Expect.equals(3, fs.length);
27 Expect.equals(2, fs[0]()); 27 Expect.equals(2, fs[0]());
28 Expect.equals(3, fs[1]()); 28 Expect.equals(3, fs[1]());
29 Expect.equals(4, fs[2]()); 29 Expect.equals(4, fs[2]());
30 } 30 }
31 31
32 closure2() { 32 closure2() {
33 var input = [1, 2, 3]; 33 var input = [1, 2, 3];
34 var fs = []; 34 var fs = [];
35 for (var i = 0; i < input.length; i++) { 35 for (var i = 0; i < input.length; i++) {
36 var j = i; 36 var j = i;
37 fs.add(fun() { return input[j]; }); 37 fs.add(() { return input[j]; });
38 } 38 }
39 Expect.equals(3, fs.length); 39 Expect.equals(3, fs.length);
40 Expect.equals(1, fs[0]()); 40 Expect.equals(1, fs[0]());
41 Expect.equals(2, fs[1]()); 41 Expect.equals(2, fs[1]());
42 Expect.equals(3, fs[2]()); 42 Expect.equals(3, fs[2]());
43 } 43 }
44 44
45 closure3() { 45 closure3() {
46 var input = [1, 2, 3]; 46 var input = [1, 2, 3];
47 var fs = []; 47 var fs = [];
48 for (var i = 0; i < input.length; i++) { 48 for (var i = 0; i < input.length; i++) {
49 var x = input[i]; 49 var x = input[i];
50 fs.add(fun() { return x; }); 50 fs.add(() { return x; });
51 x++; 51 x++;
52 } 52 }
53 Expect.equals(3, fs.length); 53 Expect.equals(3, fs.length);
54 Expect.equals(2, fs[0]()); 54 Expect.equals(2, fs[0]());
55 Expect.equals(3, fs[1]()); 55 Expect.equals(3, fs[1]());
56 Expect.equals(4, fs[2]()); 56 Expect.equals(4, fs[2]());
57 } 57 }
58 58
59 closure4() { 59 closure4() {
60 var input = [1, 2, 3]; 60 var input = [1, 2, 3];
61 var fs = []; 61 var fs = [];
62 var x; 62 var x;
63 for (var i = 0; i < input.length; i++) { 63 for (var i = 0; i < input.length; i++) {
64 x = input[i]; 64 x = input[i];
65 fs.add(fun() { return x; }); 65 fs.add(() { return x; });
66 x++; 66 x++;
67 } 67 }
68 Expect.equals(3, fs.length); 68 Expect.equals(3, fs.length);
69 Expect.equals(4, fs[0]()); 69 Expect.equals(4, fs[0]());
70 Expect.equals(4, fs[1]()); 70 Expect.equals(4, fs[1]());
71 Expect.equals(4, fs[2]()); 71 Expect.equals(4, fs[2]());
72 } 72 }
73 73
74 closure5() { 74 closure5() {
75 var input = [1, 2, 3]; 75 var input = [1, 2, 3];
76 var fs = []; 76 var fs = [];
77 var i = 0; 77 var i = 0;
78 do { 78 do {
79 var x = input[i]; 79 var x = input[i];
80 fs.add(fun() { return x; }); 80 fs.add(() { return x; });
81 } while (++i < input.length); 81 } while (++i < input.length);
82 Expect.equals(3, fs.length); 82 Expect.equals(3, fs.length);
83 Expect.equals(1, fs[0]()); 83 Expect.equals(1, fs[0]());
84 Expect.equals(2, fs[1]()); 84 Expect.equals(2, fs[1]());
85 Expect.equals(3, fs[2]()); 85 Expect.equals(3, fs[2]());
86 } 86 }
87 87
88 main() { 88 main() {
89 closure0(); 89 closure0();
90 closure1(); 90 closure1();
91 closure2(); 91 closure2();
92 closure3(); 92 closure3();
93 closure4(); 93 closure4();
94 closure5(); 94 closure5();
95 } 95 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js_extra/closure_capture3_test.dart ('k') | tests/compiler/dart2js_extra/closure_capture5_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698