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

Side by Side Diff: tests/compiler/dart2js/jsinterop/world_test.dart

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: revert another multipart test Created 4 years, 3 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 jsinterop.world_test; 5 library jsinterop.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 'package:compiler/src/common.dart'; 9 import 'package:compiler/src/common.dart';
10 import 'package:compiler/src/elements/elements.dart' 10 import 'package:compiler/src/elements/elements.dart' show Element, ClassElement;
11 show Element, ClassElement;
12 import 'package:compiler/src/js_backend/js_backend.dart'; 11 import 'package:compiler/src/js_backend/js_backend.dart';
13 import 'package:compiler/src/world.dart'; 12 import 'package:compiler/src/world.dart';
14 import '../type_test_helper.dart'; 13 import '../type_test_helper.dart';
15 14
16 void main() { 15 void main() {
17 asyncTest(() async { 16 asyncTest(() async {
18 await testClasses(); 17 await testClasses();
19 }); 18 });
20 } 19 }
21 20
22 testClasses() async { 21 testClasses() async {
23 test(String mainSource, 22 test(String mainSource,
24 {List<String> directlyInstantiated: const <String>[], 23 {List<String> directlyInstantiated: const <String>[],
25 List<String> indirectlyInstantiated: const <String>[]}) async { 24 List<String> indirectlyInstantiated: const <String>[]}) async {
26 TypeEnvironment env = await TypeEnvironment.create(r""" 25 TypeEnvironment env = await TypeEnvironment.create(
26 r"""
27 @JS() 27 @JS()
28 class A { 28 class A {
29 get foo; 29 get foo;
30 30
31 external A(var foo); 31 external A(var foo);
32 } 32 }
33 33
34 @JS() 34 @JS()
35 class B { 35 class B {
36 get foo; 36 get foo;
(...skipping 28 matching lines...) Expand all
65 65
66 F(this.foo); 66 F(this.foo);
67 } 67 }
68 68
69 newA() => new A(0); 69 newA() => new A(0);
70 newB() => new B(1); 70 newB() => new B(1);
71 newC() => new C(foo: 2); 71 newC() => new C(foo: 2);
72 newD() => new D(foo: 3); 72 newD() => new D(foo: 3);
73 newE() => new E(4); 73 newE() => new E(4);
74 newF() => new F(5); 74 newF() => new F(5);
75 """, mainSource: """ 75 """,
76 mainSource: """
76 import 'package:js/js.dart'; 77 import 'package:js/js.dart';
77 78
78 $mainSource 79 $mainSource
79 """, useMockCompiler: false); 80 """,
81 useMockCompiler: false);
80 Map<String, ClassElement> classEnvironment = <String, ClassElement>{}; 82 Map<String, ClassElement> classEnvironment = <String, ClassElement>{};
81 83
82 ClassElement registerClass(ClassElement cls) { 84 ClassElement registerClass(ClassElement cls) {
83 classEnvironment[cls.name] = cls; 85 classEnvironment[cls.name] = cls;
84 return cls; 86 return cls;
85 } 87 }
86 88
87 ClassWorld world = env.compiler.world; 89 ClassWorld world = env.compiler.world;
88 JavaScriptBackend backend = env.compiler.backend; 90 JavaScriptBackend backend = env.compiler.backend;
89 ClassElement Object_ = registerClass(env.compiler.coreClasses.objectClass); 91 ClassElement Object_ = registerClass(env.compiler.coreClasses.objectClass);
(...skipping 16 matching lines...) Expand all
106 Expect.equals(C.superclass, JavaScriptObject); 108 Expect.equals(C.superclass, JavaScriptObject);
107 Expect.equals(D.superclass, JavaScriptObject); 109 Expect.equals(D.superclass, JavaScriptObject);
108 Expect.equals(E.superclass, Object_); 110 Expect.equals(E.superclass, Object_);
109 Expect.equals(F.superclass, Object_); 111 Expect.equals(F.superclass, Object_);
110 112
111 for (String name in classEnvironment.keys) { 113 for (String name in classEnvironment.keys) {
112 ClassElement cls = classEnvironment[name]; 114 ClassElement cls = classEnvironment[name];
113 bool isInstantiated = false; 115 bool isInstantiated = false;
114 if (directlyInstantiated.contains(name)) { 116 if (directlyInstantiated.contains(name)) {
115 isInstantiated = true; 117 isInstantiated = true;
116 Expect.isTrue(world.isDirectlyInstantiated(cls), 118 Expect.isTrue(
119 world.isDirectlyInstantiated(cls),
117 "Expected $name to be directly instantiated in `${mainSource}`:" 120 "Expected $name to be directly instantiated in `${mainSource}`:"
118 "\n${world.dump(cls)}"); 121 "\n${world.dump(cls)}");
119 } 122 }
120 if (indirectlyInstantiated.contains(name)) { 123 if (indirectlyInstantiated.contains(name)) {
121 isInstantiated = true; 124 isInstantiated = true;
122 Expect.isTrue(world.isIndirectlyInstantiated(cls), 125 Expect.isTrue(
126 world.isIndirectlyInstantiated(cls),
123 "Expected $name to be indirectly instantiated in `${mainSource}`:" 127 "Expected $name to be indirectly instantiated in `${mainSource}`:"
124 "\n${world.dump(cls)}"); 128 "\n${world.dump(cls)}");
125 } 129 }
126 if (!isInstantiated && (name != 'Object' && name != 'Interceptor')) { 130 if (!isInstantiated && (name != 'Object' && name != 'Interceptor')) {
127 Expect.isFalse(world.isInstantiated(cls), 131 Expect.isFalse(
132 world.isInstantiated(cls),
128 "Expected $name to be uninstantiated in `${mainSource}`:" 133 "Expected $name to be uninstantiated in `${mainSource}`:"
129 "\n${world.dump(cls)}"); 134 "\n${world.dump(cls)}");
130 } 135 }
131 } 136 }
132 } 137 }
133 138
134 await test('main() {}'); 139 await test('main() {}');
135 140
136 await test('main() => newA();', 141 await test('main() => newA();',
137 directlyInstantiated: ['A', 'B', 'C', 'D'], 142 directlyInstantiated: ['A', 'B', 'C', 'D'],
138 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); 143 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']);
139 144
140 await test('main() => newB();', 145 await test('main() => newB();',
141 directlyInstantiated: ['A', 'B', 'C', 'D'], 146 directlyInstantiated: ['A', 'B', 'C', 'D'],
142 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); 147 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']);
143 148
144 await test('main() => newC();', 149 await test('main() => newC();',
145 directlyInstantiated: ['A', 'B', 'C', 'D'], 150 directlyInstantiated: ['A', 'B', 'C', 'D'],
146 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); 151 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']);
147 152
148 await test('main() => newD();', 153 await test('main() => newD();',
149 directlyInstantiated: ['A', 'B', 'C', 'D'], 154 directlyInstantiated: ['A', 'B', 'C', 'D'],
150 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); 155 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']);
151 156
152 await test('main() => newE();', 157 await test('main() => newE();', directlyInstantiated: ['E']);
153 directlyInstantiated: ['E']);
154 158
155 await test('main() => newF();', 159 await test('main() => newF();', directlyInstantiated: ['F']);
156 directlyInstantiated: ['F']);
157 160
158 await test('main() => [newD(), newE()];', 161 await test('main() => [newD(), newE()];',
159 directlyInstantiated: ['A', 'B', 'C', 'D', 'E'], 162 directlyInstantiated: ['A', 'B', 'C', 'D', 'E'],
160 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); 163 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']);
161 } 164 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/jsinterop/abstract_test.dart ('k') | tests/compiler/dart2js/kernel/helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698