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

Side by Side Diff: tests/language/src/FunctionLiteralsTest.dart

Issue 10248007: test rename overhaul: step 8 - language tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 /**
6 * Test various forms of function literals.
7 */
8 typedef int IntFunc(int);
9
10 class FunctionLiteralsTest {
11 static void checkIntFunction(expected, int f(x), arg) {
12 Expect.equals(expected, f(arg));
13 }
14
15 static void checkIntFuncFunction(expected, IntFunc f(x), arg) {
16 Expect.equals(expected, f(arg)(arg));
17 }
18
19 int func1(int x) => x;
20
21 int func2(x) => x;
22
23 int func3(int x) {
24 return x;
25 }
26
27 int func4(x) {
28 return x;
29 }
30
31 FunctionLiteralsTest() {}
32
33 static void testMain() {
34 var test = new FunctionLiteralsTest();
35 test.testArrow();
36 test.testArrowArrow();
37 test.testArrowBlock();
38 test.testBlock();
39 test.testBlockArrow();
40 test.testBlockBlock();
41 test.testFunctionRef();
42 }
43
44 void testArrow() {
45 checkIntFunction(42, (x) => x, 42);
46 checkIntFunction(42, _(x) => x, 42);
47 checkIntFunction(42, int f(x) => x, 42);
48 checkIntFunction(42, (int x) => x, 42);
49 checkIntFunction(42, _(int x) => x, 42);
50 checkIntFunction(42, int f(int x) => x, 42);
51 }
52
53 void testArrowArrow() {
54 checkIntFuncFunction(84, (x) => (y) => x+y, 42);
55 checkIntFuncFunction(84, _(x) => (y) => x+y, 42);
56 checkIntFuncFunction(84, IntFunc f(x) => (y) => x+y, 42);
57 checkIntFuncFunction(84, (int x) => (y) => x+y, 42);
58 checkIntFuncFunction(84, _(int x) => (y) => x+y, 42);
59 checkIntFuncFunction(84, IntFunc f(int x) => (y) => x+y, 42);
60 checkIntFuncFunction(84, (x) => f(y) => x+y, 42);
61 checkIntFuncFunction(84, _(x) => f(y) => x+y, 42);
62 checkIntFuncFunction(84, IntFunc f(x) => f(y) => x+y, 42);
63 checkIntFuncFunction(84, (int x) => f(y) => x+y, 42);
64 checkIntFuncFunction(84, _(int x) => f(y) => x+y, 42);
65 checkIntFuncFunction(84, IntFunc f(int x) => f(y) => x+y, 42);
66 checkIntFuncFunction(84, (x) => int f(y) => x+y, 42);
67 checkIntFuncFunction(84, _(x) => int f(y) => x+y, 42);
68 checkIntFuncFunction(84, IntFunc f(x) => int f(y) => x+y, 42);
69 checkIntFuncFunction(84, (int x) => int f(y) => x+y, 42);
70 checkIntFuncFunction(84, _(int x) => int f(y) => x+y, 42);
71 checkIntFuncFunction(84, IntFunc f(int x) => int f(y) => x+y, 42);
72 checkIntFuncFunction(84, (int x) => int f(int y) => x+y, 42);
73 checkIntFuncFunction(84, _(int x) => int f(int y) => x+y, 42);
74 checkIntFuncFunction(84, IntFunc f(int x) => int f(int y) => x+y, 42);
75 }
76
77 void testArrowBlock() {
78 checkIntFuncFunction(84, (x) => (y) { return x+y; }, 42);
79 checkIntFuncFunction(84, _(x) => (y) { return x+y; }, 42);
80 checkIntFuncFunction(84, IntFunc f(x) => (y) { return x+y; }, 42);
81 checkIntFuncFunction(84, (int x) => (y) { return x+y; }, 42);
82 checkIntFuncFunction(84, _(int x) => (y) { return x+y; }, 42);
83 checkIntFuncFunction(84, IntFunc f(int x) => (y) { return x+y; }, 42);
84 checkIntFuncFunction(84, (x) => f(y) { return x+y; }, 42);
85 checkIntFuncFunction(84, _(x) => f(y) { return x+y; }, 42);
86 checkIntFuncFunction(84, IntFunc f(x) => f(y) { return x+y; }, 42);
87 checkIntFuncFunction(84, (int x) => f(y) { return x+y; }, 42);
88 checkIntFuncFunction(84, _(int x) => f(y) { return x+y; }, 42);
89 checkIntFuncFunction(84, IntFunc f(int x) => f(y) { return x+y; }, 42);
90 checkIntFuncFunction(84, (x) => int f(y) { return x+y; }, 42);
91 checkIntFuncFunction(84, _(x) => int f(y) { return x+y; }, 42);
92 checkIntFuncFunction(84, IntFunc f(x) => int f(y) { return x+y; }, 42);
93 checkIntFuncFunction(84, (int x) => int f(y) { return x+y; }, 42);
94 checkIntFuncFunction(84, _(int x) => int f(y) { return x+y; }, 42);
95 checkIntFuncFunction(84, IntFunc f(int x) => int f(y) { return x+y; }, 42);
96 }
97
98 void testBlock() {
99 checkIntFunction(42, (x) { return x; }, 42);
100 checkIntFunction(42, _(x) { return x; }, 42);
101 checkIntFunction(42, int f(x) { return x; }, 42);
102 checkIntFunction(42, (int x) { return x; }, 42);
103 checkIntFunction(42, _(int x) { return x; }, 42);
104 checkIntFunction(42, int f(int x) { return x; }, 42);
105 }
106
107 void testBlockArrow() {
108 checkIntFuncFunction(84, (x) { return (y) => x+y; }, 42);
109 checkIntFuncFunction(84, _(x) { return (y) => x+y; }, 42);
110 checkIntFuncFunction(84, IntFunc f(x) { return (y) => x+y; }, 42);
111 checkIntFuncFunction(84, (int x) { return (y) => x+y; }, 42);
112 checkIntFuncFunction(84, _(int x) { return (y) => x+y; }, 42);
113 checkIntFuncFunction(84, IntFunc f(int x) { return (y) => x+y; }, 42);
114 checkIntFuncFunction(84, (x) { return f(y) => x+y; }, 42);
115 checkIntFuncFunction(84, _(x) { return f(y) => x+y; }, 42);
116 checkIntFuncFunction(84, IntFunc f(x) { return f(y) => x+y; }, 42);
117 checkIntFuncFunction(84, (int x) { return f(y) => x+y; }, 42);
118 checkIntFuncFunction(84, _(int x) { return f(y) => x+y; }, 42);
119 checkIntFuncFunction(84, IntFunc f(int x) { return f(y) => x+y; }, 42);
120 checkIntFuncFunction(84, (x) { return int f(y) => x+y; }, 42);
121 checkIntFuncFunction(84, _(x) { return int f(y) => x+y; }, 42);
122 checkIntFuncFunction(84, IntFunc f(x) { return int f(y) => x+y; }, 42);
123 checkIntFuncFunction(84, (int x) { return int f(y) => x+y; }, 42);
124 checkIntFuncFunction(84, _(int x) { return int f(y) => x+y; }, 42);
125 checkIntFuncFunction(84, IntFunc f(int x) { return int f(y) => x+y; }, 42);
126 }
127
128 void testBlockBlock() {
129 checkIntFuncFunction(84, (x) { return (y) { return x+y; }; }, 42);
130 checkIntFuncFunction(84, _(x) { return (y) { return x+y; }; }, 42);
131 checkIntFuncFunction(84, IntFunc f(x) { return (y) { return x+y; }; }, 42);
132 checkIntFuncFunction(84, (int x) { return (y) { return x+y; }; }, 42);
133 checkIntFuncFunction(84, _(int x) { return (y) { return x+y; }; }, 42);
134 checkIntFuncFunction(84, IntFunc f(int x) { return (y) { return x+y; }; }, 4 2);
135 checkIntFuncFunction(84, (x) { return f(y) { return x+y; }; }, 42);
136 checkIntFuncFunction(84, _(x) { return f(y) { return x+y; }; }, 42);
137 checkIntFuncFunction(84, IntFunc f(x) { return f(y) { return x+y; }; }, 42);
138 checkIntFuncFunction(84, (int x) { return f(y) { return x+y; }; }, 42);
139 checkIntFuncFunction(84, _(int x) { return f(y) { return x+y; }; }, 42);
140 checkIntFuncFunction(84, IntFunc f(int x) { return f(y) { return x+y; }; }, 42);
141 checkIntFuncFunction(84, (x) { return int f(y) { return x+y; }; }, 42);
142 checkIntFuncFunction(84, _(x) { return int f(y) { return x+y; }; }, 42);
143 checkIntFuncFunction(84, IntFunc f(x) { return int f(y) { return x+y; }; }, 42);
144 checkIntFuncFunction(84, (int x) { return int f(y) { return x+y; }; }, 42);
145 checkIntFuncFunction(84, _(int x) { return int f(y) { return x+y; }; }, 42);
146 checkIntFuncFunction(84, IntFunc f(int x) { return int f(y) { return x+y; }; }, 42);
147 }
148
149 void testFunctionRef() {
150 checkIntFunction(42, func1, 42);
151 checkIntFunction(42, func2, 42);
152 checkIntFunction(42, func3, 42);
153 checkIntFunction(42, func4, 42);
154 }
155 }
156
157
158 main() {
159 FunctionLiteralsTest.testMain();
160 }
OLDNEW
« no previous file with comments | « tests/language/src/FunctionLiterals2Test.dart ('k') | tests/language/src/FunctionSyntaxTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698