Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(877)

Side by Side Diff: pkg/analysis_server/test/services/search/search_engine2_test.dart

Issue 1760243004: Implement search for local elements. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 '''); 285 ''');
286 FunctionElement element = findElement('test'); 286 FunctionElement element = findElement('test');
287 Element mainElement = findElement('main'); 287 Element mainElement = findElement('main');
288 var expected = [ 288 var expected = [
289 _expectId(mainElement, MatchKind.INVOCATION, 'test();'), 289 _expectId(mainElement, MatchKind.INVOCATION, 'test();'),
290 _expectId(mainElement, MatchKind.REFERENCE, 'test);') 290 _expectId(mainElement, MatchKind.REFERENCE, 'test);')
291 ]; 291 ];
292 await _verifyReferences(element, expected); 292 await _verifyReferences(element, expected);
293 } 293 }
294 294
295 test_searchReferences_FunctionElement_local() async {
296 _indexTestUnit('''
297 main() {
298 test() {}
299 test();
300 print(test);
301 }
302 ''');
303 FunctionElement element = findElement('test');
304 Element mainElement = findElement('main');
305 var expected = [
306 _expectId(mainElement, MatchKind.INVOCATION, 'test();'),
307 _expectId(mainElement, MatchKind.REFERENCE, 'test);')
308 ];
309 await _verifyReferences(element, expected);
310 }
311
295 test_searchReferences_FunctionTypeAliasElement() async { 312 test_searchReferences_FunctionTypeAliasElement() async {
296 _indexTestUnit(''' 313 _indexTestUnit('''
297 typedef Test(); 314 typedef Test();
298 main() { 315 main() {
299 Test a; 316 Test a;
300 Test b; 317 Test b;
301 } 318 }
302 '''); 319 ''');
303 FunctionTypeAliasElement element = findElement('Test'); 320 FunctionTypeAliasElement element = findElement('Test');
304 Element aElement = findElement('a'); 321 Element aElement = findElement('a');
(...skipping 27 matching lines...) Expand all
332 //} 349 //}
333 //'''); 350 //''');
334 // ImportElement element = testLibraryElement.imports[0]; 351 // ImportElement element = testLibraryElement.imports[0];
335 // Element mainElement = findElement('main'); 352 // Element mainElement = findElement('main');
336 // var kind = MatchKind.REFERENCE; 353 // var kind = MatchKind.REFERENCE;
337 // var expected = [ 354 // var expected = [
338 // _expectId(mainElement, kind, 'math.PI);', length: 'math.'.length) 355 // _expectId(mainElement, kind, 'math.PI);', length: 'math.'.length)
339 // ]; 356 // ];
340 // return _verifyReferences(element, expected); 357 // return _verifyReferences(element, expected);
341 // } 358 // }
342 // 359
343 // Future test_searchReferences_LabelElement() { 360 test_searchReferences_LabelElement() async {
344 // _indexTestUnit(''' 361 _indexTestUnit('''
345 //main() { 362 main() {
346 //label: 363 label:
347 // while (true) { 364 while (true) {
348 // if (true) { 365 if (true) {
349 // break label; // 1 366 break label; // 1
350 // } 367 }
351 // break label; // 2 368 break label; // 2
352 // } 369 }
353 //} 370 }
354 //'''); 371 ''');
355 // LabelElement element = findElement('label'); 372 LabelElement element = findElement('label');
356 // Element mainElement = findElement('main'); 373 Element mainElement = findElement('main');
357 // var expected = [ 374 var expected = [
358 // _expectId(mainElement, MatchKind.REFERENCE, 'label; // 1'), 375 _expectId(mainElement, MatchKind.REFERENCE, 'label; // 1'),
359 // _expectId(mainElement, MatchKind.REFERENCE, 'label; // 2') 376 _expectId(mainElement, MatchKind.REFERENCE, 'label; // 2')
360 // ]; 377 ];
361 // return _verifyReferences(element, expected); 378 await _verifyReferences(element, expected);
362 // } 379 }
363 // 380
364 // Future test_searchReferences_LibraryElement() { 381 // Future test_searchReferences_LibraryElement() {
365 // var codeA = 'part of lib; // A'; 382 // var codeA = 'part of lib; // A';
366 // var codeB = 'part of lib; // B'; 383 // var codeB = 'part of lib; // B';
367 // addSource('/unitA.dart', codeA); 384 // addSource('/unitA.dart', codeA);
368 // addSource('/unitB.dart', codeB); 385 // addSource('/unitB.dart', codeB);
369 // _indexTestUnit(''' 386 // _indexTestUnit('''
370 //library lib; 387 //library lib;
371 //part 'unitA.dart'; 388 //part 'unitA.dart';
372 //part 'unitB.dart'; 389 //part 'unitB.dart';
373 //'''); 390 //''');
374 // LibraryElement element = testLibraryElement; 391 // LibraryElement element = testLibraryElement;
375 // CompilationUnitElement elementA = element.parts[0]; 392 // CompilationUnitElement elementA = element.parts[0];
376 // CompilationUnitElement elementB = element.parts[1]; 393 // CompilationUnitElement elementB = element.parts[1];
377 // index.index(context, elementA.computeNode()); 394 // index.index(context, elementA.computeNode());
378 // index.index(context, elementB.computeNode()); 395 // index.index(context, elementB.computeNode());
379 // var expected = [ 396 // var expected = [
380 // new ExpectedMatch(elementA, MatchKind.REFERENCE, 397 // new ExpectedMatch(elementA, MatchKind.REFERENCE,
381 // codeA.indexOf('lib; // A'), 'lib'.length), 398 // codeA.indexOf('lib; // A'), 'lib'.length),
382 // new ExpectedMatch(elementB, MatchKind.REFERENCE, 399 // new ExpectedMatch(elementB, MatchKind.REFERENCE,
383 // codeB.indexOf('lib; // B'), 'lib'.length), 400 // codeB.indexOf('lib; // B'), 'lib'.length),
384 // ]; 401 // ];
385 // return _verifyReferences(element, expected); 402 // return _verifyReferences(element, expected);
386 // } 403 // }
387 //
388 // Future test_searchReferences_LocalVariableElement() {
389 // _indexTestUnit('''
390 //main() {
391 // var v;
392 // v = 1;
393 // v += 2;
394 // print(v);
395 // v();
396 //}
397 //''');
398 // LocalVariableElement element = findElement('v');
399 // Element mainElement = findElement('main');
400 // var expected = [
401 // _expectId(mainElement, MatchKind.WRITE, 'v = 1;'),
402 // _expectId(mainElement, MatchKind.READ_WRITE, 'v += 2;'),
403 // _expectId(mainElement, MatchKind.READ, 'v);'),
404 // _expectId(mainElement, MatchKind.INVOCATION, 'v();')
405 // ];
406 // return _verifyReferences(element, expected);
407 // }
408 404
405 test_searchReferences_LocalVariableElement() async {
406 _indexTestUnit('''
407 main() {
408 var v;
409 v = 1;
410 v += 2;
411 print(v);
412 v();
413 }
414 ''');
415 LocalVariableElement element = findElement('v');
416 Element mainElement = findElement('main');
417 var expected = [
418 _expectId(mainElement, MatchKind.WRITE, 'v = 1;'),
419 _expectId(mainElement, MatchKind.READ_WRITE, 'v += 2;'),
420 _expectId(mainElement, MatchKind.READ, 'v);'),
421 _expectId(mainElement, MatchKind.INVOCATION, 'v();')
422 ];
423 await _verifyReferences(element, expected);
424 }
425
409 test_searchReferences_MethodElement() async { 426 test_searchReferences_MethodElement() async {
410 _indexTestUnit(''' 427 _indexTestUnit('''
411 class A { 428 class A {
412 m() {} 429 m() {}
413 main() { 430 main() {
414 m(); // 1 431 m(); // 1
415 this.m(); // 2 432 this.m(); // 2
416 print(m); // 3 433 print(m); // 3
417 print(this.m); // 4 434 print(this.m); // 4
418 } 435 }
(...skipping 20 matching lines...) Expand all
439 } 456 }
440 '''); 457 ''');
441 MethodMember method = findNodeElementAtString('m(); // ref'); 458 MethodMember method = findNodeElementAtString('m(); // ref');
442 Element mainElement = findElement('main'); 459 Element mainElement = findElement('main');
443 var expected = [ 460 var expected = [
444 _expectIdQ(mainElement, MatchKind.INVOCATION, 'm(); // ref') 461 _expectIdQ(mainElement, MatchKind.INVOCATION, 'm(); // ref')
445 ]; 462 ];
446 await _verifyReferences(method, expected); 463 await _verifyReferences(method, expected);
447 } 464 }
448 465
449 // Future test_searchReferences_ParameterElement() { 466 test_searchReferences_ParameterElement() async {
450 // _indexTestUnit(''' 467 _indexTestUnit('''
451 //foo({p}) { 468 foo({p}) {
452 // p = 1; 469 p = 1;
453 // p += 2; 470 p += 2;
454 // print(p); 471 print(p);
455 // p(); 472 p();
456 //} 473 }
457 //main() { 474 main() {
458 // foo(p: 42); 475 foo(p: 42);
459 //} 476 }
460 //'''); 477 ''');
461 // ParameterElement element = findElement('p'); 478 ParameterElement element = findElement('p');
462 // Element fooElement = findElement('foo'); 479 Element fooElement = findElement('foo');
463 // Element mainElement = findElement('main'); 480 Element mainElement = findElement('main');
464 // var expected = [ 481 var expected = [
465 // _expectId(fooElement, MatchKind.WRITE, 'p = 1;'), 482 _expectId(fooElement, MatchKind.WRITE, 'p = 1;'),
466 // _expectId(fooElement, MatchKind.READ_WRITE, 'p += 2;'), 483 _expectId(fooElement, MatchKind.READ_WRITE, 'p += 2;'),
467 // _expectId(fooElement, MatchKind.READ, 'p);'), 484 _expectId(fooElement, MatchKind.READ, 'p);'),
468 // _expectId(fooElement, MatchKind.INVOCATION, 'p();'), 485 _expectId(fooElement, MatchKind.INVOCATION, 'p();'),
469 // _expectId(mainElement, MatchKind.REFERENCE, 'p: 42') 486 _expectIdQ(mainElement, MatchKind.REFERENCE, 'p: 42')
470 // ]; 487 ];
471 // return _verifyReferences(element, expected); 488 await _verifyReferences(element, expected);
472 // } 489 }
473 // 490
474 // Future test_searchReferences_PrefixElement() { 491 // Future test_searchReferences_PrefixElement() {
475 // _indexTestUnit(''' 492 // _indexTestUnit('''
476 //import 'dart:async' as ppp; 493 //import 'dart:async' as ppp;
477 //main() { 494 //main() {
478 // ppp.Future a; 495 // ppp.Future a;
479 // ppp.Stream b; 496 // ppp.Stream b;
480 //} 497 //}
481 //'''); 498 //''');
482 // PrefixElement element = findNodeElementAtString('ppp;'); 499 // PrefixElement element = findNodeElementAtString('ppp;');
483 // Element elementA = findElement('a'); 500 // Element elementA = findElement('a');
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 _expectIdQ(main, MatchKind.WRITE, 'V = 1; // q'), 573 _expectIdQ(main, MatchKind.WRITE, 'V = 1; // q'),
557 _expectIdQ(main, MatchKind.READ, 'V); // q'), 574 _expectIdQ(main, MatchKind.READ, 'V); // q'),
558 _expectIdQ(main, MatchKind.INVOCATION, 'V(); // q'), 575 _expectIdQ(main, MatchKind.INVOCATION, 'V(); // q'),
559 _expectId(main, MatchKind.WRITE, 'V = 1; // nq'), 576 _expectId(main, MatchKind.WRITE, 'V = 1; // nq'),
560 _expectId(main, MatchKind.READ, 'V); // nq'), 577 _expectId(main, MatchKind.READ, 'V); // nq'),
561 _expectId(main, MatchKind.INVOCATION, 'V(); // nq'), 578 _expectId(main, MatchKind.INVOCATION, 'V(); // nq'),
562 ]; 579 ];
563 await _verifyReferences(variable, expected); 580 await _verifyReferences(variable, expected);
564 } 581 }
565 582
566 // Future test_searchReferences_TypeParameterElement() { 583 test_searchReferences_TypeParameterElement() async {
567 // _indexTestUnit(''' 584 _indexTestUnit('''
568 //class A<T> { 585 class A<T> {
569 // main(T a, T b) {} 586 main(T a, T b) {}
570 //} 587 }
571 //'''); 588 ''');
572 // TypeParameterElement element = findElement('T'); 589 TypeParameterElement element = findElement('T');
573 // Element aElement = findElement('a'); 590 Element aElement = findElement('a');
574 // Element bElement = findElement('b'); 591 Element bElement = findElement('b');
575 // var expected = [ 592 var expected = [
576 // _expectId(aElement, MatchKind.REFERENCE, 'T a'), 593 _expectId(aElement, MatchKind.REFERENCE, 'T a'),
577 // _expectId(bElement, MatchKind.REFERENCE, 'T b') 594 _expectId(bElement, MatchKind.REFERENCE, 'T b')
578 // ]; 595 ];
579 // return _verifyReferences(element, expected); 596 await _verifyReferences(element, expected);
580 // } 597 }
581 598
582 // Future test_searchSubtypes() { 599 // Future test_searchSubtypes() {
583 // _indexTestUnit(''' 600 // _indexTestUnit('''
584 //class T {} 601 //class T {}
585 //class A extends T {} // A 602 //class A extends T {} // A
586 //class B = Object with T; // B 603 //class B = Object with T; // B
587 //class C implements T {} // C 604 //class C implements T {} // C
588 //'''); 605 //''');
589 // ClassElement element = findElement('T'); 606 // ClassElement element = findElement('T');
590 // ClassElement elementA = findElement('A'); 607 // ClassElement elementA = findElement('A');
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 // .then((List<SearchMatch> matches) { 679 // .then((List<SearchMatch> matches) {
663 // _assertMatches(matches, expectedMatches); 680 // _assertMatches(matches, expectedMatches);
664 // }); 681 // });
665 // } 682 // }
666 683
667 static void _assertMatches( 684 static void _assertMatches(
668 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { 685 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) {
669 expect(matches, unorderedEquals(expectedMatches)); 686 expect(matches, unorderedEquals(expectedMatches));
670 } 687 }
671 } 688 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/search/search_engine_internal2.dart ('k') | pkg/analyzer/lib/src/summary/index_unit.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698