OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // This test uses the multi-test "ok" feature to create two positive tests from |
| 6 // one file. One of these tests fail on dart2js, but pass on the VM, or vice |
| 7 // versa. |
| 8 // TODO(ahe): When both implementations agree, remove the multi-test parts. |
| 9 |
5 library test.mixin_test; | 10 library test.mixin_test; |
6 | 11 |
7 import 'dart:mirrors'; | 12 import 'dart:mirrors'; |
8 | 13 |
9 import 'package:expect/expect.dart'; | 14 import 'package:expect/expect.dart'; |
10 | 15 |
11 import 'model.dart'; | 16 import 'model.dart'; |
12 import 'stringify.dart'; | 17 import 'stringify.dart'; |
13 | 18 |
14 class Mixin { | 19 class Mixin { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 Expect.equals(a, b); | 59 Expect.equals(a, b); |
55 expect(stringify(a), b); | 60 expect(stringify(a), b); |
56 expect(stringify(b), a); | 61 expect(stringify(b), a); |
57 } | 62 } |
58 | 63 |
59 testMixin() { | 64 testMixin() { |
60 checkClass(Mixin, [ | 65 checkClass(Mixin, [ |
61 'Class(s(Mixin) in s(test.mixin_test), top-level)', | 66 'Class(s(Mixin) in s(test.mixin_test), top-level)', |
62 'Class(s(Object) in s(dart.core), top-level)', | 67 'Class(s(Object) in s(dart.core), top-level)', |
63 ]); | 68 ]); |
| 69 |
64 expect( | 70 expect( |
65 '{i: Variable(s(i) in s(Mixin)),' | 71 '{i: Variable(s(i) in s(Mixin)),' |
66 ' m: Method(s(m) in s(Mixin))}', | 72 ' m: Method(s(m) in s(Mixin))}', |
67 reflectClass(Mixin).members); | 73 reflectClass(Mixin).members); |
68 expect( | 74 |
69 '{Mixin: Method(s(Mixin) in s(Mixin), constructor)}', | 75 expect('{Mixin: Method(s(Mixin) in s(Mixin), constructor)}', |
70 reflectClass(Mixin).constructors); | 76 reflectClass(Mixin).constructors); |
71 } | 77 } |
72 | 78 |
73 testMixin2() { | 79 testMixin2() { |
74 checkClass(Mixin2, [ | 80 checkClass(Mixin2, [ |
75 'Class(s(Mixin2) in s(test.mixin_test), top-level)', | 81 'Class(s(Mixin2) in s(test.mixin_test), top-level)', |
76 'Class(s(Object) in s(dart.core), top-level)', | 82 'Class(s(Object) in s(dart.core), top-level)', |
77 ]); | 83 ]); |
| 84 |
78 expect( | 85 expect( |
79 '{i2: Variable(s(i2) in s(Mixin2)),' | 86 '{i2: Variable(s(i2) in s(Mixin2)),' |
80 ' m2: Method(s(m2) in s(Mixin2))}', | 87 ' m2: Method(s(m2) in s(Mixin2))}', |
81 reflectClass(Mixin2).members); | 88 reflectClass(Mixin2).members); |
82 expect( | 89 |
83 '{Mixin2: Method(s(Mixin2) in s(Mixin2), constructor)}', | 90 expect('{Mixin2: Method(s(Mixin2) in s(Mixin2), constructor)}', |
84 reflectClass(Mixin2).constructors); | 91 reflectClass(Mixin2).constructors); |
85 } | 92 } |
86 | 93 |
87 testMixinApplication() { | 94 testMixinApplication() { |
88 checkClass(MixinApplication, [ | 95 checkClass(MixinApplication, [ |
89 'Class(s(MixinApplication) in s(test.mixin_test), top-level)', | 96 'Class(s(MixinApplication) in s(test.mixin_test), top-level)', |
90 'Class(s(C) in s(test.model), top-level)', | 97 'Class(s(C) in s(test.model), top-level)', |
91 'Class(s(B) in s(test.model), top-level)', | 98 'Class(s(B) in s(test.model), top-level)', |
92 'Class(s(A) in s(test.model), top-level)', | 99 'Class(s(A) in s(test.model), top-level)', |
93 'Class(s(Object) in s(dart.core), top-level)', | 100 'Class(s(Object) in s(dart.core), top-level)', |
94 ]); | 101 ]); |
95 | 102 |
| 103 String owner = 'Mixin'; |
| 104 owner = 'MixinApplication'; /// 01: ok |
96 expect( | 105 expect( |
97 '{i: Variable(s(i) in s(Mixin)),' | 106 '{i: Variable(s(i) in s($owner)),' |
98 ' m: Method(s(m) in s(Mixin))}', | 107 ' m: Method(s(m) in s($owner))}', |
99 reflectClass(MixinApplication).members); | 108 reflectClass(MixinApplication).members); |
100 expect( | 109 |
101 '{MixinApplication: Method(s(MixinApplication) in s(MixinApplication),' | 110 expect('{MixinApplication: Method(s(MixinApplication) in s(MixinApplication),' |
102 ' constructor)}', | 111 ' constructor)}', |
103 reflectClass(MixinApplication).constructors); | 112 reflectClass(MixinApplication).constructors); |
104 | 113 |
105 expectSame(reflectClass(C), reflectClass(MixinApplication).superclass); | 114 expectSame(reflectClass(C), reflectClass(MixinApplication).superclass); |
106 } | 115 } |
107 | 116 |
108 testMixinApplicationA() { | 117 testMixinApplicationA() { |
| 118 // TODO(ahe): I don't think an anonymous mixin has an owner. |
| 119 String owner = ' in s(test.mixin_test)'; |
| 120 owner = ''; /// 01: ok |
109 checkClass(MixinApplicationA, [ | 121 checkClass(MixinApplicationA, [ |
110 'Class(s(MixinApplicationA) in s(test.mixin_test), top-level)', | 122 'Class(s(MixinApplicationA) in s(test.mixin_test), top-level)', |
111 'Class(s(test.model.C with test.mixin_test.Mixin) in s(test.mixin_test),' | 123 'Class(s(test.model.C with test.mixin_test.Mixin)$owner, top-level)', |
112 ' top-level)', | |
113 'Class(s(C) in s(test.model), top-level)', | 124 'Class(s(C) in s(test.model), top-level)', |
114 'Class(s(B) in s(test.model), top-level)', | 125 'Class(s(B) in s(test.model), top-level)', |
115 'Class(s(A) in s(test.model), top-level)', | 126 'Class(s(A) in s(test.model), top-level)', |
116 'Class(s(Object) in s(dart.core), top-level)', | 127 'Class(s(Object) in s(dart.core), top-level)', |
117 ]); | 128 ]); |
118 | 129 |
| 130 owner = 'Mixin2'; |
| 131 owner = 'MixinApplicationA'; /// 01: ok |
119 expect( | 132 expect( |
120 '{i2: Variable(s(i2) in s(Mixin2)),' | 133 '{i2: Variable(s(i2) in s($owner)),' |
121 ' m2: Method(s(m2) in s(Mixin2))}', | 134 ' m2: Method(s(m2) in s($owner))}', |
122 reflectClass(MixinApplicationA).members); | 135 reflectClass(MixinApplicationA).members); |
| 136 |
123 expect( | 137 expect( |
124 '{MixinApplicationA: Method(s(MixinApplicationA) in s(MixinApplicationA),' | 138 '{MixinApplicationA: Method(s(MixinApplicationA) in s(MixinApplicationA),' |
125 ' constructor)}', | 139 ' constructor)}', |
126 reflectClass(MixinApplicationA).constructors); | 140 reflectClass(MixinApplicationA).constructors); |
127 | 141 |
128 expect( | 142 expect( |
129 '{i: Variable(s(i) in s(Mixin)),' | 143 '{i: Variable(s(i) in s(Mixin)),' |
130 ' m: Method(s(m) in s(Mixin))}', | 144 ' m: Method(s(m) in s(Mixin))}', |
131 reflectClass(MixinApplicationA).superclass.members); | 145 reflectClass(MixinApplicationA).superclass.members); |
| 146 |
| 147 String name = 'test.model.C with test.mixin_test.Mixin'; |
| 148 name = 'Mixin'; /// 01: ok |
132 expect( | 149 expect( |
133 '{test.model.C with test.mixin_test.Mixin:' | 150 '{$name:' |
134 ' Method(s(test.model.C with test.mixin_test.Mixin)' | 151 ' Method(s($name)' |
135 ' in s(test.model.C with test.mixin_test.Mixin), constructor)}', | 152 ' in s($name), constructor)}', |
136 reflectClass(MixinApplicationA).superclass.constructors); | 153 reflectClass(MixinApplicationA).superclass.constructors); |
137 | 154 |
138 expectSame( | 155 expectSame( |
139 reflectClass(C), | 156 reflectClass(C), |
140 reflectClass(MixinApplicationA).superclass.superclass); | 157 reflectClass(MixinApplicationA).superclass.superclass); |
141 } | 158 } |
142 | 159 |
143 testUnusedMixinApplication() { | 160 testUnusedMixinApplication() { |
144 checkClass(UnusedMixinApplication, [ | 161 checkClass(UnusedMixinApplication, [ |
145 'Class(s(UnusedMixinApplication) in s(test.mixin_test), top-level)', | 162 'Class(s(UnusedMixinApplication) in s(test.mixin_test), top-level)', |
146 'Class(s(C) in s(test.model), top-level)', | 163 'Class(s(C) in s(test.model), top-level)', |
147 'Class(s(B) in s(test.model), top-level)', | 164 'Class(s(B) in s(test.model), top-level)', |
148 'Class(s(A) in s(test.model), top-level)', | 165 'Class(s(A) in s(test.model), top-level)', |
149 'Class(s(Object) in s(dart.core), top-level)', | 166 'Class(s(Object) in s(dart.core), top-level)', |
150 ]); | 167 ]); |
151 | 168 |
| 169 String owner = 'Mixin'; |
| 170 owner = 'UnusedMixinApplication'; /// 01: ok |
152 expect( | 171 expect( |
153 '{i: Variable(s(i) in s(Mixin)),' | 172 '{i: Variable(s(i) in s($owner)),' |
154 ' m: Method(s(m) in s(Mixin))}', | 173 ' m: Method(s(m) in s($owner))}', |
155 reflectClass(UnusedMixinApplication).members); | 174 reflectClass(UnusedMixinApplication).members); |
| 175 |
156 expect( | 176 expect( |
157 '{UnusedMixinApplication: Method(s(UnusedMixinApplication)' | 177 '{UnusedMixinApplication: Method(s(UnusedMixinApplication)' |
158 ' in s(UnusedMixinApplication), constructor)}', | 178 ' in s(UnusedMixinApplication), constructor)}', |
159 reflectClass(UnusedMixinApplication).constructors); | 179 reflectClass(UnusedMixinApplication).constructors); |
160 | 180 |
161 expectSame(reflectClass(C), reflectClass(UnusedMixinApplication).superclass); | 181 expectSame(reflectClass(C), reflectClass(UnusedMixinApplication).superclass); |
162 } | 182 } |
163 | 183 |
164 testSubclass() { | 184 testSubclass() { |
| 185 String owner = ' in s(test.mixin_test)'; |
| 186 owner = ''; /// 01: ok |
165 checkClass(Subclass, [ | 187 checkClass(Subclass, [ |
166 'Class(s(Subclass) in s(test.mixin_test), top-level)', | 188 'Class(s(Subclass) in s(test.mixin_test), top-level)', |
167 'Class(s(test.model.C with test.mixin_test.Mixin) in s(test.mixin_test),' | 189 'Class(s(test.model.C with test.mixin_test.Mixin)$owner, top-level)', |
168 ' top-level)', | |
169 'Class(s(C) in s(test.model), top-level)', | 190 'Class(s(C) in s(test.model), top-level)', |
170 'Class(s(B) in s(test.model), top-level)', | 191 'Class(s(B) in s(test.model), top-level)', |
171 'Class(s(A) in s(test.model), top-level)', | 192 'Class(s(A) in s(test.model), top-level)', |
172 'Class(s(Object) in s(dart.core), top-level)', | 193 'Class(s(Object) in s(dart.core), top-level)', |
173 ]); | 194 ]); |
174 | 195 |
175 expect( | 196 expect( |
176 '{f: Method(s(f) in s(Subclass))}', | 197 '{f: Method(s(f) in s(Subclass))}', |
177 reflectClass(Subclass).members); | 198 reflectClass(Subclass).members); |
| 199 |
178 expect( | 200 expect( |
179 '{Subclass: Method(s(Subclass) in s(Subclass), constructor)}', | 201 '{Subclass: Method(s(Subclass) in s(Subclass), constructor)}', |
180 reflectClass(Subclass).constructors); | 202 reflectClass(Subclass).constructors); |
181 | 203 |
182 expect( | 204 expect( |
183 '{i: Variable(s(i) in s(Mixin)),' | 205 '{i: Variable(s(i) in s(Mixin)),' |
184 ' m: Method(s(m) in s(Mixin))}', | 206 ' m: Method(s(m) in s(Mixin))}', |
185 reflectClass(Subclass).superclass.members); | 207 reflectClass(Subclass).superclass.members); |
| 208 |
| 209 String name = 'test.model.C with test.mixin_test.Mixin'; |
| 210 name = 'Mixin'; /// 01: ok |
186 expect( | 211 expect( |
187 '{test.model.C with test.mixin_test.Mixin:' | 212 '{$name:' |
188 ' Method(s(test.model.C with test.mixin_test.Mixin)' | 213 ' Method(s($name)' |
189 ' in s(test.model.C with test.mixin_test.Mixin), constructor)}', | 214 ' in s($name), constructor)}', |
190 reflectClass(Subclass).superclass.constructors); | 215 reflectClass(Subclass).superclass.constructors); |
191 | 216 |
192 expectSame( | 217 expectSame( |
193 reflectClass(C), | 218 reflectClass(C), |
194 reflectClass(Subclass).superclass.superclass); | 219 reflectClass(Subclass).superclass.superclass); |
195 } | 220 } |
196 | 221 |
197 testSubclass2() { | 222 testSubclass2() { |
198 checkClass(Subclass2, [ | 223 checkClass(Subclass2, [ |
199 'Class(s(Subclass2) in s(test.mixin_test), top-level)', | 224 'Class(s(Subclass2) in s(test.mixin_test), top-level)', |
200 'Class(s(MixinApplication) in s(test.mixin_test), top-level)', | 225 'Class(s(MixinApplication) in s(test.mixin_test), top-level)', |
201 'Class(s(C) in s(test.model), top-level)', | 226 'Class(s(C) in s(test.model), top-level)', |
202 'Class(s(B) in s(test.model), top-level)', | 227 'Class(s(B) in s(test.model), top-level)', |
203 'Class(s(A) in s(test.model), top-level)', | 228 'Class(s(A) in s(test.model), top-level)', |
204 'Class(s(Object) in s(dart.core), top-level)', | 229 'Class(s(Object) in s(dart.core), top-level)', |
205 ]); | 230 ]); |
206 | 231 |
207 expect( | 232 expect( |
208 '{g: Method(s(g) in s(Subclass2))}', | 233 '{g: Method(s(g) in s(Subclass2))}', |
209 reflectClass(Subclass2).members); | 234 reflectClass(Subclass2).members); |
| 235 |
210 expect( | 236 expect( |
211 '{Subclass2: Method(s(Subclass2) in s(Subclass2), constructor)}', | 237 '{Subclass2: Method(s(Subclass2) in s(Subclass2), constructor)}', |
212 reflectClass(Subclass2).constructors); | 238 reflectClass(Subclass2).constructors); |
213 | 239 |
214 expectSame( | 240 expectSame( |
215 reflectClass(MixinApplication), | 241 reflectClass(MixinApplication), |
216 reflectClass(Subclass2).superclass); | 242 reflectClass(Subclass2).superclass); |
217 } | 243 } |
218 | 244 |
219 testSubclassA() { | 245 testSubclassA() { |
| 246 // TODO(ahe): I don't think an anonymous mixin has an owner. |
| 247 String owner = ' in s(test.mixin_test)'; |
| 248 owner = ''; /// 01: ok |
220 checkClass(SubclassA, [ | 249 checkClass(SubclassA, [ |
221 'Class(s(SubclassA) in s(test.mixin_test), top-level)', | 250 'Class(s(SubclassA) in s(test.mixin_test), top-level)', |
222 'Class(s(test.model.C with test.mixin_test.Mixin, test.mixin_test.Mixin2)' | 251 'Class(s(test.model.C with test.mixin_test.Mixin, test.mixin_test.Mixin2)' |
223 ' in s(test.mixin_test), top-level)', | 252 '$owner, top-level)', |
224 'Class(s(test.model.C with test.mixin_test.Mixin) in s(test.mixin_test),' | 253 'Class(s(test.model.C with test.mixin_test.Mixin)$owner, top-level)', |
225 ' top-level)', | |
226 'Class(s(C) in s(test.model), top-level)', | 254 'Class(s(C) in s(test.model), top-level)', |
227 'Class(s(B) in s(test.model), top-level)', | 255 'Class(s(B) in s(test.model), top-level)', |
228 'Class(s(A) in s(test.model), top-level)', | 256 'Class(s(A) in s(test.model), top-level)', |
229 'Class(s(Object) in s(dart.core), top-level)', | 257 'Class(s(Object) in s(dart.core), top-level)', |
230 ]); | 258 ]); |
231 | 259 |
232 expect( | 260 expect( |
233 '{fa: Method(s(fa) in s(SubclassA))}', | 261 '{fa: Method(s(fa) in s(SubclassA))}', |
234 reflectClass(SubclassA).members); | 262 reflectClass(SubclassA).members); |
| 263 |
235 expect( | 264 expect( |
236 '{SubclassA: Method(s(SubclassA) in s(SubclassA), constructor)}', | 265 '{SubclassA: Method(s(SubclassA) in s(SubclassA), constructor)}', |
237 reflectClass(SubclassA).constructors); | 266 reflectClass(SubclassA).constructors); |
238 | 267 |
239 expect( | 268 expect( |
240 '{i2: Variable(s(i2) in s(Mixin2)),' | 269 '{i2: Variable(s(i2) in s(Mixin2)),' |
241 ' m2: Method(s(m2) in s(Mixin2))}', | 270 ' m2: Method(s(m2) in s(Mixin2))}', |
242 reflectClass(SubclassA).superclass.members); | 271 reflectClass(SubclassA).superclass.members); |
| 272 |
| 273 String name = |
| 274 'test.model.C with test.mixin_test.Mixin, test.mixin_test.Mixin2'; |
| 275 name = 'Mixin2'; /// 01: ok |
243 expect( | 276 expect( |
244 '{test.model.C with test.mixin_test.Mixin, test.mixin_test.Mixin2:' | 277 '{$name: Method(s($name) in s($name), constructor)}', |
245 ' Method(s(test.model.C with test.mixin_test.Mixin,' | |
246 ' test.mixin_test.Mixin2) in s(test.model.C with test.mixin_test.Mixin,' | |
247 ' test.mixin_test.Mixin2), constructor)}', | |
248 reflectClass(SubclassA).superclass.constructors); | 278 reflectClass(SubclassA).superclass.constructors); |
249 | 279 |
250 expect( | 280 expect( |
251 '{i: Variable(s(i) in s(Mixin)),' | 281 '{i: Variable(s(i) in s(Mixin)),' |
252 ' m: Method(s(m) in s(Mixin))}', | 282 ' m: Method(s(m) in s(Mixin))}', |
253 reflectClass(SubclassA).superclass.superclass.members); | 283 reflectClass(SubclassA).superclass.superclass.members); |
| 284 |
| 285 name = 'test.model.C with test.mixin_test.Mixin'; |
| 286 name = 'Mixin'; /// 01: ok |
254 expect( | 287 expect( |
255 '{test.model.C with test.mixin_test.Mixin:' | 288 '{$name:' |
256 ' Method(s(test.model.C with test.mixin_test.Mixin)' | 289 ' Method(s($name)' |
257 ' in s(test.model.C with test.mixin_test.Mixin), constructor)}', | 290 ' in s($name), constructor)}', |
258 reflectClass(SubclassA).superclass.superclass.constructors); | 291 reflectClass(SubclassA).superclass.superclass.constructors); |
259 | 292 |
260 expectSame( | 293 expectSame( |
261 reflectClass(C), | 294 reflectClass(C), |
262 reflectClass(SubclassA).superclass.superclass.superclass); | 295 reflectClass(SubclassA).superclass.superclass.superclass); |
263 } | 296 } |
264 | 297 |
265 testSubclass2A() { | 298 testSubclass2A() { |
| 299 // TODO(ahe): I don't think an anonymous mixin has an owner. |
| 300 String owner = ' in s(test.mixin_test)'; |
| 301 owner = ''; /// 01: ok |
266 checkClass(Subclass2A, [ | 302 checkClass(Subclass2A, [ |
267 'Class(s(Subclass2A) in s(test.mixin_test), top-level)', | 303 'Class(s(Subclass2A) in s(test.mixin_test), top-level)', |
268 'Class(s(MixinApplicationA) in s(test.mixin_test), top-level)', | 304 'Class(s(MixinApplicationA) in s(test.mixin_test), top-level)', |
269 'Class(s(test.model.C with test.mixin_test.Mixin) in s(test.mixin_test),' | 305 'Class(s(test.model.C with test.mixin_test.Mixin)$owner,' |
270 ' top-level)', | 306 ' top-level)', |
271 'Class(s(C) in s(test.model), top-level)', | 307 'Class(s(C) in s(test.model), top-level)', |
272 'Class(s(B) in s(test.model), top-level)', | 308 'Class(s(B) in s(test.model), top-level)', |
273 'Class(s(A) in s(test.model), top-level)', | 309 'Class(s(A) in s(test.model), top-level)', |
274 'Class(s(Object) in s(dart.core), top-level)', | 310 'Class(s(Object) in s(dart.core), top-level)', |
275 ]); | 311 ]); |
276 | 312 |
277 expect( | 313 expect( |
278 '{ga: Method(s(ga) in s(Subclass2A))}', | 314 '{ga: Method(s(ga) in s(Subclass2A))}', |
279 reflectClass(Subclass2A).members); | 315 reflectClass(Subclass2A).members); |
| 316 |
280 expect( | 317 expect( |
281 '{Subclass2A: Method(s(Subclass2A) in s(Subclass2A), constructor)}', | 318 '{Subclass2A: Method(s(Subclass2A) in s(Subclass2A), constructor)}', |
282 reflectClass(Subclass2A).constructors); | 319 reflectClass(Subclass2A).constructors); |
283 | 320 |
284 expectSame(reflectClass(MixinApplicationA), | 321 expectSame(reflectClass(MixinApplicationA), |
285 reflectClass(Subclass2A).superclass); | 322 reflectClass(Subclass2A).superclass); |
286 } | 323 } |
287 | 324 |
288 main() { | 325 main() { |
289 testMixin(); | 326 testMixin(); |
290 testMixin2(); | 327 testMixin2(); |
291 testMixinApplication(); | 328 testMixinApplication(); |
292 testMixinApplicationA(); | 329 testMixinApplicationA(); |
293 testUnusedMixinApplication(); | 330 testUnusedMixinApplication(); |
294 testSubclass(); | 331 testSubclass(); |
295 testSubclass2(); | 332 testSubclass2(); |
296 testSubclassA(); | 333 testSubclassA(); |
297 testSubclass2A(); | 334 testSubclass2A(); |
298 } | 335 } |
OLD | NEW |