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.dart'; | 10 import 'package:compiler/src/common.dart'; |
(...skipping 26 matching lines...) Expand all Loading... |
37 new A(); | 37 new A(); |
38 new B(); | 38 new B(); |
39 new C(); | 39 new C(); |
40 new D(); | 40 new D(); |
41 new E(); | 41 new E(); |
42 new F(); | 42 new F(); |
43 new G(); | 43 new G(); |
44 } | 44 } |
45 """, | 45 """, |
46 useMockCompiler: false); | 46 useMockCompiler: false); |
47 ClassWorld classWorld = env.compiler.world; | 47 ClassWorld classWorld = env.compiler.closedWorld; |
48 | 48 |
49 ClassElement Object_ = env.getElement("Object"); | 49 ClassElement Object_ = env.getElement("Object"); |
50 ClassElement A = env.getElement("A"); | 50 ClassElement A = env.getElement("A"); |
51 ClassElement B = env.getElement("B"); | 51 ClassElement B = env.getElement("B"); |
52 ClassElement C = env.getElement("C"); | 52 ClassElement C = env.getElement("C"); |
53 ClassElement D = env.getElement("D"); | 53 ClassElement D = env.getElement("D"); |
54 ClassElement E = env.getElement("E"); | 54 ClassElement E = env.getElement("E"); |
55 ClassElement F = env.getElement("F"); | 55 ClassElement F = env.getElement("F"); |
56 ClassElement G = env.getElement("G"); | 56 ClassElement G = env.getElement("G"); |
57 ClassElement X = env.getElement("X"); | 57 ClassElement X = env.getElement("X"); |
58 | 58 |
59 void checkClasses( | 59 void checkClasses( |
60 String property, | 60 String property, |
61 ClassElement cls, | 61 ClassElement cls, |
62 Iterable<ClassElement> foundClasses, | 62 Iterable<ClassElement> foundClasses, |
63 List<ClassElement> expectedClasses, | 63 List<ClassElement> expectedClasses, |
64 {bool exact: true}) { | 64 {bool exact: true}) { |
65 | 65 |
66 for (ClassElement expectedClass in expectedClasses) { | 66 for (ClassElement expectedClass in expectedClasses) { |
67 Expect.isTrue(foundClasses.contains(expectedClass), | 67 Expect.isTrue(foundClasses.contains(expectedClass), |
68 "Expect $expectedClass in '$property' on $cls. " | 68 "Expect $expectedClass in '$property' on $cls. " |
69 "Found:\n ${foundClasses.join('\n ')}\n" | 69 "Found:\n ${foundClasses.join('\n ')}\n" |
70 "${env.compiler.world.dump(cls)}"); | 70 "${env.compiler.closedWorld.dump(cls)}"); |
71 } | 71 } |
72 if (exact) { | 72 if (exact) { |
73 Expect.equals(expectedClasses.length, foundClasses.length, | 73 Expect.equals(expectedClasses.length, foundClasses.length, |
74 "Unexpected classes " | 74 "Unexpected classes " |
75 "${foundClasses.where((c) => !expectedClasses.contains(c))} " | 75 "${foundClasses.where((c) => !expectedClasses.contains(c))} " |
76 "in '$property' on $cls.\n" | 76 "in '$property' on $cls.\n" |
77 "${env.compiler.world.dump(cls)}"); | 77 "${env.compiler.closedWorld.dump(cls)}"); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 void check( | 81 void check( |
82 String property, | 82 String property, |
83 ClassElement cls, | 83 ClassElement cls, |
84 Iterable<ClassElement> foundClasses, | 84 Iterable<ClassElement> foundClasses, |
85 List<ClassElement> expectedClasses, | 85 List<ClassElement> expectedClasses, |
86 {bool exact: true, | 86 {bool exact: true, |
87 void forEach(ClassElement cls, ForEachFunction f), | 87 void forEach(ClassElement cls, ForEachFunction f), |
88 int getCount(ClassElement cls)}) { | 88 int getCount(ClassElement cls)}) { |
89 checkClasses(property, cls, foundClasses, expectedClasses, exact: exact); | 89 checkClasses(property, cls, foundClasses, expectedClasses, exact: exact); |
90 | 90 |
91 if (forEach != null) { | 91 if (forEach != null) { |
92 List<ClassElement> visited = <ClassElement>[]; | 92 List<ClassElement> visited = <ClassElement>[]; |
93 forEach(cls, (ClassElement c) { | 93 forEach(cls, (ClassElement c) { |
94 visited.add(c); | 94 visited.add(c); |
95 }); | 95 }); |
96 checkClasses( | 96 checkClasses( |
97 'forEach($property)', cls, visited, expectedClasses, exact: exact); | 97 'forEach($property)', cls, visited, expectedClasses, exact: exact); |
98 } | 98 } |
99 | 99 |
100 if (getCount != null && exact) { | 100 if (getCount != null && exact) { |
101 int count = getCount(cls); | 101 int count = getCount(cls); |
102 Expect.equals(expectedClasses.length, count, | 102 Expect.equals(expectedClasses.length, count, |
103 "Unexpected class count in '$property' on $cls.\n" | 103 "Unexpected class count in '$property' on $cls.\n" |
104 "${env.compiler.world.dump(cls)}"); | 104 "${env.compiler.closedWorld.dump(cls)}"); |
105 } | 105 } |
106 | 106 |
107 } | 107 } |
108 | 108 |
109 void testSubclasses( | 109 void testSubclasses( |
110 ClassElement cls, | 110 ClassElement cls, |
111 List<ClassElement> expectedClasses, | 111 List<ClassElement> expectedClasses, |
112 {bool exact: true}) { | 112 {bool exact: true}) { |
113 check( | 113 check( |
114 'subclassesOf', | 114 'subclassesOf', |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 new D2(); | 250 new D2(); |
251 new E3(); | 251 new E3(); |
252 new F1(); | 252 new F1(); |
253 new F2(); | 253 new F2(); |
254 new G2(); | 254 new G2(); |
255 new G3(); | 255 new G3(); |
256 new H4(); | 256 new H4(); |
257 } | 257 } |
258 """, | 258 """, |
259 useMockCompiler: false); | 259 useMockCompiler: false); |
260 ClassWorld classWorld = env.compiler.world; | 260 ClassWorld classWorld = env.compiler.closedWorld; |
261 | 261 |
262 check(String name, | 262 check(String name, |
263 {bool hasStrictSubtype, | 263 {bool hasStrictSubtype, |
264 bool hasOnlySubclasses}) { | 264 bool hasOnlySubclasses}) { |
265 ClassElement cls = env.getElement(name); | 265 ClassElement cls = env.getElement(name); |
266 Expect.equals(hasStrictSubtype, classWorld.hasAnyStrictSubtype(cls), | 266 Expect.equals(hasStrictSubtype, classWorld.hasAnyStrictSubtype(cls), |
267 "Unexpected hasAnyStrictSubtype property on $cls."); | 267 "Unexpected hasAnyStrictSubtype property on $cls."); |
268 Expect.equals(hasOnlySubclasses, classWorld.hasOnlySubclasses(cls), | 268 Expect.equals(hasOnlySubclasses, classWorld.hasOnlySubclasses(cls), |
269 "Unexpected hasOnlySubclasses property on $cls."); | 269 "Unexpected hasOnlySubclasses property on $cls."); |
270 } | 270 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 check("G3", hasStrictSubtype: false, hasOnlySubclasses: true); | 316 check("G3", hasStrictSubtype: false, hasOnlySubclasses: true); |
317 check("G4", hasStrictSubtype: false, hasOnlySubclasses: true); | 317 check("G4", hasStrictSubtype: false, hasOnlySubclasses: true); |
318 | 318 |
319 // class H4 extends H2 with H extends H1 extends H instantiated | 319 // class H4 extends H2 with H extends H1 extends H instantiated |
320 check("H", hasStrictSubtype: true, hasOnlySubclasses: true); | 320 check("H", hasStrictSubtype: true, hasOnlySubclasses: true); |
321 check("H1", hasStrictSubtype: true, hasOnlySubclasses: true); | 321 check("H1", hasStrictSubtype: true, hasOnlySubclasses: true); |
322 check("H2", hasStrictSubtype: true, hasOnlySubclasses: true); | 322 check("H2", hasStrictSubtype: true, hasOnlySubclasses: true); |
323 check("H3", hasStrictSubtype: false, hasOnlySubclasses: true); | 323 check("H3", hasStrictSubtype: false, hasOnlySubclasses: true); |
324 check("H4", hasStrictSubtype: false, hasOnlySubclasses: true); | 324 check("H4", hasStrictSubtype: false, hasOnlySubclasses: true); |
325 } | 325 } |
OLD | NEW |