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

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

Issue 2566393003: Implement SearchEngine.searchMemberDeclarations() for the new driver. (Closed)
Patch Set: Created 4 years 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analysis_server/src/services/search/search_engine.dart'; 7 import 'package:analysis_server/src/services/search/search_engine.dart';
8 import 'package:analysis_server/src/services/search/search_engine_internal2.dart '; 8 import 'package:analysis_server/src/services/search/search_engine_internal2.dart ';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 ClassElement element = resultA.unit.element.types[0]; 98 ClassElement element = resultA.unit.element.types[0];
99 99
100 var searchEngine = new SearchEngineImpl2([driver1, driver2]); 100 var searchEngine = new SearchEngineImpl2([driver1, driver2]);
101 Set<ClassElement> subtypes = await searchEngine.searchAllSubtypes(element); 101 Set<ClassElement> subtypes = await searchEngine.searchAllSubtypes(element);
102 expect(subtypes, hasLength(3)); 102 expect(subtypes, hasLength(3));
103 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'A'))); 103 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'A')));
104 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'B'))); 104 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'B')));
105 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'C'))); 105 expect(subtypes, contains(predicate((ClassElement e) => e.name == 'C')));
106 } 106 }
107 107
108 test_searchMemberDeclarations() async {
109 var a = _p('/test/a.dart');
110 var b = _p('/test/b.dart');
111
112 var codeA = '''
113 class A {
114 int test; // 1
115 int testTwo;
116 }
117 ''';
118 var codeB = '''
119 class B {
120 void test() {} // 2
121 void testTwo() {}
122 }
123 int test;
124 ''';
125
126 provider.newFile(a, codeA);
127 provider.newFile(b, codeB);
128
129 var driver1 = _newDriver();
130 var driver2 = _newDriver();
131
132 driver1.addFile(a);
133 driver2.addFile(b);
134
135 while (scheduler.isAnalyzing) {
136 await new Future.delayed(new Duration(milliseconds: 1));
137 }
138
139 var searchEngine = new SearchEngineImpl2([driver1, driver2]);
140 List<SearchMatch> matches =
141 await searchEngine.searchMemberDeclarations('test');
142 expect(matches, hasLength(2));
143
144 void assertHasElement(String name, int nameOffset) {
145 expect(
146 matches,
147 contains(predicate((SearchMatch m) =>
148 m.kind == MatchKind.DECLARATION &&
149 m.element.name == name &&
150 m.element.nameOffset == nameOffset)));
151 }
152
153 assertHasElement('test', codeA.indexOf('test; // 1'));
154 assertHasElement('test', codeB.indexOf('test() {} // 2'));
155 }
156
108 test_searchReferences() async { 157 test_searchReferences() async {
109 var a = _p('/test/a.dart'); 158 var a = _p('/test/a.dart');
110 var b = _p('/test/b.dart'); 159 var b = _p('/test/b.dart');
111 160
112 provider.newFile( 161 provider.newFile(
113 a, 162 a,
114 ''' 163 '''
115 class T {} 164 class T {}
116 T a; 165 T a;
117 '''); 166 ''');
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 byteStore, 241 byteStore,
193 contentOverlay, 242 contentOverlay,
194 new SourceFactory( 243 new SourceFactory(
195 [new DartUriResolver(sdk), new ResourceUriResolver(provider)], 244 [new DartUriResolver(sdk), new ResourceUriResolver(provider)],
196 null, 245 null,
197 provider), 246 provider),
198 new AnalysisOptionsImpl()..strongMode = true); 247 new AnalysisOptionsImpl()..strongMode = true);
199 248
200 String _p(String path) => provider.convertPath(path); 249 String _p(String path) => provider.convertPath(path);
201 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698