| 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_internal; | 5 library test.services.src.search.search_engine_internal; |
| 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/search/search_engine.dart'; | 10 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 11 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 11 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 12 import 'package:analyzer/dart/element/element.dart'; | 12 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/src/dart/analysis/ast_provider_context.dart'; |
| 13 import 'package:analyzer/src/dart/element/element.dart'; | 14 import 'package:analyzer/src/dart/element/element.dart'; |
| 14 import 'package:analyzer/src/dart/element/member.dart'; | 15 import 'package:analyzer/src/dart/element/member.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:test/test.dart'; | 17 import 'package:test/test.dart'; |
| 17 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 18 | 19 |
| 19 import '../../abstract_single_unit.dart'; | 20 import '../../abstract_single_unit.dart'; |
| 20 | 21 |
| 21 main() { | 22 main() { |
| 22 defineReflectiveSuite(() { | 23 defineReflectiveSuite(() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 65 } |
| 65 | 66 |
| 66 @reflectiveTest | 67 @reflectiveTest |
| 67 class SearchEngineImplTest extends AbstractSingleUnitTest { | 68 class SearchEngineImplTest extends AbstractSingleUnitTest { |
| 68 Index index; | 69 Index index; |
| 69 SearchEngineImpl searchEngine; | 70 SearchEngineImpl searchEngine; |
| 70 | 71 |
| 71 void setUp() { | 72 void setUp() { |
| 72 super.setUp(); | 73 super.setUp(); |
| 73 index = createMemoryIndex(); | 74 index = createMemoryIndex(); |
| 74 searchEngine = new SearchEngineImpl(index); | 75 searchEngine = |
| 76 new SearchEngineImpl(index, (_) => new AstProviderForContext(context)); |
| 75 } | 77 } |
| 76 | 78 |
| 77 test_searchAllSubtypes() async { | 79 test_searchAllSubtypes() async { |
| 78 await _indexTestUnit(''' | 80 await _indexTestUnit(''' |
| 79 class T {} | 81 class T {} |
| 80 class A extends T {} | 82 class A extends T {} |
| 81 class B extends A {} | 83 class B extends A {} |
| 82 class C implements B {} | 84 class C implements B {} |
| 83 '''); | 85 '''); |
| 84 ClassElement element = findElement('T'); | 86 ClassElement element = findElement('T'); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 var expected = [ | 503 var expected = [ |
| 502 _expectId(mainElement, MatchKind.REFERENCE, 'label; // 1'), | 504 _expectId(mainElement, MatchKind.REFERENCE, 'label; // 1'), |
| 503 _expectId(mainElement, MatchKind.REFERENCE, 'label; // 2') | 505 _expectId(mainElement, MatchKind.REFERENCE, 'label; // 2') |
| 504 ]; | 506 ]; |
| 505 await _verifyReferences(element, expected); | 507 await _verifyReferences(element, expected); |
| 506 } | 508 } |
| 507 | 509 |
| 508 test_searchReferences_LibraryElement() async { | 510 test_searchReferences_LibraryElement() async { |
| 509 var codeA = 'part of lib; // A'; | 511 var codeA = 'part of lib; // A'; |
| 510 var codeB = 'part of lib; // B'; | 512 var codeB = 'part of lib; // B'; |
| 511 addSource('/unitA.dart', codeA); | 513 var sourceA = addSource('/unitA.dart', codeA); |
| 512 addSource('/unitB.dart', codeB); | 514 var sourceB = addSource('/unitB.dart', codeB); |
| 513 await _indexTestUnit(''' | 515 await _indexTestUnit(''' |
| 514 library lib; | 516 library lib; |
| 515 part 'unitA.dart'; | 517 part 'unitA.dart'; |
| 516 part 'unitB.dart'; | 518 part 'unitB.dart'; |
| 517 '''); | 519 '''); |
| 518 LibraryElement element = testLibraryElement; | 520 LibraryElement element = testLibraryElement; |
| 519 CompilationUnitElement unitElementA = element.parts[0]; | 521 CompilationUnitElement unitElementA = element.parts[0]; |
| 520 CompilationUnitElement unitElementB = element.parts[1]; | 522 CompilationUnitElement unitElementB = element.parts[1]; |
| 521 index.indexUnit(unitElementA.computeNode()); | 523 index.indexUnit( |
| 522 index.indexUnit(unitElementB.computeNode()); | 524 context.resolveCompilationUnit2(sourceA, testLibraryElement.source)); |
| 525 index.indexUnit( |
| 526 context.resolveCompilationUnit2(sourceB, testLibraryElement.source)); |
| 523 var expected = [ | 527 var expected = [ |
| 524 new ExpectedMatch(unitElementA, MatchKind.REFERENCE, | 528 new ExpectedMatch(unitElementA, MatchKind.REFERENCE, |
| 525 codeA.indexOf('lib; // A'), 'lib'.length), | 529 codeA.indexOf('lib; // A'), 'lib'.length), |
| 526 new ExpectedMatch(unitElementB, MatchKind.REFERENCE, | 530 new ExpectedMatch(unitElementB, MatchKind.REFERENCE, |
| 527 codeB.indexOf('lib; // B'), 'lib'.length), | 531 codeB.indexOf('lib; // B'), 'lib'.length), |
| 528 ]; | 532 ]; |
| 529 await _verifyReferences(element, expected); | 533 await _verifyReferences(element, expected); |
| 530 } | 534 } |
| 531 | 535 |
| 532 test_searchReferences_LocalVariableElement() async { | 536 test_searchReferences_LocalVariableElement() async { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 List<SearchMatch> matches = await searchEngine.searchReferences(element); | 944 List<SearchMatch> matches = await searchEngine.searchReferences(element); |
| 941 _assertMatches(matches, expectedMatches); | 945 _assertMatches(matches, expectedMatches); |
| 942 expect(matches, hasLength(expectedMatches.length)); | 946 expect(matches, hasLength(expectedMatches.length)); |
| 943 } | 947 } |
| 944 | 948 |
| 945 static void _assertMatches( | 949 static void _assertMatches( |
| 946 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { | 950 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { |
| 947 expect(matches, unorderedEquals(expectedMatches)); | 951 expect(matches, unorderedEquals(expectedMatches)); |
| 948 } | 952 } |
| 949 } | 953 } |
| OLD | NEW |