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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 addSource('/unitA.dart', codeA); | 350 addSource('/unitA.dart', codeA); |
351 addSource('/unitB.dart', codeB); | 351 addSource('/unitB.dart', codeB); |
352 _indexTestUnit(''' | 352 _indexTestUnit(''' |
353 library lib; | 353 library lib; |
354 part 'unitA.dart'; | 354 part 'unitA.dart'; |
355 part 'unitB.dart'; | 355 part 'unitB.dart'; |
356 '''); | 356 '''); |
357 LibraryElement element = testLibraryElement; | 357 LibraryElement element = testLibraryElement; |
358 CompilationUnitElement elementA = element.parts[0]; | 358 CompilationUnitElement elementA = element.parts[0]; |
359 CompilationUnitElement elementB = element.parts[1]; | 359 CompilationUnitElement elementB = element.parts[1]; |
360 index.indexUnit(context, elementA.computeNode()); | 360 index.index(context, elementA.computeNode()); |
361 index.indexUnit(context, elementB.computeNode()); | 361 index.index(context, elementB.computeNode()); |
362 var expected = [ | 362 var expected = [ |
363 new ExpectedMatch(elementA, MatchKind.REFERENCE, | 363 new ExpectedMatch(elementA, MatchKind.REFERENCE, |
364 codeA.indexOf('lib; // A'), 'lib'.length), | 364 codeA.indexOf('lib; // A'), 'lib'.length), |
365 new ExpectedMatch(elementB, MatchKind.REFERENCE, | 365 new ExpectedMatch(elementB, MatchKind.REFERENCE, |
366 codeB.indexOf('lib; // B'), 'lib'.length), | 366 codeB.indexOf('lib; // B'), 'lib'.length), |
367 ]; | 367 ]; |
368 return _verifyReferences(element, expected); | 368 return _verifyReferences(element, expected); |
369 } | 369 } |
370 | 370 |
371 Future test_searchReferences_LocalVariableElement() { | 371 Future test_searchReferences_LocalVariableElement() { |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 return _expectId(element, kind, search, isQualified: true); | 621 return _expectId(element, kind, search, isQualified: true); |
622 } | 622 } |
623 | 623 |
624 ExpectedMatch _expectIdU(Element element, MatchKind kind, String search) { | 624 ExpectedMatch _expectIdU(Element element, MatchKind kind, String search) { |
625 return _expectId(element, kind, search, | 625 return _expectId(element, kind, search, |
626 isQualified: true, isResolved: false); | 626 isQualified: true, isResolved: false); |
627 } | 627 } |
628 | 628 |
629 void _indexTestUnit(String code) { | 629 void _indexTestUnit(String code) { |
630 resolveTestUnit(code); | 630 resolveTestUnit(code); |
631 index.indexUnit(context, testUnit); | 631 index.index(context, testUnit); |
632 } | 632 } |
633 | 633 |
634 Future _verifyReferences( | 634 Future _verifyReferences( |
635 Element element, List<ExpectedMatch> expectedMatches) { | 635 Element element, List<ExpectedMatch> expectedMatches) { |
636 return searchEngine | 636 return searchEngine |
637 .searchReferences(element) | 637 .searchReferences(element) |
638 .then((List<SearchMatch> matches) { | 638 .then((List<SearchMatch> matches) { |
639 _assertMatches(matches, expectedMatches); | 639 _assertMatches(matches, expectedMatches); |
640 }); | 640 }); |
641 } | 641 } |
642 | 642 |
643 Future _verifyTopLevelDeclarations( | 643 Future _verifyTopLevelDeclarations( |
644 String pattern, List<ExpectedMatch> expectedMatches) { | 644 String pattern, List<ExpectedMatch> expectedMatches) { |
645 return searchEngine | 645 return searchEngine |
646 .searchTopLevelDeclarations(pattern) | 646 .searchTopLevelDeclarations(pattern) |
647 .then((List<SearchMatch> matches) { | 647 .then((List<SearchMatch> matches) { |
648 _assertMatches(matches, expectedMatches); | 648 _assertMatches(matches, expectedMatches); |
649 }); | 649 }); |
650 } | 650 } |
651 | 651 |
652 static void _assertMatches( | 652 static void _assertMatches( |
653 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { | 653 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { |
654 expect(matches, unorderedEquals(expectedMatches)); | 654 expect(matches, unorderedEquals(expectedMatches)); |
655 } | 655 } |
656 } | 656 } |
OLD | NEW |