OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library world_test; | 5 library world_test; |
6 | 6 |
7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
9 import 'type_test_helper.dart'; | 9 import 'type_test_helper.dart'; |
10 import 'package:compiler/src/common/names.dart'; | 10 import 'package:compiler/src/common/names.dart'; |
11 import 'package:compiler/src/elements/elements.dart' | 11 import 'package:compiler/src/elements/elements.dart' |
12 show ClassElement, LibraryElement; | 12 show ClassElement, LibraryElement; |
13 import 'package:compiler/src/elements/entities.dart'; | 13 import 'package:compiler/src/elements/entities.dart'; |
14 import 'package:compiler/src/universe/class_set.dart'; | 14 import 'package:compiler/src/universe/class_set.dart'; |
15 import 'package:compiler/src/world.dart' show ClassQuery, ClosedWorld; | 15 import 'package:compiler/src/world.dart' show ClassQuery, ClosedWorld; |
16 | 16 |
17 void main() { | 17 void main() { |
18 asyncTest(() async { | 18 asyncTest(() async { |
19 await testClassSets(); | 19 await testClassSets(); |
20 await testProperties(); | 20 await testProperties(); |
21 await testNativeClasses(); | 21 await testNativeClasses(); |
22 await testCommonSubclasses(); | 22 await testCommonSubclasses(); |
23 }); | 23 }); |
24 } | 24 } |
25 | 25 |
26 testClassSets() async { | 26 testClassSets() async { |
27 var env = await TypeEnvironment.create( | 27 var env = await TypeEnvironment.create(r""" |
28 r""" | |
29 class A implements X {} | 28 class A implements X {} |
30 class B {} | 29 class B {} |
31 class C_Super extends A {} | 30 class C_Super extends A {} |
32 class C extends C_Super {} | 31 class C extends C_Super {} |
33 class D implements A {} | 32 class D implements A {} |
34 class E extends B implements A {} | 33 class E extends B implements A {} |
35 class F extends Object with A implements B {} | 34 class F extends Object with A implements B {} |
36 class G extends Object with A, B {} | 35 class G extends Object with A, B {} |
37 class X {} | 36 class X {} |
38 """, | 37 """, mainSource: r""" |
39 mainSource: r""" | |
40 import 'dart:html' as html; | 38 import 'dart:html' as html; |
41 main() { | 39 main() { |
42 new A(); | 40 new A(); |
43 new B(); | 41 new B(); |
44 new C(); | 42 new C(); |
45 new D(); | 43 new D(); |
46 new E(); | 44 new E(); |
47 new F(); | 45 new F(); |
48 new G(); | 46 new G(); |
49 html.window; | 47 html.window; |
50 new html.Worker(''); | 48 new html.Worker(''); |
51 } | 49 } |
52 """, | 50 """, useMockCompiler: false); |
53 useMockCompiler: false); | |
54 ClosedWorld closedWorld = env.closedWorld; | 51 ClosedWorld closedWorld = env.closedWorld; |
55 | 52 |
56 ClassElement Object_ = env.getElement("Object"); | 53 ClassElement Object_ = env.getElement("Object"); |
57 ClassElement A = env.getElement("A"); | 54 ClassElement A = env.getElement("A"); |
58 ClassElement B = env.getElement("B"); | 55 ClassElement B = env.getElement("B"); |
59 ClassElement C = env.getElement("C"); | 56 ClassElement C = env.getElement("C"); |
60 ClassElement D = env.getElement("D"); | 57 ClassElement D = env.getElement("D"); |
61 ClassElement E = env.getElement("E"); | 58 ClassElement E = env.getElement("E"); |
62 ClassElement F = env.getElement("F"); | 59 ClassElement F = env.getElement("F"); |
63 ClassElement G = env.getElement("G"); | 60 ClassElement G = env.getElement("G"); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 testMixinUses(B, [G.superclass]); | 172 testMixinUses(B, [G.superclass]); |
176 testMixinUses(C, []); | 173 testMixinUses(C, []); |
177 testMixinUses(D, []); | 174 testMixinUses(D, []); |
178 testMixinUses(E, []); | 175 testMixinUses(E, []); |
179 testMixinUses(F, []); | 176 testMixinUses(F, []); |
180 testMixinUses(G, []); | 177 testMixinUses(G, []); |
181 testMixinUses(X, []); | 178 testMixinUses(X, []); |
182 } | 179 } |
183 | 180 |
184 testProperties() async { | 181 testProperties() async { |
185 var env = await TypeEnvironment.create( | 182 var env = await TypeEnvironment.create(r""" |
186 r""" | |
187 class A {} | 183 class A {} |
188 class A1 extends A {} | 184 class A1 extends A {} |
189 class A2 implements A {} | 185 class A2 implements A {} |
190 class A3 extends Object with A {} | 186 class A3 extends Object with A {} |
191 | 187 |
192 class B {} | 188 class B {} |
193 class B1 extends B {} | 189 class B1 extends B {} |
194 class B2 implements B {} | 190 class B2 implements B {} |
195 class B3 extends Object with B {} | 191 class B3 extends Object with B {} |
196 | 192 |
(...skipping 21 matching lines...) Expand all Loading... |
218 class G1 extends G {} | 214 class G1 extends G {} |
219 class G2 extends G1 {} | 215 class G2 extends G1 {} |
220 class G3 extends G2 implements G {} | 216 class G3 extends G2 implements G {} |
221 class G4 extends G2 with G {} | 217 class G4 extends G2 with G {} |
222 | 218 |
223 class H {} | 219 class H {} |
224 class H1 extends H {} | 220 class H1 extends H {} |
225 class H2 extends H1 {} | 221 class H2 extends H1 {} |
226 class H3 extends H2 implements H {} | 222 class H3 extends H2 implements H {} |
227 class H4 extends H2 with H {} | 223 class H4 extends H2 with H {} |
228 """, | 224 """, mainSource: r""" |
229 mainSource: r""" | |
230 main() { | 225 main() { |
231 new B(); | 226 new B(); |
232 new C1(); | 227 new C1(); |
233 new D2(); | 228 new D2(); |
234 new E3(); | 229 new E3(); |
235 new F1(); | 230 new F1(); |
236 new F2(); | 231 new F2(); |
237 new G2(); | 232 new G2(); |
238 new G3(); | 233 new G3(); |
239 new H4(); | 234 new H4(); |
240 } | 235 } |
241 """, | 236 """, useMockCompiler: false); |
242 useMockCompiler: false); | |
243 ClosedWorld closedWorld = env.closedWorld; | 237 ClosedWorld closedWorld = env.closedWorld; |
244 | 238 |
245 check(String name, {bool hasStrictSubtype, bool hasOnlySubclasses}) { | 239 check(String name, {bool hasStrictSubtype, bool hasOnlySubclasses}) { |
246 ClassElement cls = env.getElement(name); | 240 ClassElement cls = env.getElement(name); |
247 Expect.equals(hasStrictSubtype, closedWorld.hasAnyStrictSubtype(cls), | 241 Expect.equals(hasStrictSubtype, closedWorld.hasAnyStrictSubtype(cls), |
248 "Unexpected hasAnyStrictSubtype property on $cls."); | 242 "Unexpected hasAnyStrictSubtype property on $cls."); |
249 Expect.equals(hasOnlySubclasses, closedWorld.hasOnlySubclasses(cls), | 243 Expect.equals(hasOnlySubclasses, closedWorld.hasOnlySubclasses(cls), |
250 "Unexpected hasOnlySubclasses property on $cls."); | 244 "Unexpected hasOnlySubclasses property on $cls."); |
251 } | 245 } |
252 | 246 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 check(B, ClassQuery.EXACT, C, ClassQuery.EXACT, []); | 593 check(B, ClassQuery.EXACT, C, ClassQuery.EXACT, []); |
600 check(B, ClassQuery.EXACT, C, ClassQuery.SUBCLASS, []); | 594 check(B, ClassQuery.EXACT, C, ClassQuery.SUBCLASS, []); |
601 check(B, ClassQuery.SUBCLASS, C, ClassQuery.EXACT, []); | 595 check(B, ClassQuery.SUBCLASS, C, ClassQuery.EXACT, []); |
602 check(B, ClassQuery.EXACT, C, ClassQuery.SUBTYPE, []); | 596 check(B, ClassQuery.EXACT, C, ClassQuery.SUBTYPE, []); |
603 check(B, ClassQuery.SUBTYPE, C, ClassQuery.EXACT, []); | 597 check(B, ClassQuery.SUBTYPE, C, ClassQuery.EXACT, []); |
604 check(B, ClassQuery.SUBCLASS, C, ClassQuery.SUBCLASS, []); | 598 check(B, ClassQuery.SUBCLASS, C, ClassQuery.SUBCLASS, []); |
605 check(B, ClassQuery.SUBCLASS, C, ClassQuery.SUBTYPE, []); | 599 check(B, ClassQuery.SUBCLASS, C, ClassQuery.SUBTYPE, []); |
606 check(B, ClassQuery.SUBTYPE, C, ClassQuery.SUBCLASS, [G]); | 600 check(B, ClassQuery.SUBTYPE, C, ClassQuery.SUBCLASS, [G]); |
607 check(B, ClassQuery.SUBTYPE, C, ClassQuery.SUBTYPE, [F, G]); | 601 check(B, ClassQuery.SUBTYPE, C, ClassQuery.SUBTYPE, [F, G]); |
608 } | 602 } |
OLD | NEW |