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.services.src.search.search_engine; | 5 library test.services.src.search.search_engine; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/src/services/index/index.dart'; | 9 import 'package:analysis_server/src/services/index/index.dart'; |
10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; | 10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 } | 360 } |
361 '''); | 361 '''); |
362 ImportElement element = testLibraryElement.imports[0]; | 362 ImportElement element = testLibraryElement.imports[0]; |
363 Element mainElement = findElement('main'); | 363 Element mainElement = findElement('main'); |
364 var kind = MatchKind.REFERENCE; | 364 var kind = MatchKind.REFERENCE; |
365 var expected = [ | 365 var expected = [ |
366 _expectId(mainElement, kind, 'math.PI);', length: 'math.'.length)]; | 366 _expectId(mainElement, kind, 'math.PI);', length: 'math.'.length)]; |
367 return _verifyReferences(element, expected); | 367 return _verifyReferences(element, expected); |
368 } | 368 } |
369 | 369 |
| 370 Future test_searchReferences_LabelElement() { |
| 371 _indexTestUnit(''' |
| 372 main() { |
| 373 label: |
| 374 while (true) { |
| 375 if (true) { |
| 376 break label; // 1 |
| 377 } |
| 378 break label; // 2 |
| 379 } |
| 380 } |
| 381 '''); |
| 382 LabelElement element = findElement('label'); |
| 383 Element mainElement = findElement('main'); |
| 384 var expected = [ |
| 385 _expectId(mainElement, MatchKind.REFERENCE, 'label; // 1'), |
| 386 _expectId(mainElement, MatchKind.REFERENCE, 'label; // 2')]; |
| 387 return _verifyReferences(element, expected); |
| 388 } |
| 389 |
370 Future test_searchReferences_LibraryElement() { | 390 Future test_searchReferences_LibraryElement() { |
371 var codeA = 'part of lib; // A'; | 391 var codeA = 'part of lib; // A'; |
372 var codeB = 'part of lib; // B'; | 392 var codeB = 'part of lib; // B'; |
373 addSource('/unitA.dart', codeA); | 393 addSource('/unitA.dart', codeA); |
374 addSource('/unitB.dart', codeB); | 394 addSource('/unitB.dart', codeB); |
375 _indexTestUnit(''' | 395 _indexTestUnit(''' |
376 library lib; | 396 library lib; |
377 part 'unitA.dart'; | 397 part 'unitA.dart'; |
378 part 'unitB.dart'; | 398 part 'unitB.dart'; |
379 '''); | 399 '''); |
(...skipping 29 matching lines...) Expand all Loading... |
409 LocalVariableElement element = findElement('v'); | 429 LocalVariableElement element = findElement('v'); |
410 Element mainElement = findElement('main'); | 430 Element mainElement = findElement('main'); |
411 var expected = [ | 431 var expected = [ |
412 _expectId(mainElement, MatchKind.WRITE, 'v = 1;'), | 432 _expectId(mainElement, MatchKind.WRITE, 'v = 1;'), |
413 _expectId(mainElement, MatchKind.READ_WRITE, 'v += 2;'), | 433 _expectId(mainElement, MatchKind.READ_WRITE, 'v += 2;'), |
414 _expectId(mainElement, MatchKind.READ, 'v);'), | 434 _expectId(mainElement, MatchKind.READ, 'v);'), |
415 _expectId(mainElement, MatchKind.INVOCATION, 'v();')]; | 435 _expectId(mainElement, MatchKind.INVOCATION, 'v();')]; |
416 return _verifyReferences(element, expected); | 436 return _verifyReferences(element, expected); |
417 } | 437 } |
418 | 438 |
419 Future test_searchReferences_LabelElement() { | |
420 _indexTestUnit(''' | |
421 main() { | |
422 label: | |
423 while (true) { | |
424 if (true) { | |
425 break label; // 1 | |
426 } | |
427 break label; // 2 | |
428 } | |
429 } | |
430 '''); | |
431 LabelElement element = findElement('label'); | |
432 Element mainElement = findElement('main'); | |
433 var expected = [ | |
434 _expectId(mainElement, MatchKind.REFERENCE, 'label; // 1'), | |
435 _expectId(mainElement, MatchKind.REFERENCE, 'label; // 2')]; | |
436 return _verifyReferences(element, expected); | |
437 } | |
438 | |
439 Future test_searchReferences_PrefixElement() { | |
440 _indexTestUnit(''' | |
441 import 'dart:async' as ppp; | |
442 main() { | |
443 ppp.Future a; | |
444 ppp.Stream b; | |
445 } | |
446 '''); | |
447 PrefixElement element = findNodeElementAtString('ppp;'); | |
448 Element elementA = findElement('a'); | |
449 Element elementB = findElement('b'); | |
450 var expected = [ | |
451 _expectId(elementA, MatchKind.REFERENCE, 'ppp.Future'), | |
452 _expectId(elementB, MatchKind.REFERENCE, 'ppp.Stream')]; | |
453 return _verifyReferences(element, expected); | |
454 } | |
455 | |
456 Future test_searchReferences_MethodElement() { | 439 Future test_searchReferences_MethodElement() { |
457 _indexTestUnit(''' | 440 _indexTestUnit(''' |
458 class A { | 441 class A { |
459 m() {} | 442 m() {} |
460 main() { | 443 main() { |
461 m(); // 1 | 444 m(); // 1 |
462 this.m(); // 2 | 445 this.m(); // 2 |
463 print(m); // 3 | 446 print(m); // 3 |
464 print(this.m); // 4 | 447 print(this.m); // 4 |
465 } | 448 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 Element mainElement = findElement('main'); | 491 Element mainElement = findElement('main'); |
509 var expected = [ | 492 var expected = [ |
510 _expectId(fooElement, MatchKind.WRITE, 'p = 1;'), | 493 _expectId(fooElement, MatchKind.WRITE, 'p = 1;'), |
511 _expectId(fooElement, MatchKind.READ_WRITE, 'p += 2;'), | 494 _expectId(fooElement, MatchKind.READ_WRITE, 'p += 2;'), |
512 _expectId(fooElement, MatchKind.READ, 'p);'), | 495 _expectId(fooElement, MatchKind.READ, 'p);'), |
513 _expectId(fooElement, MatchKind.INVOCATION, 'p();'), | 496 _expectId(fooElement, MatchKind.INVOCATION, 'p();'), |
514 _expectId(mainElement, MatchKind.REFERENCE, 'p: 42')]; | 497 _expectId(mainElement, MatchKind.REFERENCE, 'p: 42')]; |
515 return _verifyReferences(element, expected); | 498 return _verifyReferences(element, expected); |
516 } | 499 } |
517 | 500 |
| 501 Future test_searchReferences_PrefixElement() { |
| 502 _indexTestUnit(''' |
| 503 import 'dart:async' as ppp; |
| 504 main() { |
| 505 ppp.Future a; |
| 506 ppp.Stream b; |
| 507 } |
| 508 '''); |
| 509 PrefixElement element = findNodeElementAtString('ppp;'); |
| 510 Element elementA = findElement('a'); |
| 511 Element elementB = findElement('b'); |
| 512 var expected = [ |
| 513 _expectId(elementA, MatchKind.REFERENCE, 'ppp.Future'), |
| 514 _expectId(elementB, MatchKind.REFERENCE, 'ppp.Stream')]; |
| 515 return _verifyReferences(element, expected); |
| 516 } |
| 517 |
518 Future test_searchReferences_PropertyAccessorElement_getter() { | 518 Future test_searchReferences_PropertyAccessorElement_getter() { |
519 _indexTestUnit(''' | 519 _indexTestUnit(''' |
520 class A { | 520 class A { |
521 get g => null; | 521 get g => null; |
522 main() { | 522 main() { |
523 g; // 1 | 523 g; // 1 |
524 this.g; // 2 | 524 this.g; // 2 |
525 } | 525 } |
526 } | 526 } |
527 '''); | 527 '''); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 pattern).then((List<SearchMatch> matches) { | 689 pattern).then((List<SearchMatch> matches) { |
690 _assertMatches(matches, expectedMatches); | 690 _assertMatches(matches, expectedMatches); |
691 }); | 691 }); |
692 } | 692 } |
693 | 693 |
694 static void _assertMatches(List<SearchMatch> matches, | 694 static void _assertMatches(List<SearchMatch> matches, |
695 List<ExpectedMatch> expectedMatches) { | 695 List<ExpectedMatch> expectedMatches) { |
696 expect(matches, unorderedEquals(expectedMatches)); | 696 expect(matches, unorderedEquals(expectedMatches)); |
697 } | 697 } |
698 } | 698 } |
OLD | NEW |