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 test.integration.search.domain; | 5 library test.integration.search.domain; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_testing/reflective_tests.dart'; | 9 import 'package:analysis_testing/reflective_tests.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } else { | 53 } else { |
54 fail('Class $name not found in hierarchy results'); | 54 fail('Class $name not found in hierarchy results'); |
55 return null; | 55 return null; |
56 } | 56 } |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 @ReflectiveTestCase() | 60 @ReflectiveTestCase() |
61 class SearchDomainIntegrationTest extends AbstractAnalysisServerIntegrationTest | 61 class SearchDomainIntegrationTest extends AbstractAnalysisServerIntegrationTest |
62 { | 62 { |
63 test_getTypeHierarchy_classElement() { | 63 /** |
| 64 * Pathname of the main file to run tests in. |
| 65 */ |
| 66 String pathname; |
| 67 |
| 68 test_getTypeHierarchy() { |
| 69 pathname = sourcePath('test.dart'); |
| 70 // Write a dummy file which will be overridden by tests using |
| 71 // [sendAnalysisUpdateContent]. |
| 72 writeFile(pathname, '// dummy'); |
| 73 standardAnalysisRoot(); |
| 74 |
| 75 // Run all the getTypeHierarchy tests at once so that the server can take |
| 76 // advantage of incremental analysis and the test doesn't time out. |
| 77 List tests = [getTypeHierarchy_classElement, getTypeHierarchy_displayName, |
| 78 getTypeHierarchy_memberElement, getTypeHierarchy_superclass, |
| 79 getTypeHierarchy_interfaces, getTypeHierarchy_mixins, |
| 80 getTypeHierarchy_subclasses, getTypeHierarchy_badTarget, |
| 81 getTypeHierarchy_functionTarget]; |
| 82 return Future.forEach(tests, (test) => test()); |
| 83 } |
| 84 |
| 85 Future getTypeHierarchy_classElement() { |
64 String text = | 86 String text = |
65 r''' | 87 r''' |
66 class Base {} | 88 class Base {} |
67 class Pivot /* target */ extends Base {} | 89 class Pivot /* target */ extends Base {} |
68 class Derived extends Pivot {} | 90 class Derived extends Pivot {} |
69 '''; | 91 '''; |
70 return typeHierarchyTest(text).then((HierarchyResults results) { | 92 return typeHierarchyTest(text).then((HierarchyResults results) { |
71 expect(results.items, hasLength(4)); | 93 expect(results.items, hasLength(4)); |
72 expect(results.nameToIndex['Pivot'], equals(0)); | 94 expect(results.nameToIndex['Pivot'], equals(0)); |
73 void checkElement(String name) { | 95 void checkElement(String name) { |
74 // We don't check the full element data structure; just enough to make | 96 // We don't check the full element data structure; just enough to make |
75 // sure that we're pointing to the correct element. | 97 // sure that we're pointing to the correct element. |
76 Map element = results.items[results.nameToIndex[name]]['classElement']; | 98 Map element = results.items[results.nameToIndex[name]]['classElement']; |
77 expect(element['kind'], equals('CLASS')); | 99 expect(element['kind'], equals('CLASS')); |
78 expect(element['name'], equals(name)); | 100 expect(element['name'], equals(name)); |
79 if (name != 'Object') { | 101 if (name != 'Object') { |
80 expect(element['location']['offset'], equals(text.indexOf( | 102 expect(element['location']['offset'], equals(text.indexOf( |
81 'class $name') + 'class '.length)); | 103 'class $name') + 'class '.length)); |
82 } | 104 } |
83 } | 105 } |
84 checkElement('Object'); | 106 checkElement('Object'); |
85 checkElement('Base'); | 107 checkElement('Base'); |
86 checkElement('Pivot'); | 108 checkElement('Pivot'); |
87 checkElement('Derived'); | 109 checkElement('Derived'); |
88 }); | 110 }); |
89 } | 111 } |
90 | 112 |
91 test_getTypeHierarchy_displayName() { | 113 Future getTypeHierarchy_displayName() { |
92 String text = r''' | 114 String text = |
| 115 r''' |
93 class Base<T> {} | 116 class Base<T> {} |
94 class Pivot /* target */ extends Base<int> {} | 117 class Pivot /* target */ extends Base<int> {} |
95 '''; | 118 '''; |
96 return typeHierarchyTest(text).then((HierarchyResults results) { | 119 return typeHierarchyTest(text).then((HierarchyResults results) { |
97 expect(results.items, hasLength(3)); | 120 expect(results.items, hasLength(3)); |
98 expect(results.getItem('Object')['displayName'], isNull); | 121 expect(results.getItem('Object')['displayName'], isNull); |
99 expect(results.getItem('Base')['displayName'], equals('Base<int>')); | 122 expect(results.getItem('Base')['displayName'], equals('Base<int>')); |
100 expect(results.getItem('Pivot')['displayName'], isNull); | 123 expect(results.getItem('Pivot')['displayName'], isNull); |
101 }); | 124 }); |
102 } | 125 } |
103 | 126 |
104 test_getTypeHierarchy_memberElement() { | 127 Future getTypeHierarchy_memberElement() { |
105 String text = | 128 String text = |
106 r''' | 129 r''' |
107 class Base1 { | 130 class Base1 { |
108 void foo /* base1 */ (); | 131 void foo /* base1 */ (); |
109 } | 132 } |
110 class Base2 extends Base1 {} | 133 class Base2 extends Base1 {} |
111 class Pivot extends Base2 { | 134 class Pivot extends Base2 { |
112 void foo /* target */ (); | 135 void foo /* target */ (); |
113 } | 136 } |
114 class Derived1 extends Pivot {} | 137 class Derived1 extends Pivot {} |
115 class Derived2 extends Derived1 { | 138 class Derived2 extends Derived1 { |
116 void foo /* derived2 */ (); | 139 void foo /* derived2 */ (); |
117 }'''; | 140 }'''; |
118 return typeHierarchyTest(text).then((HierarchyResults results) { | 141 return typeHierarchyTest(text).then((HierarchyResults results) { |
119 expect(results.items, hasLength(6)); | 142 expect(results.items, hasLength(6)); |
120 expect(results.getItem('Object')['memberElement'], isNull); | 143 expect(results.getItem('Object')['memberElement'], isNull); |
121 expect(results.getItem('Base1')['memberElement']['location']['offset'], | 144 expect(results.getItem('Base1')['memberElement']['location']['offset'], |
122 equals(text.indexOf('foo /* base1 */'))); | 145 equals(text.indexOf('foo /* base1 */'))); |
123 expect(results.getItem('Base2')['memberElement'], isNull); | 146 expect(results.getItem('Base2')['memberElement'], isNull); |
124 expect(results.getItem('Pivot')['memberElement']['location']['offset'], | 147 expect(results.getItem('Pivot')['memberElement']['location']['offset'], |
125 equals(text.indexOf('foo /* target */'))); | 148 equals(text.indexOf('foo /* target */'))); |
126 expect(results.getItem('Derived1')['memberElement'], isNull); | 149 expect(results.getItem('Derived1')['memberElement'], isNull); |
127 expect(results.getItem('Derived2')['memberElement']['location']['offset'], | 150 expect(results.getItem('Derived2')['memberElement']['location']['offset'], |
128 equals(text.indexOf('foo /* derived2 */'))); | 151 equals(text.indexOf('foo /* derived2 */'))); |
129 }); | 152 }); |
130 } | 153 } |
131 | 154 |
132 test_getTypeHierarchy_superclass() { | 155 Future getTypeHierarchy_superclass() { |
133 String text = | 156 String text = |
134 r''' | 157 r''' |
135 class Base1 {} | 158 class Base1 {} |
136 class Base2 extends Base1 {} | 159 class Base2 extends Base1 {} |
137 class Pivot /* target */ extends Base2 {} | 160 class Pivot /* target */ extends Base2 {} |
138 '''; | 161 '''; |
139 return typeHierarchyTest(text).then((HierarchyResults results) { | 162 return typeHierarchyTest(text).then((HierarchyResults results) { |
140 expect(results.items, hasLength(4)); | 163 expect(results.items, hasLength(4)); |
141 expect(results.getItem('Object')['superclass'], isNull); | 164 expect(results.getItem('Object')['superclass'], isNull); |
142 expect(results.getItem('Base1')['superclass'], equals( | 165 expect(results.getItem('Base1')['superclass'], equals( |
143 results.nameToIndex['Object'])); | 166 results.nameToIndex['Object'])); |
144 expect(results.getItem('Base2')['superclass'], equals( | 167 expect(results.getItem('Base2')['superclass'], equals( |
145 results.nameToIndex['Base1'])); | 168 results.nameToIndex['Base1'])); |
146 expect(results.getItem('Pivot')['superclass'], equals( | 169 expect(results.getItem('Pivot')['superclass'], equals( |
147 results.nameToIndex['Base2'])); | 170 results.nameToIndex['Base2'])); |
148 }); | 171 }); |
149 } | 172 } |
150 | 173 |
151 test_getTypeHierarchy_interfaces() { | 174 Future getTypeHierarchy_interfaces() { |
152 String text = | 175 String text = |
153 r''' | 176 r''' |
154 class Interface1 {} | 177 class Interface1 {} |
155 class Interface2 {} | 178 class Interface2 {} |
156 class Pivot /* target */ implements Interface1, Interface2 {} | 179 class Pivot /* target */ implements Interface1, Interface2 {} |
157 '''; | 180 '''; |
158 return typeHierarchyTest(text).then((HierarchyResults results) { | 181 return typeHierarchyTest(text).then((HierarchyResults results) { |
159 expect(results.items, hasLength(4)); | 182 expect(results.items, hasLength(4)); |
160 expect(results.pivot['interfaces'], hasLength(2)); | 183 expect(results.pivot['interfaces'], hasLength(2)); |
161 expect(results.pivot['interfaces'], contains( | 184 expect(results.pivot['interfaces'], contains( |
162 results.nameToIndex['Interface1'])); | 185 results.nameToIndex['Interface1'])); |
163 expect(results.pivot['interfaces'], contains( | 186 expect(results.pivot['interfaces'], contains( |
164 results.nameToIndex['Interface2'])); | 187 results.nameToIndex['Interface2'])); |
165 expect(results.getItem('Object')['interfaces'], isEmpty); | 188 expect(results.getItem('Object')['interfaces'], isEmpty); |
166 expect(results.getItem('Interface1')['interfaces'], isEmpty); | 189 expect(results.getItem('Interface1')['interfaces'], isEmpty); |
167 expect(results.getItem('Interface2')['interfaces'], isEmpty); | 190 expect(results.getItem('Interface2')['interfaces'], isEmpty); |
168 }); | 191 }); |
169 } | 192 } |
170 | 193 |
171 test_getTypeHierarchy_mixins() { | 194 Future getTypeHierarchy_mixins() { |
172 String text = | 195 String text = |
173 r''' | 196 r''' |
174 class Base {} | 197 class Base {} |
175 class Mixin1 {} | 198 class Mixin1 {} |
176 class Mixin2 {} | 199 class Mixin2 {} |
177 class Pivot /* target */ extends Base with Mixin1, Mixin2 {} | 200 class Pivot /* target */ extends Base with Mixin1, Mixin2 {} |
178 '''; | 201 '''; |
179 return typeHierarchyTest(text).then((HierarchyResults results) { | 202 return typeHierarchyTest(text).then((HierarchyResults results) { |
180 expect(results.items, hasLength(5)); | 203 expect(results.items, hasLength(5)); |
181 expect(results.pivot['mixins'], hasLength(2)); | 204 expect(results.pivot['mixins'], hasLength(2)); |
182 expect(results.pivot['mixins'], contains(results.nameToIndex['Mixin1'])); | 205 expect(results.pivot['mixins'], contains(results.nameToIndex['Mixin1'])); |
183 expect(results.pivot['mixins'], contains(results.nameToIndex['Mixin2'])); | 206 expect(results.pivot['mixins'], contains(results.nameToIndex['Mixin2'])); |
184 expect(results.getItem('Object')['mixins'], isEmpty); | 207 expect(results.getItem('Object')['mixins'], isEmpty); |
185 expect(results.getItem('Base')['mixins'], isEmpty); | 208 expect(results.getItem('Base')['mixins'], isEmpty); |
186 expect(results.getItem('Mixin1')['mixins'], isEmpty); | 209 expect(results.getItem('Mixin1')['mixins'], isEmpty); |
187 expect(results.getItem('Mixin2')['mixins'], isEmpty); | 210 expect(results.getItem('Mixin2')['mixins'], isEmpty); |
188 }); | 211 }); |
189 } | 212 } |
190 | 213 |
191 test_getTypeHierarchy_subclasses() { | 214 Future getTypeHierarchy_subclasses() { |
192 String text = | 215 String text = |
193 r''' | 216 r''' |
194 class Base {} | 217 class Base {} |
195 class Pivot /* target */ extends Base {} | 218 class Pivot /* target */ extends Base {} |
196 class Sub1 extends Pivot {} | 219 class Sub1 extends Pivot {} |
197 class Sub2 extends Pivot {} | 220 class Sub2 extends Pivot {} |
198 class Sub2a extends Sub2 {} | 221 class Sub2a extends Sub2 {} |
199 '''; | 222 '''; |
200 return typeHierarchyTest(text).then((HierarchyResults results) { | 223 return typeHierarchyTest(text).then((HierarchyResults results) { |
201 expect(results.items, hasLength(6)); | 224 expect(results.items, hasLength(6)); |
202 expect(results.pivot['subclasses'], hasLength(2)); | 225 expect(results.pivot['subclasses'], hasLength(2)); |
203 expect(results.pivot['subclasses'], contains(results.nameToIndex['Sub1']) | 226 expect(results.pivot['subclasses'], contains(results.nameToIndex['Sub1']) |
204 ); | 227 ); |
205 expect(results.pivot['subclasses'], contains(results.nameToIndex['Sub2']) | 228 expect(results.pivot['subclasses'], contains(results.nameToIndex['Sub2']) |
206 ); | 229 ); |
207 expect(results.getItem('Object')['subclasses'], isEmpty); | 230 expect(results.getItem('Object')['subclasses'], isEmpty); |
208 expect(results.getItem('Base')['subclasses'], isEmpty); | 231 expect(results.getItem('Base')['subclasses'], isEmpty); |
209 expect(results.getItem('Sub1')['subclasses'], isEmpty); | 232 expect(results.getItem('Sub1')['subclasses'], isEmpty); |
210 expect(results.getItem('Sub2')['subclasses'], equals( | 233 expect(results.getItem('Sub2')['subclasses'], equals( |
211 [results.nameToIndex['Sub2a']])); | 234 [results.nameToIndex['Sub2a']])); |
212 expect(results.getItem('Sub2a')['subclasses'], isEmpty); | 235 expect(results.getItem('Sub2a')['subclasses'], isEmpty); |
213 }); | 236 }); |
214 } | 237 } |
215 | 238 |
216 test_getTypeHierarchy_badTarget() { | 239 Future getTypeHierarchy_badTarget() { |
217 String text = | 240 String text = |
218 r''' | 241 r''' |
219 main() { | 242 main() { |
220 if /* target */ (true) { | 243 if /* target */ (true) { |
221 print('Hello'); | 244 print('Hello'); |
222 } | 245 } |
223 } | 246 } |
224 '''; | 247 '''; |
225 return typeHierarchyTest(text).then((HierarchyResults results) { | 248 return typeHierarchyTest(text).then((HierarchyResults results) { |
226 expect(results, isNull); | 249 expect(results, isNull); |
227 }); | 250 }); |
228 } | 251 } |
229 | 252 |
230 test_getTypeHierarchy_functionTarget() { | 253 Future getTypeHierarchy_functionTarget() { |
231 String text = | 254 String text = r''' |
232 r''' | |
233 main /* target */ () { | 255 main /* target */ () { |
234 } | 256 } |
235 '''; | 257 '''; |
236 return typeHierarchyTest(text).then((HierarchyResults results) { | 258 return typeHierarchyTest(text).then((HierarchyResults results) { |
237 expect(results, isNull); | 259 expect(results, isNull); |
238 }); | 260 }); |
239 } | 261 } |
240 | 262 |
241 Future<HierarchyResults> typeHierarchyTest(String text) { | 263 Future<HierarchyResults> typeHierarchyTest(String text) { |
242 String pathname = sourcePath('test.dart'); | |
243 int offset = text.indexOf(' /* target */') - 1; | 264 int offset = text.indexOf(' /* target */') - 1; |
244 writeFile(pathname, text); | 265 sendAnalysisUpdateContent({ |
245 standardAnalysisRoot(); | 266 pathname: { |
| 267 'type': 'add', |
| 268 'content': text |
| 269 } |
| 270 }); |
246 return analysisFinished.then((_) => sendSearchGetTypeHierarchy(pathname, | 271 return analysisFinished.then((_) => sendSearchGetTypeHierarchy(pathname, |
247 offset)).then((result) { | 272 offset)).then((result) { |
248 if (result.isEmpty) { | 273 if (result.isEmpty) { |
249 return null; | 274 return null; |
250 } else { | 275 } else { |
251 return new HierarchyResults(result); | 276 return new HierarchyResults(result); |
252 } | 277 } |
253 }); | 278 }); |
254 } | 279 } |
255 } | 280 } |
256 | 281 |
257 main() { | 282 main() { |
258 runReflectiveTests(SearchDomainIntegrationTest); | 283 runReflectiveTests(SearchDomainIntegrationTest); |
259 } | 284 } |
OLD | NEW |