| 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 24 matching lines...) Expand all Loading... |
| 35 return hovers.isNotEmpty ? hovers.first : null; | 35 return hovers.isNotEmpty ? hovers.first : null; |
| 36 }); | 36 }); |
| 37 } | 37 } |
| 38 | 38 |
| 39 @override | 39 @override |
| 40 void setUp() { | 40 void setUp() { |
| 41 super.setUp(); | 41 super.setUp(); |
| 42 createProject(); | 42 createProject(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 test_dartdoc_clunky() { | 45 test_dartdoc_clunky() async { |
| 46 addTestFile(''' | 46 addTestFile(''' |
| 47 library my.library; | 47 library my.library; |
| 48 /** | 48 /** |
| 49 * doc aaa | 49 * doc aaa |
| 50 * doc bbb | 50 * doc bbb |
| 51 */ | 51 */ |
| 52 main() { | 52 main() { |
| 53 } | 53 } |
| 54 '''); | 54 '''); |
| 55 return prepareHover('main() {').then((HoverInformation hover) { | 55 HoverInformation hover = await prepareHover('main() {'); |
| 56 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | 56 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); |
| 57 }); | |
| 58 } | 57 } |
| 59 | 58 |
| 60 test_dartdoc_elegant() { | 59 test_dartdoc_elegant() async { |
| 61 addTestFile(''' | 60 addTestFile(''' |
| 62 library my.library; | 61 library my.library; |
| 63 /// doc aaa | 62 /// doc aaa |
| 64 /// doc bbb | 63 /// doc bbb |
| 65 main() { | 64 main() { |
| 66 } | 65 } |
| 67 '''); | 66 '''); |
| 68 return prepareHover('main() {').then((HoverInformation hover) { | 67 HoverInformation hover = await prepareHover('main() {'); |
| 69 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | 68 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); |
| 70 }); | |
| 71 } | 69 } |
| 72 | 70 |
| 73 test_expression_function() { | 71 test_expression_function() async { |
| 74 addTestFile(''' | 72 addTestFile(''' |
| 75 library my.library; | 73 library my.library; |
| 76 /// doc aaa | 74 /// doc aaa |
| 77 /// doc bbb | 75 /// doc bbb |
| 78 List<String> fff(int a, String b) { | 76 List<String> fff(int a, String b) { |
| 79 } | 77 } |
| 80 '''); | 78 '''); |
| 81 return prepareHover('fff(int a').then((HoverInformation hover) { | 79 HoverInformation hover = await prepareHover('fff(int a'); |
| 82 // element | 80 // element |
| 83 expect(hover.containingLibraryName, 'my.library'); | 81 expect(hover.containingLibraryName, 'my.library'); |
| 84 expect(hover.containingLibraryPath, testFile); | 82 expect(hover.containingLibraryPath, testFile); |
| 85 expect(hover.containingClassDescription, isNull); | 83 expect(hover.containingClassDescription, isNull); |
| 86 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | 84 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); |
| 87 expect(hover.elementDescription, 'fff(int a, String b) → List<String>'); | 85 expect(hover.elementDescription, 'fff(int a, String b) → List<String>'); |
| 88 expect(hover.elementKind, 'function'); | 86 expect(hover.elementKind, 'function'); |
| 89 // types | 87 // types |
| 90 expect(hover.staticType, '(int, String) → List<String>'); | 88 expect(hover.staticType, '(int, String) → List<String>'); |
| 91 expect(hover.propagatedType, isNull); | 89 expect(hover.propagatedType, isNull); |
| 92 // no parameter | 90 // no parameter |
| 93 expect(hover.parameter, isNull); | 91 expect(hover.parameter, isNull); |
| 94 }); | |
| 95 } | 92 } |
| 96 | 93 |
| 97 test_expression_literal_noElement() { | 94 test_expression_literal_noElement() async { |
| 98 addTestFile(''' | 95 addTestFile(''' |
| 99 main() { | 96 main() { |
| 100 foo(123); | 97 foo(123); |
| 101 } | 98 } |
| 102 foo(Object myParameter) {} | 99 foo(Object myParameter) {} |
| 103 '''); | 100 '''); |
| 104 return prepareHover('123').then((HoverInformation hover) { | 101 HoverInformation hover = await prepareHover('123'); |
| 105 // literal, no Element | 102 // literal, no Element |
| 106 expect(hover.containingClassDescription, isNull); | 103 expect(hover.containingClassDescription, isNull); |
| 107 expect(hover.elementDescription, isNull); | 104 expect(hover.elementDescription, isNull); |
| 108 expect(hover.elementKind, isNull); | 105 expect(hover.elementKind, isNull); |
| 109 // types | 106 // types |
| 110 expect(hover.staticType, 'int'); | 107 expect(hover.staticType, 'int'); |
| 111 expect(hover.propagatedType, isNull); | 108 expect(hover.propagatedType, isNull); |
| 112 // parameter | 109 // parameter |
| 113 expect(hover.parameter, 'Object myParameter'); | 110 expect(hover.parameter, 'Object myParameter'); |
| 114 }); | |
| 115 } | 111 } |
| 116 | 112 |
| 117 test_expression_method() { | 113 test_expression_method() async { |
| 118 addTestFile(''' | 114 addTestFile(''' |
| 119 library my.library; | 115 library my.library; |
| 120 class A { | 116 class A { |
| 121 /// doc aaa | 117 /// doc aaa |
| 122 /// doc bbb | 118 /// doc bbb |
| 123 List<String> mmm(int a, String b) { | 119 List<String> mmm(int a, String b) { |
| 124 } | 120 } |
| 125 } | 121 } |
| 126 '''); | 122 '''); |
| 127 return prepareHover('mmm(int a').then((HoverInformation hover) { | 123 HoverInformation hover = await prepareHover('mmm(int a'); |
| 128 // element | 124 // element |
| 129 expect(hover.containingLibraryName, 'my.library'); | 125 expect(hover.containingLibraryName, 'my.library'); |
| 130 expect(hover.containingLibraryPath, testFile); | 126 expect(hover.containingLibraryPath, testFile); |
| 131 expect(hover.containingClassDescription, 'A'); | 127 expect(hover.containingClassDescription, 'A'); |
| 132 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | 128 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); |
| 133 expect(hover.elementDescription, 'mmm(int a, String b) → List<String>'); | 129 expect(hover.elementDescription, 'mmm(int a, String b) → List<String>'); |
| 134 expect(hover.elementKind, 'method'); | 130 expect(hover.elementKind, 'method'); |
| 135 // types | 131 // types |
| 136 expect(hover.staticType, '(int, String) → List<String>'); | 132 expect(hover.staticType, '(int, String) → List<String>'); |
| 137 expect(hover.propagatedType, isNull); | 133 expect(hover.propagatedType, isNull); |
| 138 // no parameter | 134 // no parameter |
| 139 expect(hover.parameter, isNull); | 135 expect(hover.parameter, isNull); |
| 140 }); | |
| 141 } | 136 } |
| 142 | 137 |
| 143 test_expression_method_invocation() { | 138 test_expression_method_invocation() async { |
| 144 addTestFile(''' | 139 addTestFile(''' |
| 145 library my.library; | 140 library my.library; |
| 146 class A { | 141 class A { |
| 147 List<String> mmm(int a, String b) { | 142 List<String> mmm(int a, String b) { |
| 148 } | 143 } |
| 149 } | 144 } |
| 150 main(A a) { | 145 main(A a) { |
| 151 a.mmm(42, 'foo'); | 146 a.mmm(42, 'foo'); |
| 152 } | 147 } |
| 153 '''); | 148 '''); |
| 154 return prepareHover('mm(42, ').then((HoverInformation hover) { | 149 HoverInformation hover = await prepareHover('mm(42, '); |
| 155 // range | 150 // range |
| 156 expect(hover.offset, findOffset('mmm(42, ')); | 151 expect(hover.offset, findOffset('mmm(42, ')); |
| 157 expect(hover.length, 'mmm'.length); | 152 expect(hover.length, 'mmm'.length); |
| 158 // element | 153 // element |
| 159 expect(hover.containingLibraryName, 'my.library'); | 154 expect(hover.containingLibraryName, 'my.library'); |
| 160 expect(hover.containingLibraryPath, testFile); | 155 expect(hover.containingLibraryPath, testFile); |
| 161 expect(hover.elementDescription, 'mmm(int a, String b) → List<String>'); | 156 expect(hover.elementDescription, 'mmm(int a, String b) → List<String>'); |
| 162 expect(hover.elementKind, 'method'); | 157 expect(hover.elementKind, 'method'); |
| 163 // types | 158 // types |
| 164 expect(hover.staticType, isNull); | 159 expect(hover.staticType, isNull); |
| 165 expect(hover.propagatedType, isNull); | 160 expect(hover.propagatedType, isNull); |
| 166 // no parameter | 161 // no parameter |
| 167 expect(hover.parameter, isNull); | 162 expect(hover.parameter, isNull); |
| 168 }); | |
| 169 } | 163 } |
| 170 | 164 |
| 171 test_expression_parameter() { | 165 test_expression_parameter() async { |
| 172 addTestFile(''' | 166 addTestFile(''' |
| 173 library my.library; | 167 library my.library; |
| 174 class A { | 168 class A { |
| 175 /// The method documentation. | 169 /// The method documentation. |
| 176 m(int p) { | 170 m(int p) { |
| 177 } | 171 } |
| 178 } | 172 } |
| 179 '''); | 173 '''); |
| 180 return prepareHover('p) {').then((HoverInformation hover) { | 174 HoverInformation hover = await prepareHover('p) {'); |
| 181 // element | 175 // element |
| 182 expect(hover.containingLibraryName, isNull); | 176 expect(hover.containingLibraryName, isNull); |
| 183 expect(hover.containingLibraryPath, isNull); | 177 expect(hover.containingLibraryPath, isNull); |
| 184 expect(hover.containingClassDescription, isNull); | 178 expect(hover.containingClassDescription, isNull); |
| 185 expect(hover.dartdoc, 'The method documentation.'); | 179 expect(hover.dartdoc, 'The method documentation.'); |
| 186 expect(hover.elementDescription, 'int p'); | 180 expect(hover.elementDescription, 'int p'); |
| 187 expect(hover.elementKind, 'parameter'); | 181 expect(hover.elementKind, 'parameter'); |
| 188 // types | 182 // types |
| 189 expect(hover.staticType, 'int'); | 183 expect(hover.staticType, 'int'); |
| 190 expect(hover.propagatedType, isNull); | 184 expect(hover.propagatedType, isNull); |
| 191 // no parameter | 185 // no parameter |
| 192 expect(hover.parameter, isNull); | 186 expect(hover.parameter, isNull); |
| 193 }); | |
| 194 } | 187 } |
| 195 | 188 |
| 196 test_expression_syntheticGetter() { | 189 test_expression_syntheticGetter() async { |
| 197 addTestFile(''' | 190 addTestFile(''' |
| 198 library my.library; | 191 library my.library; |
| 199 class A { | 192 class A { |
| 200 /// doc aaa | 193 /// doc aaa |
| 201 /// doc bbb | 194 /// doc bbb |
| 202 String fff; | 195 String fff; |
| 203 } | 196 } |
| 204 main(A a) { | 197 main(A a) { |
| 205 print(a.fff); | 198 print(a.fff); |
| 206 } | 199 } |
| 207 '''); | 200 '''); |
| 208 return prepareHover('fff);').then((HoverInformation hover) { | 201 HoverInformation hover = await prepareHover('fff);'); |
| 209 // element | 202 // element |
| 210 expect(hover.containingLibraryName, 'my.library'); | 203 expect(hover.containingLibraryName, 'my.library'); |
| 211 expect(hover.containingLibraryPath, testFile); | 204 expect(hover.containingLibraryPath, testFile); |
| 212 expect(hover.containingClassDescription, 'A'); | 205 expect(hover.containingClassDescription, 'A'); |
| 213 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); | 206 expect(hover.dartdoc, '''doc aaa\ndoc bbb'''); |
| 214 expect(hover.elementDescription, 'String fff'); | 207 expect(hover.elementDescription, 'String fff'); |
| 215 expect(hover.elementKind, 'field'); | 208 expect(hover.elementKind, 'field'); |
| 216 // types | 209 // types |
| 217 expect(hover.staticType, 'String'); | 210 expect(hover.staticType, 'String'); |
| 218 expect(hover.propagatedType, isNull); | 211 expect(hover.propagatedType, isNull); |
| 219 }); | |
| 220 } | 212 } |
| 221 | 213 |
| 222 test_expression_variable_hasPropagatedType() { | 214 test_expression_variable_hasPropagatedType() async { |
| 223 addTestFile(''' | 215 addTestFile(''' |
| 224 library my.library; | 216 library my.library; |
| 225 main() { | 217 main() { |
| 226 var vvv = 123; | 218 var vvv = 123; |
| 227 print(vvv); | 219 print(vvv); |
| 228 } | 220 } |
| 229 '''); | 221 '''); |
| 230 return prepareHover('vvv);').then((HoverInformation hover) { | 222 HoverInformation hover = await prepareHover('vvv);'); |
| 231 // element | 223 // element |
| 232 expect(hover.containingLibraryName, isNull); | 224 expect(hover.containingLibraryName, isNull); |
| 233 expect(hover.containingLibraryPath, isNull); | 225 expect(hover.containingLibraryPath, isNull); |
| 234 expect(hover.containingClassDescription, isNull); | 226 expect(hover.containingClassDescription, isNull); |
| 235 expect(hover.dartdoc, isNull); | 227 expect(hover.dartdoc, isNull); |
| 236 expect(hover.elementDescription, 'dynamic vvv'); | 228 expect(hover.elementDescription, 'dynamic vvv'); |
| 237 expect(hover.elementKind, 'local variable'); | 229 expect(hover.elementKind, 'local variable'); |
| 238 // types | 230 // types |
| 239 expect(hover.staticType, 'dynamic'); | 231 expect(hover.staticType, 'dynamic'); |
| 240 expect(hover.propagatedType, 'int'); | 232 expect(hover.propagatedType, 'int'); |
| 241 }); | |
| 242 } | 233 } |
| 243 | 234 |
| 244 test_expression_variable_inMethod() { | 235 test_expression_variable_inMethod() async { |
| 245 addTestFile(''' | 236 addTestFile(''' |
| 246 library my.library; | 237 library my.library; |
| 247 class A { | 238 class A { |
| 248 m() { | 239 m() { |
| 249 num vvv = 42; | 240 num vvv = 42; |
| 250 } | 241 } |
| 251 } | 242 } |
| 252 '''); | 243 '''); |
| 253 return prepareHover('vvv = 42').then((HoverInformation hover) { | 244 HoverInformation hover = await prepareHover('vvv = 42'); |
| 254 // element | 245 // element |
| 255 expect(hover.containingLibraryName, isNull); | 246 expect(hover.containingLibraryName, isNull); |
| 256 expect(hover.containingLibraryPath, isNull); | 247 expect(hover.containingLibraryPath, isNull); |
| 257 expect(hover.containingClassDescription, isNull); | 248 expect(hover.containingClassDescription, isNull); |
| 258 expect(hover.dartdoc, isNull); | 249 expect(hover.dartdoc, isNull); |
| 259 expect(hover.elementDescription, 'num vvv'); | 250 expect(hover.elementDescription, 'num vvv'); |
| 260 expect(hover.elementKind, 'local variable'); | 251 expect(hover.elementKind, 'local variable'); |
| 261 // types | 252 // types |
| 262 expect(hover.staticType, 'num'); | 253 expect(hover.staticType, 'num'); |
| 263 expect(hover.propagatedType, 'int'); | 254 expect(hover.propagatedType, 'int'); |
| 264 // no parameter | 255 // no parameter |
| 265 expect(hover.parameter, isNull); | 256 expect(hover.parameter, isNull); |
| 266 }); | |
| 267 } | 257 } |
| 268 | 258 |
| 269 test_instanceCreation_implicit() { | 259 test_instanceCreation_implicit() async { |
| 270 addTestFile(''' | 260 addTestFile(''' |
| 271 library my.library; | 261 library my.library; |
| 272 class A { | 262 class A { |
| 273 } | 263 } |
| 274 main() { | 264 main() { |
| 275 new A(); | 265 new A(); |
| 276 } | 266 } |
| 277 '''); | 267 '''); |
| 278 return prepareHover('new A').then((HoverInformation hover) { | 268 HoverInformation hover = await prepareHover('new A'); |
| 279 // range | 269 // range |
| 280 expect(hover.offset, findOffset('new A')); | 270 expect(hover.offset, findOffset('new A')); |
| 281 expect(hover.length, 'new A()'.length); | 271 expect(hover.length, 'new A()'.length); |
| 282 // element | 272 // element |
| 283 expect(hover.containingLibraryName, 'my.library'); | 273 expect(hover.containingLibraryName, 'my.library'); |
| 284 expect(hover.containingLibraryPath, testFile); | 274 expect(hover.containingLibraryPath, testFile); |
| 285 expect(hover.dartdoc, isNull); | 275 expect(hover.dartdoc, isNull); |
| 286 expect(hover.elementDescription, 'A() → A'); | 276 expect(hover.elementDescription, 'A() → A'); |
| 287 expect(hover.elementKind, 'constructor'); | 277 expect(hover.elementKind, 'constructor'); |
| 288 // types | 278 // types |
| 289 expect(hover.staticType, 'A'); | 279 expect(hover.staticType, 'A'); |
| 290 expect(hover.propagatedType, isNull); | 280 expect(hover.propagatedType, isNull); |
| 291 // no parameter | 281 // no parameter |
| 292 expect(hover.parameter, isNull); | 282 expect(hover.parameter, isNull); |
| 293 }); | |
| 294 } | 283 } |
| 295 | 284 |
| 296 test_instanceCreation_implicit_withTypeArgument() { | 285 test_instanceCreation_implicit_withTypeArgument() async { |
| 297 addTestFile(''' | 286 addTestFile(''' |
| 298 library my.library; | 287 library my.library; |
| 299 class A<T> {} | 288 class A<T> {} |
| 300 main() { | 289 main() { |
| 301 new A<String>(); | 290 new A<String>(); |
| 302 } | 291 } |
| 303 '''); | 292 '''); |
| 304 Function onConstructor = (HoverInformation hover) { | 293 void onConstructor(HoverInformation hover) { |
| 305 // range | 294 // range |
| 306 expect(hover.offset, findOffset('new A<String>')); | 295 expect(hover.offset, findOffset('new A<String>')); |
| 307 expect(hover.length, 'new A<String>()'.length); | 296 expect(hover.length, 'new A<String>()'.length); |
| 308 // element | 297 // element |
| 309 expect(hover.containingLibraryName, 'my.library'); | 298 expect(hover.containingLibraryName, 'my.library'); |
| 310 expect(hover.containingLibraryPath, testFile); | 299 expect(hover.containingLibraryPath, testFile); |
| 311 expect(hover.dartdoc, isNull); | 300 expect(hover.dartdoc, isNull); |
| 312 expect(hover.elementDescription, 'A() → A<String>'); | 301 expect(hover.elementDescription, 'A() → A<String>'); |
| 313 expect(hover.elementKind, 'constructor'); | 302 expect(hover.elementKind, 'constructor'); |
| 314 // types | 303 // types |
| 315 expect(hover.staticType, 'A<String>'); | 304 expect(hover.staticType, 'A<String>'); |
| 316 expect(hover.propagatedType, isNull); | 305 expect(hover.propagatedType, isNull); |
| 317 // no parameter | 306 // no parameter |
| 318 expect(hover.parameter, isNull); | 307 expect(hover.parameter, isNull); |
| 319 }; | 308 } |
| 320 var futureNewA = prepareHover('new A').then(onConstructor); | 309 { |
| 321 var futureA = prepareHover('A<String>()').then(onConstructor); | 310 HoverInformation hover = await prepareHover('new A'); |
| 322 var futureString = prepareHover('String>').then((HoverInformation hover) { | 311 onConstructor(hover); |
| 312 } |
| 313 { |
| 314 HoverInformation hover = await prepareHover('A<String>()'); |
| 315 onConstructor(hover); |
| 316 } |
| 317 { |
| 318 HoverInformation hover = await prepareHover('String>'); |
| 323 expect(hover.offset, findOffset('String>')); | 319 expect(hover.offset, findOffset('String>')); |
| 324 expect(hover.length, 'String'.length); | 320 expect(hover.length, 'String'.length); |
| 325 expect(hover.elementKind, 'class'); | 321 expect(hover.elementKind, 'class'); |
| 326 }); | 322 } |
| 327 return Future.wait([futureNewA, futureA, futureString]); | |
| 328 } | 323 } |
| 329 | 324 |
| 330 test_instanceCreation_named() { | 325 test_instanceCreation_named() async { |
| 331 addTestFile(''' | 326 addTestFile(''' |
| 332 library my.library; | 327 library my.library; |
| 333 class A { | 328 class A { |
| 334 /// my doc | 329 /// my doc |
| 335 A.named() {} | 330 A.named() {} |
| 336 } | 331 } |
| 337 main() { | 332 main() { |
| 338 new A.named(); | 333 new A.named(); |
| 339 } | 334 } |
| 340 '''); | 335 '''); |
| 341 var onConstructor = (HoverInformation hover) { | 336 void onConstructor(HoverInformation hover) { |
| 342 // range | 337 // range |
| 343 expect(hover.offset, findOffset('new A')); | 338 expect(hover.offset, findOffset('new A')); |
| 344 expect(hover.length, 'new A.named()'.length); | 339 expect(hover.length, 'new A.named()'.length); |
| 345 // element | 340 // element |
| 346 expect(hover.dartdoc, 'my doc'); | 341 expect(hover.dartdoc, 'my doc'); |
| 347 expect(hover.elementDescription, 'A.named() → A'); | 342 expect(hover.elementDescription, 'A.named() → A'); |
| 348 expect(hover.elementKind, 'constructor'); | 343 expect(hover.elementKind, 'constructor'); |
| 349 }; | 344 } |
| 350 var futureCreation = prepareHover('new A').then(onConstructor); | 345 { |
| 351 var futureName = prepareHover('named();').then(onConstructor); | 346 HoverInformation hover = await prepareHover('new A'); |
| 352 return Future.wait([futureCreation, futureName]); | 347 onConstructor(hover); |
| 348 } |
| 349 { |
| 350 HoverInformation hover = await prepareHover('named();'); |
| 351 onConstructor(hover); |
| 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 test_noHoverInfo() { | 355 test_noHoverInfo() { |
| 356 addTestFile(''' | 356 addTestFile(''' |
| 357 library my.library; | 357 library my.library; |
| 358 main() { | 358 main() { |
| 359 // nothing | 359 // nothing |
| 360 } | 360 } |
| 361 '''); | 361 '''); |
| 362 return prepareHover('nothing').then((HoverInformation hover) { | 362 return prepareHover('nothing').then((HoverInformation hover) { |
| 363 expect(hover, isNull); | 363 expect(hover, isNull); |
| 364 }); | 364 }); |
| 365 } | 365 } |
| 366 } | 366 } |
| OLD | NEW |