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

Side by Side Diff: pkg/analysis_services/test/search/hierarchy_test.dart

Issue 484733003: Import analysis_services.dart into analysis_server.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.services.src.search.hierarchy;
6
7 import 'dart:async';
8
9 import 'package:analysis_services/index/index.dart';
10 import 'package:analysis_services/index/local_memory_index.dart';
11 import 'package:analysis_services/search/hierarchy.dart';
12 import 'package:analysis_services/src/search/search_engine.dart';
13 import 'package:analysis_testing/abstract_single_unit.dart';
14 import 'package:analysis_testing/reflective_tests.dart';
15 import 'package:analyzer/src/generated/element.dart';
16 import 'package:unittest/unittest.dart';
17
18
19 main() {
20 groupSep = ' | ';
21 runReflectiveTests(HierarchyTest);
22 }
23
24
25 @ReflectiveTestCase()
26 class HierarchyTest extends AbstractSingleUnitTest {
27 Index index;
28 SearchEngineImpl searchEngine;
29
30 void setUp() {
31 super.setUp();
32 index = createLocalMemoryIndex();
33 searchEngine = new SearchEngineImpl(index);
34 }
35
36 void test_getClassMembers() {
37 _indexTestUnit('''
38 class A {
39 A() {}
40 var ma1;
41 ma2() {}
42 }
43 class B extends A {
44 B() {}
45 B.named() {}
46 var mb1;
47 mb2() {}
48 }
49 ''');
50 {
51 ClassElement classA = findElement('A');
52 List<Element> members = getClassMembers(classA);
53 expect(members.map((e) => e.name), unorderedEquals(['ma1', 'ma2']));
54 }
55 {
56 ClassElement classB = findElement('B');
57 List<Element> members = getClassMembers(classB);
58 expect(members.map((e) => e.name), unorderedEquals(['mb1', 'mb2']));
59 }
60 }
61
62 Future test_getHierarchyMembers_constructors() {
63 _indexTestUnit('''
64 class A {
65 A() {}
66 }
67 class B extends A {
68 B() {}
69 }
70 ''');
71 ClassElement classA = findElement("A");
72 ClassElement classB = findElement("B");
73 ClassMemberElement memberA = classA.constructors[0];
74 ClassMemberElement memberB = classB.constructors[0];
75 var futureA = getHierarchyMembers(searchEngine, memberA).then((members) {
76 expect(members, unorderedEquals([memberA]));
77 });
78 var futureB = getHierarchyMembers(searchEngine, memberB).then((members) {
79 expect(members, unorderedEquals([memberB]));
80 });
81 return Future.wait([futureA, futureB]);
82 }
83
84 Future test_getHierarchyMembers_fields() {
85 _indexTestUnit('''
86 class A {
87 int foo;
88 }
89 class B extends A {
90 get foo => null;
91 }
92 class C extends B {
93 set foo(x) {}
94 }
95 class D {
96 int foo;
97 }
98 ''');
99 ClassElement classA = findElement("A");
100 ClassElement classB = findElement("B");
101 ClassElement classC = findElement("C");
102 ClassElement classD = findElement("D");
103 ClassElement classE = findElement("E");
104 ClassMemberElement memberA = classA.fields[0];
105 ClassMemberElement memberB = classB.fields[0];
106 ClassMemberElement memberC = classC.fields[0];
107 ClassMemberElement memberD = classD.fields[0];
108 var futureA = getHierarchyMembers(searchEngine, memberA).then((members) {
109 expect(members, unorderedEquals([memberA, memberB, memberC]));
110 });
111 var futureB = getHierarchyMembers(searchEngine, memberB).then((members) {
112 expect(members, unorderedEquals([memberA, memberB, memberC]));
113 });
114 var futureC = getHierarchyMembers(searchEngine, memberC).then((members) {
115 expect(members, unorderedEquals([memberA, memberB, memberC]));
116 });
117 var futureD = getHierarchyMembers(searchEngine, memberD).then((members) {
118 expect(members, unorderedEquals([memberD]));
119 });
120 return Future.wait([futureA, futureB, futureC, futureD]);
121 }
122
123 Future test_getHierarchyMembers_methods() {
124 _indexTestUnit('''
125 class A {
126 foo() {}
127 }
128 class B extends A {
129 foo() {}
130 }
131 class C extends B {
132 foo() {}
133 }
134 class D {
135 foo() {}
136 }
137 class E extends D {
138 foo() {}
139 }
140 ''');
141 ClassElement classA = findElement("A");
142 ClassElement classB = findElement("B");
143 ClassElement classC = findElement("C");
144 ClassElement classD = findElement("D");
145 ClassElement classE = findElement("E");
146 ClassMemberElement memberA = classA.methods[0];
147 ClassMemberElement memberB = classB.methods[0];
148 ClassMemberElement memberC = classC.methods[0];
149 ClassMemberElement memberD = classD.methods[0];
150 ClassMemberElement memberE = classE.methods[0];
151 var futureA = getHierarchyMembers(searchEngine, memberA).then((members) {
152 expect(members, unorderedEquals([memberA, memberB, memberC]));
153 });
154 var futureB = getHierarchyMembers(searchEngine, memberB).then((members) {
155 expect(members, unorderedEquals([memberA, memberB, memberC]));
156 });
157 var futureC = getHierarchyMembers(searchEngine, memberC).then((members) {
158 expect(members, unorderedEquals([memberA, memberB, memberC]));
159 });
160 var futureD = getHierarchyMembers(searchEngine, memberD).then((members) {
161 expect(members, unorderedEquals([memberD, memberE]));
162 });
163 var futureE = getHierarchyMembers(searchEngine, memberE).then((members) {
164 expect(members, unorderedEquals([memberD, memberE]));
165 });
166 return Future.wait([futureA, futureB, futureC, futureD, futureE]);
167 }
168
169 Future test_getHierarchyMembers_withInterfaces() {
170 _indexTestUnit('''
171 class A {
172 foo() {}
173 }
174 class B implements A {
175 foo() {}
176 }
177 abstract class C implements A {
178 }
179 class D extends C {
180 foo() {}
181 }
182 class E {
183 foo() {}
184 }
185 ''');
186 ClassElement classA = findElement("A");
187 ClassElement classB = findElement("B");
188 ClassElement classC = findElement("C");
189 ClassElement classD = findElement("D");
190 ClassElement classE = findElement("E");
191 ClassMemberElement memberA = classA.methods[0];
192 ClassMemberElement memberB = classB.methods[0];
193 ClassMemberElement memberD = classD.methods[0];
194 var futureA = getHierarchyMembers(searchEngine, memberA).then((members) {
195 expect(members, unorderedEquals([memberA, memberB, memberD]));
196 });
197 var futureB = getHierarchyMembers(searchEngine, memberB).then((members) {
198 expect(members, unorderedEquals([memberA, memberB, memberD]));
199 });
200 var futureD = getHierarchyMembers(searchEngine, memberD).then((members) {
201 expect(members, unorderedEquals([memberA, memberB, memberD]));
202 });
203 return Future.wait([futureA, futureB, futureD]);
204 }
205
206 void test_getMembers() {
207 _indexTestUnit('''
208 class A {
209 A() {}
210 var ma1;
211 ma2() {}
212 }
213 class B extends A {
214 B() {}
215 B.named() {}
216 var mb1;
217 mb2() {}
218 }
219 ''');
220 {
221 ClassElement classA = findElement('A');
222 List<Element> members = getMembers(classA);
223 expect(members.map((e) => e.name), unorderedEquals(['ma1', 'ma2', '==']));
224 }
225 {
226 ClassElement classB = findElement('B');
227 List<Element> members = getMembers(classB);
228 expect(
229 members.map((e) => e.name),
230 unorderedEquals(['mb1', 'mb2', 'ma1', 'ma2', '==']));
231 }
232 }
233
234 Future test_getSubClasses() {
235 _indexTestUnit('''
236 class A {}
237 class B extends A {}
238 class C extends B {}
239 class D extends B implements A {}
240 class M {}
241 class E extends A with M {}
242 ''');
243 ClassElement classA = findElement("A");
244 ClassElement classB = findElement("B");
245 ClassElement classC = findElement("C");
246 ClassElement classD = findElement("D");
247 ClassElement classM = findElement("M");
248 ClassElement classE = findElement("E");
249 var futureA = getSubClasses(searchEngine, classA).then((subs) {
250 expect(subs, unorderedEquals([classB, classC, classD, classE]));
251 });
252 var futureB = getSubClasses(searchEngine, classB).then((subs) {
253 expect(subs, unorderedEquals([classC, classD]));
254 });
255 var futureC = getSubClasses(searchEngine, classC).then((subs) {
256 expect(subs, isEmpty);
257 });
258 var futureM = getSubClasses(searchEngine, classM).then((subs) {
259 expect(subs, unorderedEquals([classE]));
260 });
261 return Future.wait([futureA, futureB, futureC, futureM]);
262 }
263
264 void test_getSuperClasses() {
265 _indexTestUnit('''
266 class A {}
267 class B extends A {}
268 class C extends B {}
269 class D extends B implements A {}
270 class M {}
271 class E extends A with M {}
272 class F implements A {}
273 ''');
274 ClassElement classA = findElement("A");
275 ClassElement classB = findElement("B");
276 ClassElement classC = findElement("C");
277 ClassElement classD = findElement("D");
278 ClassElement classE = findElement("E");
279 ClassElement classF = findElement("F");
280 ClassElement objectElement = classA.supertype.element;
281 // Object
282 {
283 Set<ClassElement> supers = getSuperClasses(objectElement);
284 expect(supers, isEmpty);
285 }
286 // A
287 {
288 Set<ClassElement> supers = getSuperClasses(classA);
289 expect(supers, unorderedEquals([objectElement]));
290 }
291 // B
292 {
293 Set<ClassElement> supers = getSuperClasses(classB);
294 expect(supers, unorderedEquals([objectElement, classA]));
295 }
296 // C
297 {
298 Set<ClassElement> supers = getSuperClasses(classC);
299 expect(supers, unorderedEquals([objectElement, classA, classB]));
300 }
301 // D
302 {
303 Set<ClassElement> supers = getSuperClasses(classD);
304 expect(supers, unorderedEquals([objectElement, classA, classB]));
305 }
306 // E
307 {
308 Set<ClassElement> supers = getSuperClasses(classE);
309 expect(supers, unorderedEquals([objectElement, classA]));
310 }
311 // F
312 {
313 Set<ClassElement> supers = getSuperClasses(classF);
314 expect(supers, unorderedEquals([objectElement, classA]));
315 }
316 }
317
318 void _indexTestUnit(String code) {
319 resolveTestUnit(code);
320 index.indexUnit(context, testUnit);
321 }
322 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/test/refactoring/test_all.dart ('k') | pkg/analysis_services/test/search/search_engine_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698