| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // ClassElement elementC = findElement('C'); | 86 // ClassElement elementC = findElement('C'); |
| 87 // var expected = [ | 87 // var expected = [ |
| 88 // _expectId(elementA, MatchKind.DECLARATION, 'A extends T'), | 88 // _expectId(elementA, MatchKind.DECLARATION, 'A extends T'), |
| 89 // _expectId(elementB, MatchKind.DECLARATION, 'B extends A'), | 89 // _expectId(elementB, MatchKind.DECLARATION, 'B extends A'), |
| 90 // _expectId(elementC, MatchKind.DECLARATION, 'C implements B') | 90 // _expectId(elementC, MatchKind.DECLARATION, 'C implements B') |
| 91 // ]; | 91 // ]; |
| 92 // return searchEngine.searchAllSubtypes(element).then((matches) { | 92 // return searchEngine.searchAllSubtypes(element).then((matches) { |
| 93 // _assertMatches(matches, expected); | 93 // _assertMatches(matches, expected); |
| 94 // }); | 94 // }); |
| 95 // } | 95 // } |
| 96 // | 96 |
| 97 // Future test_searchMemberDeclarations() { | 97 test_searchMemberDeclarations() async { |
| 98 // _indexTestUnit(''' | 98 _indexTestUnit(''' |
| 99 //class A { | 99 class A { |
| 100 // test() {} | 100 test() {} |
| 101 //} | 101 } |
| 102 //class B { | 102 class B { |
| 103 // int test = 1; | 103 int test = 1; |
| 104 // main() { | 104 main() { |
| 105 // int test = 2; | 105 int test = 2; |
| 106 // } | 106 } |
| 107 //} | 107 } |
| 108 //'''); | 108 '''); |
| 109 // ClassElement elementA = findElement('A'); | 109 ClassElement elementA = findElement('A'); |
| 110 // ClassElement elementB = findElement('B'); | 110 ClassElement elementB = findElement('B'); |
| 111 // var expected = [ | 111 var expected = [ |
| 112 // _expectId(elementA.methods[0], MatchKind.DECLARATION, 'test() {}'), | 112 _expectId(elementA.methods[0], MatchKind.DECLARATION, 'test() {}'), |
| 113 // _expectId(elementB.fields[0], MatchKind.DECLARATION, 'test = 1;') | 113 _expectId(elementB.fields[0], MatchKind.DECLARATION, 'test = 1;') |
| 114 // ]; | 114 ]; |
| 115 // return searchEngine.searchMemberDeclarations('test').then((matches) { | 115 List<SearchMatch> matches = |
| 116 // _assertMatches(matches, expected); | 116 await searchEngine.searchMemberDeclarations('test'); |
| 117 // }); | 117 _assertMatches(matches, expected); |
| 118 // } | 118 } |
| 119 // | 119 |
| 120 // Future test_searchMemberReferences() { | 120 // Future test_searchMemberReferences() { |
| 121 // _indexTestUnit(''' | 121 // _indexTestUnit(''' |
| 122 //class A { | 122 //class A { |
| 123 // var test; // A | 123 // var test; // A |
| 124 // mainA() { | 124 // mainA() { |
| 125 // test(); // a-inv-r-nq | 125 // test(); // a-inv-r-nq |
| 126 // test = 1; // a-write-r-nq | 126 // test = 1; // a-write-r-nq |
| 127 // test += 2; // a-read-write-r-nq | 127 // test += 2; // a-read-write-r-nq |
| 128 // print(test); // a-read-r-nq | 128 // print(test); // a-read-r-nq |
| 129 // } | 129 // } |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 // ClassElement elementC = findElement('C'); | 653 // ClassElement elementC = findElement('C'); |
| 654 // var expected = [ | 654 // var expected = [ |
| 655 // _expectId(elementA, MatchKind.REFERENCE, 'T {} // A'), | 655 // _expectId(elementA, MatchKind.REFERENCE, 'T {} // A'), |
| 656 // _expectId(elementB, MatchKind.REFERENCE, 'T; // B'), | 656 // _expectId(elementB, MatchKind.REFERENCE, 'T; // B'), |
| 657 // _expectId(elementC, MatchKind.REFERENCE, 'T {} // C') | 657 // _expectId(elementC, MatchKind.REFERENCE, 'T {} // C') |
| 658 // ]; | 658 // ]; |
| 659 // return searchEngine.searchSubtypes(element).then((matches) { | 659 // return searchEngine.searchSubtypes(element).then((matches) { |
| 660 // _assertMatches(matches, expected); | 660 // _assertMatches(matches, expected); |
| 661 // }); | 661 // }); |
| 662 // } | 662 // } |
| 663 // | 663 |
| 664 // Future test_searchTopLevelDeclarations() { | 664 test_searchTopLevelDeclarations() async { |
| 665 // _indexTestUnit(''' | 665 _indexTestUnit(''' |
| 666 //class A {} // A | 666 class A {} // A |
| 667 //class B = Object with A; | 667 class B = Object with A; |
| 668 //typedef C(); | 668 typedef C(); |
| 669 //D() {} | 669 D() {} |
| 670 //var E = null; | 670 var E = null; |
| 671 //class NoMatchABCDE {} | 671 class NoMatchABCDE {} |
| 672 //'''); | 672 '''); |
| 673 // Element topA = findElement('A'); | 673 Element topA = findElement('A'); |
| 674 // Element topB = findElement('B'); | 674 Element topB = findElement('B'); |
| 675 // Element topC = findElement('C'); | 675 Element topC = findElement('C'); |
| 676 // Element topD = findElement('D'); | 676 Element topD = findElement('D'); |
| 677 // Element topE = findElement('E'); | 677 Element topE = findElement('E'); |
| 678 // var expected = [ | 678 var expected = [ |
| 679 // _expectId(topA, MatchKind.DECLARATION, 'A {} // A'), | 679 _expectId(topA, MatchKind.DECLARATION, 'A {} // A'), |
| 680 // _expectId(topB, MatchKind.DECLARATION, 'B ='), | 680 _expectId(topB, MatchKind.DECLARATION, 'B ='), |
| 681 // _expectId(topC, MatchKind.DECLARATION, 'C()'), | 681 _expectId(topC, MatchKind.DECLARATION, 'C()'), |
| 682 // _expectId(topD, MatchKind.DECLARATION, 'D() {}'), | 682 _expectId(topD, MatchKind.DECLARATION, 'D() {}'), |
| 683 // _expectId(topE, MatchKind.DECLARATION, 'E = null') | 683 _expectId(topE, MatchKind.DECLARATION, 'E = null') |
| 684 // ]; | 684 ]; |
| 685 // return _verifyTopLevelDeclarations('^[A-E]\$', expected); | 685 List<SearchMatch> matches = |
| 686 // } | 686 await searchEngine.searchTopLevelDeclarations(r'^[A-E]$'); |
| 687 _assertMatches(matches, expected); |
| 688 } |
| 687 | 689 |
| 688 ExpectedMatch _expectId(Element element, MatchKind kind, String search, | 690 ExpectedMatch _expectId(Element element, MatchKind kind, String search, |
| 689 {int length, bool isResolved: true, bool isQualified: false}) { | 691 {int length, bool isResolved: true, bool isQualified: false}) { |
| 690 int offset = findOffset(search); | 692 int offset = findOffset(search); |
| 691 if (length == null) { | 693 if (length == null) { |
| 692 length = getLeadingIdentifierLength(search); | 694 length = getLeadingIdentifierLength(search); |
| 693 } | 695 } |
| 694 return new ExpectedMatch(element, kind, offset, length, | 696 return new ExpectedMatch(element, kind, offset, length, |
| 695 isResolved: isResolved, isQualified: isQualified); | 697 isResolved: isResolved, isQualified: isQualified); |
| 696 } | 698 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 709 resolveTestUnit(code); | 711 resolveTestUnit(code); |
| 710 index.indexUnit(testUnit); | 712 index.indexUnit(testUnit); |
| 711 } | 713 } |
| 712 | 714 |
| 713 Future _verifyReferences( | 715 Future _verifyReferences( |
| 714 Element element, List<ExpectedMatch> expectedMatches) async { | 716 Element element, List<ExpectedMatch> expectedMatches) async { |
| 715 List<SearchMatch> matches = await searchEngine.searchReferences(element); | 717 List<SearchMatch> matches = await searchEngine.searchReferences(element); |
| 716 _assertMatches(matches, expectedMatches); | 718 _assertMatches(matches, expectedMatches); |
| 717 } | 719 } |
| 718 | 720 |
| 719 // Future _verifyTopLevelDeclarations( | |
| 720 // String pattern, List<ExpectedMatch> expectedMatches) { | |
| 721 // return searchEngine | |
| 722 // .searchTopLevelDeclarations(pattern) | |
| 723 // .then((List<SearchMatch> matches) { | |
| 724 // _assertMatches(matches, expectedMatches); | |
| 725 // }); | |
| 726 // } | |
| 727 | |
| 728 static void _assertMatches( | 721 static void _assertMatches( |
| 729 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { | 722 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { |
| 730 expect(matches, unorderedEquals(expectedMatches)); | 723 expect(matches, unorderedEquals(expectedMatches)); |
| 731 } | 724 } |
| 732 } | 725 } |
| OLD | NEW |