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

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

Issue 1788673004: Index unqualified unresolved used names. (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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 ClassElement elementB = findElement('B'); 109 ClassElement elementB = findElement('B');
110 var expected = [ 110 var expected = [
111 _expectId(elementA.methods[0], MatchKind.DECLARATION, 'test() {}'), 111 _expectId(elementA.methods[0], MatchKind.DECLARATION, 'test() {}'),
112 _expectId(elementB.fields[0], MatchKind.DECLARATION, 'test = 1;') 112 _expectId(elementB.fields[0], MatchKind.DECLARATION, 'test = 1;')
113 ]; 113 ];
114 List<SearchMatch> matches = 114 List<SearchMatch> matches =
115 await searchEngine.searchMemberDeclarations('test'); 115 await searchEngine.searchMemberDeclarations('test');
116 _assertMatches(matches, expected); 116 _assertMatches(matches, expected);
117 } 117 }
118 118
119 test_searchMemberReferences() async { 119 test_searchMemberReferences_qualified_resolved() async {
120 _indexTestUnit(''' 120 _indexTestUnit('''
121 class A { 121 class C {
122 var test; // A 122 var test;
123 mainA() { 123 }
124 test(); // a-inv-r-nq 124 main(C c) {
125 test = 1; // a-ref-r-nq 125 print(c.test);
126 test += 2; // a-ref-r-nq 126 c.test = 1;
127 print(test); // a-ref-r-nq 127 c.test += 2;
128 c.test();
129 }
130 ''');
131 List<SearchMatch> matches =
132 await searchEngine.searchMemberReferences('test');
133 expect(matches, isEmpty);
128 } 134 }
129 } 135
130 main(A a, p) { 136 test_searchMemberReferences_qualified_unresolved() async {
131 print(a.test); // r 137 _indexTestUnit('''
132 a.test = 1; // r 138 main(p) {
133 a.test += 2; // r 139 print(p.test);
134 a.test(); // r 140 p.test = 1;
135 print(p.test); // ur 141 p.test += 2;
136 p.test = 1; // ur 142 p.test();
137 p.test += 2; // ur
138 p.test(); // ur
139 } 143 }
140 '''); 144 ''');
141 Element main = findElement('main'); 145 Element main = findElement('main');
142 var expected = [ 146 var expected = [
143 _expectIdQU(main, MatchKind.READ, 'test); // ur'), 147 _expectIdQU(main, MatchKind.READ, 'test);'),
144 _expectIdQU(main, MatchKind.WRITE, 'test = 1; // ur'), 148 _expectIdQU(main, MatchKind.WRITE, 'test = 1;'),
145 _expectIdQU(main, MatchKind.READ_WRITE, 'test += 2; // ur'), 149 _expectIdQU(main, MatchKind.READ_WRITE, 'test += 2;'),
146 _expectIdQU(main, MatchKind.INVOCATION, 'test(); // ur'), 150 _expectIdQU(main, MatchKind.INVOCATION, 'test();'),
147 ]; 151 ];
148 List<SearchMatch> matches = 152 List<SearchMatch> matches =
149 await searchEngine.searchMemberReferences('test'); 153 await searchEngine.searchMemberReferences('test');
154 _assertMatches(matches, expected);
155 }
156
157 test_searchMemberReferences_unqualified_resolved() async {
158 _indexTestUnit('''
159 class C {
160 var test;
161 main() {
162 print(test);
163 test = 1;
164 test += 2;
165 test();
166 }
167 }
168 ''');
169 List<SearchMatch> matches =
170 await searchEngine.searchMemberReferences('test');
171 expect(matches, isEmpty);
172 }
173
174 test_searchMemberReferences_unqualified_unresolved() async {
175 verifyNoTestUnitErrors = false;
176 _indexTestUnit('''
177 class C {
178 main() {
179 print(test);
180 test = 1;
181 test += 2;
182 test();
183 }
184 }
185 ''');
186 Element main = findElement('main');
187 var expected = [
188 _expectIdU(main, MatchKind.READ, 'test);'),
189 _expectIdU(main, MatchKind.WRITE, 'test = 1;'),
190 _expectIdU(main, MatchKind.READ_WRITE, 'test += 2;'),
191 _expectIdU(main, MatchKind.INVOCATION, 'test();'),
192 ];
193 List<SearchMatch> matches =
194 await searchEngine.searchMemberReferences('test');
150 _assertMatches(matches, expected); 195 _assertMatches(matches, expected);
151 } 196 }
152 197
153 test_searchReferences_ClassElement() async { 198 test_searchReferences_ClassElement() async {
154 _indexTestUnit(''' 199 _indexTestUnit('''
155 class A {} 200 class A {}
156 main(A p) { 201 main(A p) {
157 A v; 202 A v;
158 } 203 }
159 '''); 204 ''');
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 794
750 /** 795 /**
751 * Create [ExpectedMatch] for a qualified and unresolved match. 796 * Create [ExpectedMatch] for a qualified and unresolved match.
752 */ 797 */
753 ExpectedMatch _expectIdQU(Element element, MatchKind kind, String search, 798 ExpectedMatch _expectIdQU(Element element, MatchKind kind, String search,
754 {int length}) { 799 {int length}) {
755 return _expectId(element, kind, search, 800 return _expectId(element, kind, search,
756 isQualified: true, isResolved: false, length: length); 801 isQualified: true, isResolved: false, length: length);
757 } 802 }
758 803
804 /**
805 * Create [ExpectedMatch] for a unqualified and unresolved match.
806 */
807 ExpectedMatch _expectIdU(Element element, MatchKind kind, String search,
808 {int length}) {
809 return _expectId(element, kind, search,
810 isQualified: false, isResolved: false, length: length);
811 }
812
759 void _indexTestUnit(String code) { 813 void _indexTestUnit(String code) {
760 resolveTestUnit(code); 814 resolveTestUnit(code);
761 index.indexUnit(testUnit); 815 index.indexUnit(testUnit);
762 } 816 }
763 817
764 Future _verifyReferences( 818 Future _verifyReferences(
765 Element element, List<ExpectedMatch> expectedMatches) async { 819 Element element, List<ExpectedMatch> expectedMatches) async {
766 List<SearchMatch> matches = await searchEngine.searchReferences(element); 820 List<SearchMatch> matches = await searchEngine.searchReferences(element);
767 _assertMatches(matches, expectedMatches); 821 _assertMatches(matches, expectedMatches);
768 expect(matches, hasLength(expectedMatches.length)); 822 expect(matches, hasLength(expectedMatches.length));
769 } 823 }
770 824
771 static void _assertMatches( 825 static void _assertMatches(
772 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { 826 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) {
773 expect(matches, unorderedEquals(expectedMatches)); 827 expect(matches, unorderedEquals(expectedMatches));
774 } 828 }
775 } 829 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698