OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 instantiated_classes_test; | 5 library instantiated_classes_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
10 import 'package:compiler/src/elements/elements.dart' | 10 import 'package:compiler/src/elements/elements.dart' show ClassElement; |
11 show ClassElement; | |
12 import 'type_test_helper.dart'; | 11 import 'type_test_helper.dart'; |
13 | 12 |
14 void main() { | 13 void main() { |
15 asyncTest(() => Future.forEach([ | 14 asyncTest(() => Future.forEach([ |
16 () => test("class Class {}", ["Class"]), | 15 () => test("class Class {}", ["Class"]), |
17 () => test("""abstract class A {} | 16 () => test( |
| 17 """abstract class A {} |
18 class Class extends A {}""", | 18 class Class extends A {}""", |
19 ["Class"]), | 19 ["Class"]), |
20 () => test("""class A {} | 20 () => test( |
| 21 """class A {} |
21 class Class extends A {}""", | 22 class Class extends A {}""", |
22 ["Class"]), | 23 ["Class"]), |
23 () => test("""class A {} | 24 () => test( |
| 25 """class A {} |
24 class B {} | 26 class B {} |
25 class Class extends A {}""", | 27 class Class extends A {}""", |
26 ["Class"]), | 28 ["Class"]), |
27 () => test("""class A {} | 29 () => test( |
| 30 """class A {} |
28 class Class implements A {}""", | 31 class Class implements A {}""", |
29 ["Class"]), | 32 ["Class"]), |
30 () => test("""class A {} | 33 () => test( |
| 34 """class A {} |
31 class Class extends Object with A {}""", | 35 class Class extends Object with A {}""", |
32 ["Class"]), | 36 ["Class"]), |
33 () => test("""class A {} | 37 () => test( |
| 38 """class A {} |
34 class B {} | 39 class B {} |
35 class Class extends Object with B implements A {}""", | 40 class Class extends Object with B implements A {}""", |
36 ["Class"]), | 41 ["Class"]), |
37 | 42 |
38 () => test("""class A {} | 43 () => test( |
| 44 """class A {} |
39 class Class {}""", | 45 class Class {}""", |
40 ["Class", "A"], ["Class", "A"]), | 46 ["Class", "A"], |
41 () => test("""class A {} | 47 ["Class", "A"]), |
| 48 () => test( |
| 49 """class A {} |
42 class Class extends A {}""", | 50 class Class extends A {}""", |
43 ["Class", "A"], ["Class", "A"]), | 51 ["Class", "A"], |
44 () => test("""class A {} | 52 ["Class", "A"]), |
| 53 () => test( |
| 54 """class A {} |
45 class Class implements A {}""", | 55 class Class implements A {}""", |
46 ["Class", "A"], ["Class", "A"]), | 56 ["Class", "A"], |
47 () => test("""class A {} | 57 ["Class", "A"]), |
| 58 () => test( |
| 59 """class A {} |
48 class B extends A {} | 60 class B extends A {} |
49 class Class extends B {}""", | 61 class Class extends B {}""", |
50 ["Class", "A"], ["Class", "A"]), | 62 ["Class", "A"], |
51 () => test("""class A {} | 63 ["Class", "A"]), |
| 64 () => test( |
| 65 """class A {} |
52 class B {} | 66 class B {} |
53 class Class extends B with A {}""", | 67 class Class extends B with A {}""", |
54 ["Class", "A"], ["Class", "A"]), | 68 ["Class", "A"], |
| 69 ["Class", "A"]), |
55 | 70 |
56 // TODO(johnniwinther): Avoid registration of `Class` as instantiated. | 71 // TODO(johnniwinther): Avoid registration of `Class` as instantiated. |
57 () => test("""class A {} | 72 () => test( |
| 73 """class A {} |
58 class Class implements A { | 74 class Class implements A { |
59 factory Class() = A; | 75 factory Class() = A; |
60 }""", | 76 }""", |
61 ["Class", "A"], ["Class"]), | 77 ["Class", "A"], |
62 ], (f) => f())); | 78 ["Class"]), |
| 79 ], (f) => f())); |
63 } | 80 } |
64 | 81 |
65 Future test(String source, List<String> directlyInstantiatedClasses, | 82 Future test(String source, List<String> directlyInstantiatedClasses, |
66 [List<String> newClasses = const <String>["Class"]]) { | 83 [List<String> newClasses = const <String>["Class"]]) { |
67 StringBuffer mainSource = new StringBuffer(); | 84 StringBuffer mainSource = new StringBuffer(); |
68 mainSource.write('main() {\n'); | 85 mainSource.write('main() {\n'); |
69 for (String newClass in newClasses) { | 86 for (String newClass in newClasses) { |
70 mainSource.write(' new $newClass();\n'); | 87 mainSource.write(' new $newClass();\n'); |
71 } | 88 } |
72 mainSource.write('}'); | 89 mainSource.write('}'); |
73 return TypeEnvironment.create(source, | 90 return TypeEnvironment |
74 mainSource: mainSource.toString(), | 91 .create(source, mainSource: mainSource.toString(), useMockCompiler: true) |
75 useMockCompiler: true).then((env) { | 92 .then((env) { |
76 Iterable<ClassElement> expectedClasses = | 93 Iterable<ClassElement> expectedClasses = |
77 directlyInstantiatedClasses.map(env.getElement); | 94 directlyInstantiatedClasses.map(env.getElement); |
78 Iterable<ClassElement> actualClasses = | 95 Iterable<ClassElement> actualClasses = env |
79 env.compiler.resolverWorld.directlyInstantiatedClasses.where( | 96 .compiler.resolverWorld.directlyInstantiatedClasses |
80 (c) => c.library == env.compiler.mainApp); | 97 .where((c) => c.library == env.compiler.mainApp); |
81 Expect.setEquals(expectedClasses, actualClasses); | 98 Expect.setEquals(expectedClasses, actualClasses); |
82 }); | 99 }); |
83 } | 100 } |
84 | |
85 | |
OLD | NEW |