| 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'; |
| 11 import 'package:analysis_server/src/services/search/search_engine.dart'; | 11 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 12 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 12 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 13 import 'package:analyzer/src/generated/element.dart'; | 13 import 'package:analyzer/src/generated/element.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 15 import 'package:typed_mock/typed_mock.dart'; | 16 import 'package:typed_mock/typed_mock.dart'; |
| 16 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
| 17 | 18 |
| 18 import '../../abstract_single_unit.dart'; | 19 import '../../abstract_single_unit.dart'; |
| 19 import '../../reflective_tests.dart'; | |
| 20 | 20 |
| 21 main() { | 21 main() { |
| 22 groupSep = ' | '; | 22 groupSep = ' | '; |
| 23 runReflectiveTests(SearchEngineImplTest); | 23 defineReflectiveTests(SearchEngineImplTest); |
| 24 } | 24 } |
| 25 | 25 |
| 26 class ExpectedMatch { | 26 class ExpectedMatch { |
| 27 final Element element; | 27 final Element element; |
| 28 final MatchKind kind; | 28 final MatchKind kind; |
| 29 SourceRange range; | 29 SourceRange range; |
| 30 final bool isResolved; | 30 final bool isResolved; |
| 31 final bool isQualified; | 31 final bool isQualified; |
| 32 | 32 |
| 33 ExpectedMatch(this.element, this.kind, int offset, int length, | 33 ExpectedMatch(this.element, this.kind, int offset, int length, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 _indexTestUnit(''' | 204 _indexTestUnit(''' |
| 205 class A { | 205 class A { |
| 206 A.named() {} | 206 A.named() {} |
| 207 } | 207 } |
| 208 main() { | 208 main() { |
| 209 new A.named(); | 209 new A.named(); |
| 210 } | 210 } |
| 211 '''); | 211 '''); |
| 212 ConstructorElement element = findElement('named'); | 212 ConstructorElement element = findElement('named'); |
| 213 Element mainElement = findElement('main'); | 213 Element mainElement = findElement('main'); |
| 214 var expected = [ | 214 var expected = |
| 215 _expectId(mainElement, MatchKind.REFERENCE, '.named();', length: 6) | 215 [_expectId(mainElement, MatchKind.REFERENCE, '.named();', length: 6)]; |
| 216 ]; | |
| 217 return _verifyReferences(element, expected); | 216 return _verifyReferences(element, expected); |
| 218 } | 217 } |
| 219 | 218 |
| 220 Future test_searchReferences_Element_unknown() { | 219 Future test_searchReferences_Element_unknown() { |
| 221 return _verifyReferences(DynamicElementImpl.instance, []); | 220 return _verifyReferences(DynamicElementImpl.instance, []); |
| 222 } | 221 } |
| 223 | 222 |
| 224 Future test_searchReferences_FieldElement() { | 223 Future test_searchReferences_FieldElement() { |
| 225 _indexTestUnit(''' | 224 _indexTestUnit(''' |
| 226 class A { | 225 class A { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 Future test_searchReferences_ImportElement_withPrefix() { | 306 Future test_searchReferences_ImportElement_withPrefix() { |
| 308 _indexTestUnit(''' | 307 _indexTestUnit(''' |
| 309 import 'dart:math' as math; | 308 import 'dart:math' as math; |
| 310 main() { | 309 main() { |
| 311 print(math.PI); | 310 print(math.PI); |
| 312 } | 311 } |
| 313 '''); | 312 '''); |
| 314 ImportElement element = testLibraryElement.imports[0]; | 313 ImportElement element = testLibraryElement.imports[0]; |
| 315 Element mainElement = findElement('main'); | 314 Element mainElement = findElement('main'); |
| 316 var kind = MatchKind.REFERENCE; | 315 var kind = MatchKind.REFERENCE; |
| 317 var expected = [ | 316 var expected = |
| 318 _expectId(mainElement, kind, 'math.PI);', length: 'math.'.length) | 317 [_expectId(mainElement, kind, 'math.PI);', length: 'math.'.length)]; |
| 319 ]; | |
| 320 return _verifyReferences(element, expected); | 318 return _verifyReferences(element, expected); |
| 321 } | 319 } |
| 322 | 320 |
| 323 Future test_searchReferences_LabelElement() { | 321 Future test_searchReferences_LabelElement() { |
| 324 _indexTestUnit(''' | 322 _indexTestUnit(''' |
| 325 main() { | 323 main() { |
| 326 label: | 324 label: |
| 327 while (true) { | 325 while (true) { |
| 328 if (true) { | 326 if (true) { |
| 329 break label; // 1 | 327 break label; // 1 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 _indexTestUnit(''' | 411 _indexTestUnit(''' |
| 414 class A<T> { | 412 class A<T> { |
| 415 T m() => null; | 413 T m() => null; |
| 416 } | 414 } |
| 417 main(A<int> a) { | 415 main(A<int> a) { |
| 418 a.m(); // ref | 416 a.m(); // ref |
| 419 } | 417 } |
| 420 '''); | 418 '''); |
| 421 MethodMember method = findNodeElementAtString('m(); // ref'); | 419 MethodMember method = findNodeElementAtString('m(); // ref'); |
| 422 Element mainElement = findElement('main'); | 420 Element mainElement = findElement('main'); |
| 423 var expected = [ | 421 var expected = |
| 424 _expectIdQ(mainElement, MatchKind.INVOCATION, 'm(); // ref') | 422 [_expectIdQ(mainElement, MatchKind.INVOCATION, 'm(); // ref')]; |
| 425 ]; | |
| 426 return _verifyReferences(method, expected); | 423 return _verifyReferences(method, expected); |
| 427 } | 424 } |
| 428 | 425 |
| 429 Future test_searchReferences_ParameterElement() { | 426 Future test_searchReferences_ParameterElement() { |
| 430 _indexTestUnit(''' | 427 _indexTestUnit(''' |
| 431 foo({p}) { | 428 foo({p}) { |
| 432 p = 1; | 429 p = 1; |
| 433 p += 2; | 430 p += 2; |
| 434 print(p); | 431 print(p); |
| 435 p(); | 432 p(); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 .then((List<SearchMatch> matches) { | 639 .then((List<SearchMatch> matches) { |
| 643 _assertMatches(matches, expectedMatches); | 640 _assertMatches(matches, expectedMatches); |
| 644 }); | 641 }); |
| 645 } | 642 } |
| 646 | 643 |
| 647 static void _assertMatches( | 644 static void _assertMatches( |
| 648 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { | 645 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { |
| 649 expect(matches, unorderedEquals(expectedMatches)); | 646 expect(matches, unorderedEquals(expectedMatches)); |
| 650 } | 647 } |
| 651 } | 648 } |
| OLD | NEW |