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

Side by Side Diff: pkg/analysis_server/test/services/index2/index2_test.dart

Issue 1783503004: Listen for context add/remove and unit invalidation to update the index. (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) 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 'package:analysis_server/src/services/index2/index2.dart'; 5 import 'package:analysis_server/src/services/index2/index2.dart';
6 import 'package:analyzer/dart/ast/ast.dart'; 6 import 'package:analyzer/dart/ast/ast.dart';
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/src/generated/source.dart'; 8 import 'package:analyzer/src/generated/source.dart';
9 import 'package:analyzer/src/summary/idl.dart'; 9 import 'package:analyzer/src/summary/idl.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; 10 import 'package:test_reflective_loader/test_reflective_loader.dart';
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 index.indexUnit(testUnit); 190 index.indexUnit(testUnit);
191 } 191 }
192 192
193 test_removeContext() async { 193 test_removeContext() async {
194 _indexTestUnit(''' 194 _indexTestUnit('''
195 class A {} 195 class A {}
196 '''); 196 ''');
197 RegExp regExp = new RegExp(r'^A$'); 197 RegExp regExp = new RegExp(r'^A$');
198 expect(await index.getDefinedNames(regExp, IndexNameKind.topLevel), 198 expect(await index.getDefinedNames(regExp, IndexNameKind.topLevel),
199 hasLength(1)); 199 hasLength(1));
200 // remove the context - no 200 // remove the context - no top-level declarations
201 index.removeContext(context); 201 index.removeContext(context);
202 expect( 202 expect(
203 await index.getDefinedNames(regExp, IndexNameKind.topLevel), isEmpty); 203 await index.getDefinedNames(regExp, IndexNameKind.topLevel), isEmpty);
204 } 204 }
205 205
206 test_removeUnit() async {
207 RegExp regExp = new RegExp(r'^[AB]$');
208 Source sourceA = addSource('/a.dart', 'class A {}');
209 Source sourceB = addSource('/b.dart', 'class B {}');
210 CompilationUnit unitA = resolveLibraryUnit(sourceA);
211 CompilationUnit unitB = resolveLibraryUnit(sourceB);
212 index.indexUnit(unitA);
213 index.indexUnit(unitB);
214 {
215 List<Location> locations =
216 await index.getDefinedNames(regExp, IndexNameKind.topLevel);
217 expect(locations, hasLength(2));
218 expect(locations.map((l) => l.libraryUri),
219 unorderedEquals([sourceA.uri.toString(), sourceB.uri.toString()]));
220 }
221 // remove a.dart - no a.dart location
222 index.removeUnit(context, sourceA, sourceA);
223 {
224 List<Location> locations =
225 await index.getDefinedNames(regExp, IndexNameKind.topLevel);
226 expect(locations, hasLength(1));
227 expect(locations.map((l) => l.libraryUri),
228 unorderedEquals([sourceB.uri.toString()]));
229 }
230 }
231
206 /** 232 /**
207 * Assert that the given list of [locations] has a [Location] corresponding 233 * Assert that the given list of [locations] has a [Location] corresponding
208 * to the [element]. 234 * to the [element].
209 */ 235 */
210 void _assertHasDefinedName(List<Location> locations, Element element) { 236 void _assertHasDefinedName(List<Location> locations, Element element) {
211 String libraryUri = element.library.source.uri.toString(); 237 String libraryUri = element.library.source.uri.toString();
212 String unitUri = element.source.uri.toString(); 238 String unitUri = element.source.uri.toString();
213 for (Location location in locations) { 239 for (Location location in locations) {
214 if (location.libraryUri == libraryUri && 240 if (location.libraryUri == libraryUri &&
215 location.unitUri == unitUri && 241 location.unitUri == unitUri &&
(...skipping 11 matching lines...) Expand all
227 index.indexUnit(testUnit); 253 index.indexUnit(testUnit);
228 } 254 }
229 255
230 Source _indexUnit(String path, String code) { 256 Source _indexUnit(String path, String code) {
231 Source source = addSource(path, code); 257 Source source = addSource(path, code);
232 CompilationUnit unit = resolveLibraryUnit(source); 258 CompilationUnit unit = resolveLibraryUnit(source);
233 index.indexUnit(unit); 259 index.indexUnit(unit);
234 return source; 260 return source;
235 } 261 }
236 } 262 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/status/get_handler.dart ('k') | pkg/analysis_server/test/services/search/search_engine2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698