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.domain.analysis.hover; | 5 library test.domain.analysis.hover; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
(...skipping 23 matching lines...) Expand all Loading... |
34 List<HoverInformation> hovers = result.hovers; | 34 List<HoverInformation> hovers = result.hovers; |
35 return hovers.isNotEmpty ? hovers.first : null; | 35 return hovers.isNotEmpty ? hovers.first : null; |
36 } | 36 } |
37 | 37 |
38 @override | 38 @override |
39 void setUp() { | 39 void setUp() { |
40 super.setUp(); | 40 super.setUp(); |
41 createProject(); | 41 createProject(); |
42 } | 42 } |
43 | 43 |
| 44 test_class() async { |
| 45 addTestFile(''' |
| 46 class A<E> {} |
| 47 class I1<K, V> {} |
| 48 class I2<E> {} |
| 49 class M1 {} |
| 50 class M2<E> {} |
| 51 class B<T> extends A<T> with M1, M2<int> implements I1<int, String>, I2 {} |
| 52 '''); |
| 53 HoverInformation hover = await prepareHover('B<T>'); |
| 54 expect( |
| 55 hover.elementDescription, |
| 56 'class B<T> extends A<T> with M1, M2<int> ' |
| 57 'implements I1<int, String>, I2'); |
| 58 expect(hover.staticType, isNull); |
| 59 expect(hover.propagatedType, isNull); |
| 60 } |
| 61 |
| 62 test_class_abstract() async { |
| 63 addTestFile(''' |
| 64 class A {} |
| 65 abstract class B extends A {} |
| 66 '''); |
| 67 HoverInformation hover = await prepareHover('B extends'); |
| 68 expect(hover.elementDescription, 'abstract class B extends A'); |
| 69 expect(hover.staticType, isNull); |
| 70 expect(hover.propagatedType, isNull); |
| 71 } |
| 72 |
44 test_dartdoc_clunky() async { | 73 test_dartdoc_clunky() async { |
45 addTestFile(''' | 74 addTestFile(''' |
46 library my.library; | 75 library my.library; |
47 /** | 76 /** |
48 * doc aaa | 77 * doc aaa |
49 * doc bbb | 78 * doc bbb |
50 */ | 79 */ |
51 main() { | 80 main() { |
52 } | 81 } |
53 '''); | 82 '''); |
(...skipping 23 matching lines...) Expand all Loading... |
77 '''); | 106 '''); |
78 HoverInformation hover = await prepareHover('fff(int a'); | 107 HoverInformation hover = await prepareHover('fff(int a'); |
79 // element | 108 // element |
80 expect(hover.containingLibraryName, 'my.library'); | 109 expect(hover.containingLibraryName, 'my.library'); |
81 expect(hover.containingLibraryPath, testFile); | 110 expect(hover.containingLibraryPath, testFile); |
82 expect(hover.containingClassDescription, isNull); | 111 expect(hover.containingClassDescription, isNull); |
83 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | 112 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); |
84 expect(hover.elementDescription, 'fff(int a, String b) → List<String>'); | 113 expect(hover.elementDescription, 'fff(int a, String b) → List<String>'); |
85 expect(hover.elementKind, 'function'); | 114 expect(hover.elementKind, 'function'); |
86 // types | 115 // types |
87 expect(hover.staticType, '(int, String) → List<String>'); | 116 expect(hover.staticType, isNull); |
88 expect(hover.propagatedType, isNull); | 117 expect(hover.propagatedType, isNull); |
89 // no parameter | 118 // no parameter |
90 expect(hover.parameter, isNull); | 119 expect(hover.parameter, isNull); |
91 } | 120 } |
92 | 121 |
93 test_expression_literal_noElement() async { | 122 test_expression_literal_noElement() async { |
94 addTestFile(''' | 123 addTestFile(''' |
95 main() { | 124 main() { |
96 foo(123); | 125 foo(123); |
97 } | 126 } |
(...skipping 23 matching lines...) Expand all Loading... |
121 '''); | 150 '''); |
122 HoverInformation hover = await prepareHover('mmm(int a'); | 151 HoverInformation hover = await prepareHover('mmm(int a'); |
123 // element | 152 // element |
124 expect(hover.containingLibraryName, 'my.library'); | 153 expect(hover.containingLibraryName, 'my.library'); |
125 expect(hover.containingLibraryPath, testFile); | 154 expect(hover.containingLibraryPath, testFile); |
126 expect(hover.containingClassDescription, 'A'); | 155 expect(hover.containingClassDescription, 'A'); |
127 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | 156 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); |
128 expect(hover.elementDescription, 'mmm(int a, String b) → List<String>'); | 157 expect(hover.elementDescription, 'mmm(int a, String b) → List<String>'); |
129 expect(hover.elementKind, 'method'); | 158 expect(hover.elementKind, 'method'); |
130 // types | 159 // types |
131 expect(hover.staticType, '(int, String) → List<String>'); | 160 expect(hover.staticType, isNull); |
132 expect(hover.propagatedType, isNull); | 161 expect(hover.propagatedType, isNull); |
133 // no parameter | 162 // no parameter |
134 expect(hover.parameter, isNull); | 163 expect(hover.parameter, isNull); |
135 } | 164 } |
136 | 165 |
137 test_expression_method_invocation() async { | 166 test_expression_method_invocation() async { |
138 addTestFile(''' | 167 addTestFile(''' |
139 library my.library; | 168 library my.library; |
140 class A { | 169 class A { |
141 List<String> mmm(int a, String b) { | 170 List<String> mmm(int a, String b) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 expect(hover.dartdoc, 'The method documentation.'); | 207 expect(hover.dartdoc, 'The method documentation.'); |
179 expect(hover.elementDescription, 'int p'); | 208 expect(hover.elementDescription, 'int p'); |
180 expect(hover.elementKind, 'parameter'); | 209 expect(hover.elementKind, 'parameter'); |
181 // types | 210 // types |
182 expect(hover.staticType, 'int'); | 211 expect(hover.staticType, 'int'); |
183 expect(hover.propagatedType, isNull); | 212 expect(hover.propagatedType, isNull); |
184 // no parameter | 213 // no parameter |
185 expect(hover.parameter, isNull); | 214 expect(hover.parameter, isNull); |
186 } | 215 } |
187 | 216 |
188 test_expression_syntheticGetter() async { | 217 test_expression_syntheticGetter_invocation() async { |
189 addTestFile(''' | 218 addTestFile(''' |
190 library my.library; | 219 library my.library; |
191 class A { | 220 class A { |
192 /// doc aaa | 221 /// doc aaa |
193 /// doc bbb | 222 /// doc bbb |
194 String fff; | 223 String fff; |
195 } | 224 } |
196 main(A a) { | 225 main(A a) { |
197 print(a.fff); | 226 print(a.fff); |
198 } | 227 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 // range | 297 // range |
269 expect(hover.offset, findOffset('new A')); | 298 expect(hover.offset, findOffset('new A')); |
270 expect(hover.length, 'new A()'.length); | 299 expect(hover.length, 'new A()'.length); |
271 // element | 300 // element |
272 expect(hover.containingLibraryName, 'my.library'); | 301 expect(hover.containingLibraryName, 'my.library'); |
273 expect(hover.containingLibraryPath, testFile); | 302 expect(hover.containingLibraryPath, testFile); |
274 expect(hover.dartdoc, isNull); | 303 expect(hover.dartdoc, isNull); |
275 expect(hover.elementDescription, 'A() → A'); | 304 expect(hover.elementDescription, 'A() → A'); |
276 expect(hover.elementKind, 'constructor'); | 305 expect(hover.elementKind, 'constructor'); |
277 // types | 306 // types |
278 expect(hover.staticType, 'A'); | 307 expect(hover.staticType, isNull); |
279 expect(hover.propagatedType, isNull); | 308 expect(hover.propagatedType, isNull); |
280 // no parameter | 309 // no parameter |
281 expect(hover.parameter, isNull); | 310 expect(hover.parameter, isNull); |
282 } | 311 } |
283 | 312 |
284 test_instanceCreation_implicit_withTypeArgument() async { | 313 test_instanceCreation_implicit_withTypeArgument() async { |
285 addTestFile(''' | 314 addTestFile(''' |
286 library my.library; | 315 library my.library; |
287 class A<T> {} | 316 class A<T> {} |
288 main() { | 317 main() { |
289 new A<String>(); | 318 new A<String>(); |
290 } | 319 } |
291 '''); | 320 '''); |
292 void onConstructor(HoverInformation hover) { | 321 void onConstructor(HoverInformation hover) { |
293 // range | 322 // range |
294 expect(hover.offset, findOffset('new A<String>')); | 323 expect(hover.offset, findOffset('new A<String>')); |
295 expect(hover.length, 'new A<String>()'.length); | 324 expect(hover.length, 'new A<String>()'.length); |
296 // element | 325 // element |
297 expect(hover.containingLibraryName, 'my.library'); | 326 expect(hover.containingLibraryName, 'my.library'); |
298 expect(hover.containingLibraryPath, testFile); | 327 expect(hover.containingLibraryPath, testFile); |
299 expect(hover.dartdoc, isNull); | 328 expect(hover.dartdoc, isNull); |
300 expect(hover.elementDescription, 'A() → A<String>'); | 329 expect(hover.elementDescription, 'A() → A<String>'); |
301 expect(hover.elementKind, 'constructor'); | 330 expect(hover.elementKind, 'constructor'); |
302 // types | 331 // types |
303 expect(hover.staticType, 'A<String>'); | 332 expect(hover.staticType, isNull); |
304 expect(hover.propagatedType, isNull); | 333 expect(hover.propagatedType, isNull); |
305 // no parameter | 334 // no parameter |
306 expect(hover.parameter, isNull); | 335 expect(hover.parameter, isNull); |
307 } | 336 } |
308 { | 337 { |
309 HoverInformation hover = await prepareHover('new A'); | 338 HoverInformation hover = await prepareHover('new A'); |
310 onConstructor(hover); | 339 onConstructor(hover); |
311 } | 340 } |
312 { | 341 { |
313 HoverInformation hover = await prepareHover('A<String>()'); | 342 HoverInformation hover = await prepareHover('A<String>()'); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 addTestFile(''' | 384 addTestFile(''' |
356 library my.library; | 385 library my.library; |
357 main() { | 386 main() { |
358 // nothing | 387 // nothing |
359 } | 388 } |
360 '''); | 389 '''); |
361 HoverInformation hover = await prepareHover('nothing'); | 390 HoverInformation hover = await prepareHover('nothing'); |
362 expect(hover, isNull); | 391 expect(hover, isNull); |
363 } | 392 } |
364 } | 393 } |
OLD | NEW |