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.search.element_references; | 5 library test.search.element_references; |
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:analysis_server/src/services/index/index.dart'; | 10 import 'package:analysis_server/src/services/index/index.dart'; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 '''); | 215 '''); |
216 await findElementReferences('fff); // in constructor', false); | 216 await findElementReferences('fff); // in constructor', false); |
217 expect(searchElement.kind, ElementKind.FIELD); | 217 expect(searchElement.kind, ElementKind.FIELD); |
218 expect(results, hasLength(4)); | 218 expect(results, hasLength(4)); |
219 assertHasResult(SearchResultKind.DECLARATION, 'fff; // declaration'); | 219 assertHasResult(SearchResultKind.DECLARATION, 'fff; // declaration'); |
220 assertHasResult(SearchResultKind.WRITE, 'fff); // in constructor'); | 220 assertHasResult(SearchResultKind.WRITE, 'fff); // in constructor'); |
221 assertHasResult(SearchResultKind.WRITE, 'fff = 2;'); | 221 assertHasResult(SearchResultKind.WRITE, 'fff = 2;'); |
222 assertHasResult(SearchResultKind.READ, 'fff); // in m()'); | 222 assertHasResult(SearchResultKind.READ, 'fff); // in m()'); |
223 } | 223 } |
224 | 224 |
| 225 test_file_libraryUnit_atImportDirective() async { |
| 226 String fileLib = '$testFolder/my_lib.dart'; |
| 227 String fileUser = '$testFolder/userA.dart'; |
| 228 String codeUser = "import 'my_lib.dart'; // U"; |
| 229 addFile(fileLib, 'library my.lib;'); |
| 230 addFile(fileUser, codeUser); |
| 231 addTestFile(''' |
| 232 import 'my_lib.dart'; // T |
| 233 '''); |
| 234 await findElementReferences('import ', false); |
| 235 expect(searchElement.kind, ElementKind.FILE); |
| 236 expect(results, hasLength(2)); |
| 237 // in U |
| 238 { |
| 239 SearchResult result = results.singleWhere((result) { |
| 240 return result.location.file == fileUser; |
| 241 }); |
| 242 expect(result.location.offset, codeUser.indexOf("'my_lib.dart'; // U")); |
| 243 expect(result.location.length, "'my_lib.dart'".length); |
| 244 } |
| 245 // in T |
| 246 { |
| 247 SearchResult result = results.singleWhere((result) { |
| 248 return result.location.file == testFile; |
| 249 }); |
| 250 expect(result.location.offset, testCode.indexOf("'my_lib.dart'; // T")); |
| 251 expect(result.location.length, "'my_lib.dart'".length); |
| 252 } |
| 253 } |
| 254 |
| 255 test_file_libraryUnit_atImportDirectiveUri() async { |
| 256 String fileLib = '$testFolder/my_lib.dart'; |
| 257 String fileA = '$testFolder/userA.dart'; |
| 258 String fileB = '$testFolder/userB.dart'; |
| 259 String codeA = "import 'my_lib.dart'; // A"; |
| 260 String codeB = "export 'my_lib.dart'; // B"; |
| 261 addFile(fileLib, 'library my.lib;'); |
| 262 addFile(fileA, codeA); |
| 263 addFile(fileB, codeB); |
| 264 addTestFile(''' |
| 265 import 'my_lib.dart'; // T |
| 266 '''); |
| 267 await findElementReferences('my_', false); |
| 268 expect(searchElement.kind, ElementKind.FILE); |
| 269 expect(results, hasLength(3)); |
| 270 // in A |
| 271 { |
| 272 SearchResult result = results.singleWhere((result) { |
| 273 return result.location.file == fileA; |
| 274 }); |
| 275 expect(result.location.offset, codeA.indexOf("'my_lib.dart'; // A")); |
| 276 expect(result.location.length, "'my_lib.dart'".length); |
| 277 } |
| 278 // in B |
| 279 { |
| 280 SearchResult result = results.singleWhere((result) { |
| 281 return result.location.file == fileB; |
| 282 }); |
| 283 expect(result.location.offset, codeB.indexOf("'my_lib.dart'; // B")); |
| 284 expect(result.location.length, "'my_lib.dart'".length); |
| 285 } |
| 286 // in T |
| 287 { |
| 288 SearchResult result = results.singleWhere((result) { |
| 289 return result.location.file == testFile; |
| 290 }); |
| 291 expect(result.location.offset, testCode.indexOf("'my_lib.dart'; // T")); |
| 292 expect(result.location.length, "'my_lib.dart'".length); |
| 293 } |
| 294 } |
| 295 |
| 296 test_file_libraryUnit_atLibraryDirectiveIdentifier() async { |
| 297 String fileA = '$testFolder/userA.dart'; |
| 298 String fileB = '$testFolder/userB.dart'; |
| 299 String codeA = "import 'test.dart'; // A"; |
| 300 String codeB = "export 'test.dart'; // B"; |
| 301 addFile(fileA, codeA); |
| 302 addFile(fileB, codeB); |
| 303 addTestFile(''' |
| 304 library my.test.lib; |
| 305 '''); |
| 306 await findElementReferences('test.', false); |
| 307 expect(searchElement.kind, ElementKind.LIBRARY); |
| 308 expect(results, hasLength(2)); |
| 309 // in A |
| 310 { |
| 311 SearchResult result = results.singleWhere((result) { |
| 312 return result.location.file == fileA; |
| 313 }); |
| 314 expect(result.location.offset, codeA.indexOf("'test.dart'; // A")); |
| 315 expect(result.location.length, "'test.dart'".length); |
| 316 } |
| 317 // in B |
| 318 { |
| 319 SearchResult result = results.singleWhere((result) { |
| 320 return result.location.file == fileB; |
| 321 }); |
| 322 expect(result.location.offset, codeB.indexOf("'test.dart'; // B")); |
| 323 expect(result.location.length, "'test.dart'".length); |
| 324 } |
| 325 } |
| 326 |
| 327 test_file_partUnit_atPartDirective() async { |
| 328 String filePart = '$testFolder/my_part.dart'; |
| 329 String fileOther = '$testFolder/userOther.dart'; |
| 330 String codeOther = ''' |
| 331 library lib; |
| 332 part 'my_part.dart'; // O |
| 333 '''; |
| 334 addFile(filePart, 'part of lib;'); |
| 335 addFile(fileOther, codeOther); |
| 336 addTestFile(''' |
| 337 library lib; |
| 338 part 'my_part.dart'; // T |
| 339 '''); |
| 340 await findElementReferences('part ', false); |
| 341 expect(searchElement.kind, ElementKind.FILE); |
| 342 expect(searchElement.name, filePart); |
| 343 expect(results, hasLength(2)); |
| 344 // in O |
| 345 { |
| 346 SearchResult result = results.singleWhere((result) { |
| 347 return result.location.file == fileOther; |
| 348 }); |
| 349 expect(result.location.offset, codeOther.indexOf("'my_part.dart'; // O")); |
| 350 expect(result.location.length, "'my_part.dart'".length); |
| 351 } |
| 352 // in T |
| 353 { |
| 354 SearchResult result = results.singleWhere((result) { |
| 355 return result.location.file == testFile; |
| 356 }); |
| 357 expect(result.location.offset, testCode.indexOf("'my_part.dart'; // T")); |
| 358 expect(result.location.length, "'my_part.dart'".length); |
| 359 } |
| 360 } |
| 361 |
| 362 test_file_partUnit_atPartDirectiveUri() async { |
| 363 String filePart = '$testFolder/my_part.dart'; |
| 364 String fileOther = '$testFolder/userOther.dart'; |
| 365 String codeOther = ''' |
| 366 library lib; |
| 367 part 'my_part.dart'; // O |
| 368 '''; |
| 369 addFile(filePart, 'part of lib;'); |
| 370 addFile(fileOther, codeOther); |
| 371 addTestFile(''' |
| 372 library lib; |
| 373 part 'my_part.dart'; // T |
| 374 '''); |
| 375 await findElementReferences('my_', false); |
| 376 expect(searchElement.kind, ElementKind.FILE); |
| 377 expect(searchElement.name, filePart); |
| 378 expect(results, hasLength(2)); |
| 379 // in O |
| 380 { |
| 381 SearchResult result = results.singleWhere((result) { |
| 382 return result.location.file == fileOther; |
| 383 }); |
| 384 expect(result.location.offset, codeOther.indexOf("'my_part.dart'; // O")); |
| 385 expect(result.location.length, "'my_part.dart'".length); |
| 386 } |
| 387 // in T |
| 388 { |
| 389 SearchResult result = results.singleWhere((result) { |
| 390 return result.location.file == testFile; |
| 391 }); |
| 392 expect(result.location.offset, testCode.indexOf("'my_part.dart'; // T")); |
| 393 expect(result.location.length, "'my_part.dart'".length); |
| 394 } |
| 395 } |
| 396 |
225 test_function() async { | 397 test_function() async { |
226 addTestFile(''' | 398 addTestFile(''' |
227 fff(p) {} | 399 fff(p) {} |
228 main() { | 400 main() { |
229 fff(1); | 401 fff(1); |
230 print(fff); | 402 print(fff); |
231 } | 403 } |
232 '''); | 404 '''); |
233 await findElementReferences('fff(p) {}', false); | 405 await findElementReferences('fff(p) {}', false); |
234 expect(searchElement.kind, ElementKind.FUNCTION); | 406 expect(searchElement.kind, ElementKind.FUNCTION); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 A a = null; | 645 A a = null; |
474 } | 646 } |
475 } | 647 } |
476 '''); | 648 '''); |
477 await findElementReferences('A {}', false); | 649 await findElementReferences('A {}', false); |
478 assertHasResult(SearchResultKind.REFERENCE, 'A a = null;'); | 650 assertHasResult(SearchResultKind.REFERENCE, 'A a = null;'); |
479 expect( | 651 expect( |
480 getPathString(result.path), | 652 getPathString(result.path), |
481 ''' | 653 ''' |
482 LOCAL_VARIABLE a | 654 LOCAL_VARIABLE a |
483 CONSTRUCTOR | 655 CONSTRUCTOR |
484 CLASS B | 656 CLASS B |
485 COMPILATION_UNIT test.dart | 657 COMPILATION_UNIT test.dart |
486 LIBRARY my_lib'''); | 658 LIBRARY my_lib'''); |
487 } | 659 } |
488 | 660 |
489 test_path_inFunction() async { | 661 test_path_inFunction() async { |
490 addTestFile(''' | 662 addTestFile(''' |
491 library my_lib; | 663 library my_lib; |
492 class A {} | 664 class A {} |
493 main() { | 665 main() { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 await findElementReferences("ppp;", false); | 773 await findElementReferences("ppp;", false); |
602 expect(searchElement.kind, ElementKind.PREFIX); | 774 expect(searchElement.kind, ElementKind.PREFIX); |
603 expect(searchElement.name, 'ppp'); | 775 expect(searchElement.name, 'ppp'); |
604 expect(searchElement.location.startLine, 1); | 776 expect(searchElement.location.startLine, 1); |
605 expect(results, hasLength(3)); | 777 expect(results, hasLength(3)); |
606 assertHasResult(SearchResultKind.DECLARATION, 'ppp;'); | 778 assertHasResult(SearchResultKind.DECLARATION, 'ppp;'); |
607 assertHasResult(SearchResultKind.REFERENCE, 'ppp.Future'); | 779 assertHasResult(SearchResultKind.REFERENCE, 'ppp.Future'); |
608 assertHasResult(SearchResultKind.REFERENCE, 'ppp.Stream'); | 780 assertHasResult(SearchResultKind.REFERENCE, 'ppp.Stream'); |
609 } | 781 } |
610 | 782 |
611 test_prefix_null() async { | |
612 addTestFile(''' | |
613 import 'dart:async'; | |
614 main() { | |
615 Future a; | |
616 Stream b; | |
617 } | |
618 '''); | |
619 await findElementReferences("import ", false); | |
620 expect(searchElement, isNull); | |
621 } | |
622 | |
623 test_topLevelVariable_explicit() async { | 783 test_topLevelVariable_explicit() async { |
624 addTestFile(''' | 784 addTestFile(''' |
625 var vvv = 1; | 785 var vvv = 1; |
626 main() { | 786 main() { |
627 print(vvv); | 787 print(vvv); |
628 vvv += 3; | 788 vvv += 3; |
629 vvv = 2; | 789 vvv = 2; |
630 vvv(); | 790 vvv(); |
631 } | 791 } |
632 '''); | 792 '''); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 print(vvv); | 878 print(vvv); |
719 } | 879 } |
720 '''); | 880 '''); |
721 Request request = new SearchFindElementReferencesParams(testFile, 0, false) | 881 Request request = new SearchFindElementReferencesParams(testFile, 0, false) |
722 .toRequest('0'); | 882 .toRequest('0'); |
723 Response response = await waitResponse(request); | 883 Response response = await waitResponse(request); |
724 expect(response.error, isNotNull); | 884 expect(response.error, isNotNull); |
725 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); | 885 expect(response.error.code, RequestErrorCode.NO_INDEX_GENERATED); |
726 } | 886 } |
727 } | 887 } |
OLD | NEW |