| 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_engine2; | 5 library test.services.src.search.search_engine2; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/services/index2/index2.dart'; | 9 import 'package:analysis_server/src/services/index2/index2.dart'; |
| 10 import 'package:analysis_server/src/services/search/search_engine.dart'; | 10 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 _expectId(main, MatchKind.READ, 'field); // ref-nq'), | 250 _expectId(main, MatchKind.READ, 'field); // ref-nq'), |
| 251 _expectIdQ(main, MatchKind.READ, 'field); // ref-q'), | 251 _expectIdQ(main, MatchKind.READ, 'field); // ref-q'), |
| 252 _expectId(main, MatchKind.INVOCATION, 'field(); // inv-nq'), | 252 _expectId(main, MatchKind.INVOCATION, 'field(); // inv-nq'), |
| 253 _expectIdQ(main, MatchKind.INVOCATION, 'field(); // inv-q'), | 253 _expectIdQ(main, MatchKind.INVOCATION, 'field(); // inv-q'), |
| 254 _expectId(main, MatchKind.WRITE, 'field = 2; // ref-nq'), | 254 _expectId(main, MatchKind.WRITE, 'field = 2; // ref-nq'), |
| 255 _expectIdQ(main, MatchKind.WRITE, 'field = 3; // ref-q'), | 255 _expectIdQ(main, MatchKind.WRITE, 'field = 3; // ref-q'), |
| 256 ]; | 256 ]; |
| 257 await _verifyReferences(element, expected); | 257 await _verifyReferences(element, expected); |
| 258 } | 258 } |
| 259 | 259 |
| 260 test_searchReferences_FieldElement_synthetic() async { |
| 261 _indexTestUnit(''' |
| 262 class A { |
| 263 get field => null; |
| 264 set field(x) {} |
| 265 main() { |
| 266 // getter |
| 267 print(field); // ref-nq |
| 268 print(this.field); // ref-q |
| 269 field(); // inv-nq |
| 270 this.field(); // inv-q |
| 271 // setter |
| 272 field = 2; // ref-nq; |
| 273 this.field = 3; // ref-q; |
| 274 } |
| 275 } |
| 276 '''); |
| 277 FieldElement element = findElement('field', ElementKind.FIELD); |
| 278 Element main = findElement('main'); |
| 279 var expected = [ |
| 280 _expectId(main, MatchKind.READ, 'field); // ref-nq'), |
| 281 _expectIdQ(main, MatchKind.READ, 'field); // ref-q'), |
| 282 _expectId(main, MatchKind.INVOCATION, 'field(); // inv-nq'), |
| 283 _expectIdQ(main, MatchKind.INVOCATION, 'field(); // inv-q'), |
| 284 _expectId(main, MatchKind.WRITE, 'field = 2; // ref-nq'), |
| 285 _expectIdQ(main, MatchKind.WRITE, 'field = 3; // ref-q'), |
| 286 ]; |
| 287 await _verifyReferences(element, expected); |
| 288 } |
| 289 |
| 260 test_searchReferences_FunctionElement() async { | 290 test_searchReferences_FunctionElement() async { |
| 261 _indexTestUnit(''' | 291 _indexTestUnit(''' |
| 262 test() {} | 292 test() {} |
| 263 main() { | 293 main() { |
| 264 test(); | 294 test(); |
| 265 print(test); | 295 print(test); |
| 266 } | 296 } |
| 267 '''); | 297 '''); |
| 268 FunctionElement element = findElement('test'); | 298 FunctionElement element = findElement('test'); |
| 269 Element mainElement = findElement('main'); | 299 Element mainElement = findElement('main'); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 Element bElement = findElement('b'); | 334 Element bElement = findElement('b'); |
| 305 var expected = [ | 335 var expected = [ |
| 306 _expectId(aElement, MatchKind.REFERENCE, 'Test a;'), | 336 _expectId(aElement, MatchKind.REFERENCE, 'Test a;'), |
| 307 _expectId(bElement, MatchKind.REFERENCE, 'Test b;') | 337 _expectId(bElement, MatchKind.REFERENCE, 'Test b;') |
| 308 ]; | 338 ]; |
| 309 await _verifyReferences(element, expected); | 339 await _verifyReferences(element, expected); |
| 310 } | 340 } |
| 311 | 341 |
| 312 test_searchReferences_ImportElement_noPrefix() async { | 342 test_searchReferences_ImportElement_noPrefix() async { |
| 313 _indexTestUnit(''' | 343 _indexTestUnit(''' |
| 314 import 'dart:math'; | 344 import 'dart:math' show max, PI, Random; |
| 315 main() { | 345 main() { |
| 316 print(PI); | 346 print(PI); |
| 317 print(new Random()); | 347 print(new Random()); |
| 318 print(max(1, 2)); | 348 print(max(1, 2)); |
| 319 } | 349 } |
| 320 Random bar() => null; | 350 Random bar() => null; |
| 321 '''); | 351 '''); |
| 322 ImportElement element = testLibraryElement.imports[0]; | 352 ImportElement element = testLibraryElement.imports[0]; |
| 323 Element mainElement = findElement('main'); | 353 Element mainElement = findElement('main'); |
| 324 Element barElement = findElement('bar'); | 354 Element barElement = findElement('bar'); |
| 325 var kind = MatchKind.REFERENCE; | 355 var kind = MatchKind.REFERENCE; |
| 326 var expected = [ | 356 var expected = [ |
| 327 _expectId(mainElement, kind, 'PI);', length: 0), | 357 _expectId(mainElement, kind, 'PI);', length: 0), |
| 328 _expectId(mainElement, kind, 'Random()', length: 0), | 358 _expectId(mainElement, kind, 'Random()', length: 0), |
| 329 _expectId(mainElement, kind, 'max(', length: 0), | 359 _expectId(mainElement, kind, 'max(', length: 0), |
| 330 _expectId(barElement, kind, 'Random bar()', length: 0), | 360 _expectId(barElement, kind, 'Random bar()', length: 0), |
| 331 ]; | 361 ]; |
| 332 await _verifyReferences(element, expected); | 362 await _verifyReferences(element, expected); |
| 333 } | 363 } |
| 334 | 364 |
| 335 test_searchReferences_ImportElement_withPrefix() async { | 365 test_searchReferences_ImportElement_withPrefix() async { |
| 336 _indexTestUnit(''' | 366 _indexTestUnit(''' |
| 337 import 'dart:math' as math; | 367 import 'dart:math' as math show max, PI, Random; |
| 338 main() { | 368 main() { |
| 339 print(math.PI); | 369 print(math.PI); |
| 340 print(new math.Random()); | 370 print(new math.Random()); |
| 341 print(math.max(1, 2)); | 371 print(math.max(1, 2)); |
| 342 } | 372 } |
| 343 math.Random bar() => null; | 373 math.Random bar() => null; |
| 344 '''); | 374 '''); |
| 345 ImportElement element = testLibraryElement.imports[0]; | 375 ImportElement element = testLibraryElement.imports[0]; |
| 346 Element mainElement = findElement('main'); | 376 Element mainElement = findElement('main'); |
| 347 Element barElement = findElement('bar'); | 377 Element barElement = findElement('bar'); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 } | 735 } |
| 706 return new ExpectedMatch(element, kind, offset, length, | 736 return new ExpectedMatch(element, kind, offset, length, |
| 707 isResolved: isResolved, isQualified: isQualified); | 737 isResolved: isResolved, isQualified: isQualified); |
| 708 } | 738 } |
| 709 | 739 |
| 710 ExpectedMatch _expectIdQ(Element element, MatchKind kind, String search, | 740 ExpectedMatch _expectIdQ(Element element, MatchKind kind, String search, |
| 711 {int length}) { | 741 {int length}) { |
| 712 return _expectId(element, kind, search, isQualified: true, length: length); | 742 return _expectId(element, kind, search, isQualified: true, length: length); |
| 713 } | 743 } |
| 714 | 744 |
| 715 // ExpectedMatch _expectIdU(Element element, MatchKind kind, String search) { | |
| 716 // return _expectId(element, kind, search, | |
| 717 // isQualified: true, isResolved: false); | |
| 718 // } | |
| 719 | |
| 720 void _indexTestUnit(String code) { | 745 void _indexTestUnit(String code) { |
| 721 resolveTestUnit(code); | 746 resolveTestUnit(code); |
| 722 index.indexUnit(testUnit); | 747 index.indexUnit(testUnit); |
| 723 } | 748 } |
| 724 | 749 |
| 725 Future _verifyReferences( | 750 Future _verifyReferences( |
| 726 Element element, List<ExpectedMatch> expectedMatches) async { | 751 Element element, List<ExpectedMatch> expectedMatches) async { |
| 727 List<SearchMatch> matches = await searchEngine.searchReferences(element); | 752 List<SearchMatch> matches = await searchEngine.searchReferences(element); |
| 728 _assertMatches(matches, expectedMatches); | 753 _assertMatches(matches, expectedMatches); |
| 754 expect(matches, hasLength(expectedMatches.length)); |
| 729 } | 755 } |
| 730 | 756 |
| 731 static void _assertMatches( | 757 static void _assertMatches( |
| 732 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { | 758 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { |
| 733 expect(matches, unorderedEquals(expectedMatches)); | 759 expect(matches, unorderedEquals(expectedMatches)); |
| 734 } | 760 } |
| 735 } | 761 } |
| OLD | NEW |