OLD | NEW |
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'; |
11 import 'package:analyzer/file_system/memory_file_system.dart'; | 11 import 'package:analyzer/file_system/memory_file_system.dart'; |
12 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 12 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
13 import 'package:analyzer/src/dart/analysis/driver.dart'; | 13 import 'package:analyzer/src/dart/analysis/driver.dart'; |
14 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 14 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 16 import 'package:analyzer/src/generated/sdk.dart'; |
16 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
17 import 'package:test/test.dart'; | 18 import 'package:test/test.dart'; |
18 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 19 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
19 | 20 |
20 import '../../mock_sdk.dart'; | 21 import '../../mock_sdk.dart'; |
21 | 22 |
22 main() { | 23 main() { |
23 defineReflectiveSuite(() { | 24 defineReflectiveSuite(() { |
24 defineReflectiveTests(SearchEngineImpl2Test); | 25 defineReflectiveTests(SearchEngineImpl2Test); |
25 }); | 26 }); |
26 } | 27 } |
27 | 28 |
28 @reflectiveTest | 29 @reflectiveTest |
29 class SearchEngineImpl2Test { | 30 class SearchEngineImpl2Test { |
30 static final MockSdk sdk = new MockSdk(); | |
31 | |
32 final MemoryResourceProvider provider = new MemoryResourceProvider(); | 31 final MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 32 DartSdk sdk; |
33 final ByteStore byteStore = new MemoryByteStore(); | 33 final ByteStore byteStore = new MemoryByteStore(); |
34 final FileContentOverlay contentOverlay = new FileContentOverlay(); | 34 final FileContentOverlay contentOverlay = new FileContentOverlay(); |
35 | 35 |
36 final StringBuffer logBuffer = new StringBuffer(); | 36 final StringBuffer logBuffer = new StringBuffer(); |
37 PerformanceLog logger; | 37 PerformanceLog logger; |
38 | 38 |
39 AnalysisDriverScheduler scheduler; | 39 AnalysisDriverScheduler scheduler; |
40 | 40 |
41 void setUp() { | 41 void setUp() { |
| 42 sdk = new MockSdk(resourceProvider: provider); |
42 logger = new PerformanceLog(logBuffer); | 43 logger = new PerformanceLog(logBuffer); |
43 scheduler = new AnalysisDriverScheduler(logger); | 44 scheduler = new AnalysisDriverScheduler(logger); |
44 scheduler.start(); | 45 scheduler.start(); |
45 } | 46 } |
46 | 47 |
47 test_searchAllSubtypes() async { | 48 test_searchAllSubtypes() async { |
48 var p = _p('/test.dart'); | 49 var p = _p('/test.dart'); |
49 | 50 |
50 provider.newFile( | 51 provider.newFile( |
51 p, | 52 p, |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 driver1.addFile(a); | 256 driver1.addFile(a); |
256 driver2.addFile(b); | 257 driver2.addFile(b); |
257 | 258 |
258 while (scheduler.isAnalyzing) { | 259 while (scheduler.isAnalyzing) { |
259 await new Future.delayed(new Duration(milliseconds: 1)); | 260 await new Future.delayed(new Duration(milliseconds: 1)); |
260 } | 261 } |
261 | 262 |
262 var searchEngine = new SearchEngineImpl2([driver1, driver2]); | 263 var searchEngine = new SearchEngineImpl2([driver1, driver2]); |
263 List<SearchMatch> matches = | 264 List<SearchMatch> matches = |
264 await searchEngine.searchTopLevelDeclarations('.*'); | 265 await searchEngine.searchTopLevelDeclarations('.*'); |
265 expect(matches, hasLength(4)); | 266 expect( |
| 267 matches.where((match) => !match.libraryElement.isInSdk), hasLength(4)); |
266 | 268 |
267 void assertHasElement(String name) { | 269 void assertHasElement(String name) { |
268 expect( | 270 expect( |
269 matches, | 271 matches, |
270 contains(predicate((SearchMatch m) => | 272 contains(predicate((SearchMatch m) => |
271 m.kind == MatchKind.DECLARATION && m.element.name == name))); | 273 m.kind == MatchKind.DECLARATION && m.element.name == name))); |
272 } | 274 } |
273 | 275 |
274 assertHasElement('A'); | 276 assertHasElement('A'); |
275 assertHasElement('a'); | 277 assertHasElement('a'); |
276 assertHasElement('B'); | 278 assertHasElement('B'); |
277 assertHasElement('b'); | 279 assertHasElement('b'); |
278 } | 280 } |
279 | 281 |
280 AnalysisDriver _newDriver() => new AnalysisDriver( | 282 AnalysisDriver _newDriver() => new AnalysisDriver( |
281 scheduler, | 283 scheduler, |
282 logger, | 284 logger, |
283 provider, | 285 provider, |
284 byteStore, | 286 byteStore, |
285 contentOverlay, | 287 contentOverlay, |
286 'test', | 288 'test', |
287 new SourceFactory( | 289 new SourceFactory( |
288 [new DartUriResolver(sdk), new ResourceUriResolver(provider)], | 290 [new DartUriResolver(sdk), new ResourceUriResolver(provider)], |
289 null, | 291 null, |
290 provider), | 292 provider), |
291 new AnalysisOptionsImpl()..strongMode = true); | 293 new AnalysisOptionsImpl()..strongMode = true); |
292 | 294 |
293 String _p(String path) => provider.convertPath(path); | 295 String _p(String path) => provider.convertPath(path); |
294 } | 296 } |
OLD | NEW |