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 testing.mock_sdk; | 5 library testing.mock_sdk; |
6 | 6 |
7 import 'package:analyzer/file_system/file_system.dart' as resource; | 7 import 'package:analyzer/file_system/file_system.dart' as resource; |
8 import 'package:analyzer/file_system/memory_file_system.dart' as resource; | 8 import 'package:analyzer/file_system/memory_file_system.dart' as resource; |
9 import 'package:analyzer/src/context/context.dart'; | 9 import 'package:analyzer/src/context/context.dart'; |
10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 static const List<SdkLibrary> LIBRARIES = const [ | 235 static const List<SdkLibrary> LIBRARIES = const [ |
236 LIB_CORE, | 236 LIB_CORE, |
237 LIB_ASYNC, | 237 LIB_ASYNC, |
238 LIB_COLLECTION, | 238 LIB_COLLECTION, |
239 LIB_CONVERT, | 239 LIB_CONVERT, |
240 LIB_MATH, | 240 LIB_MATH, |
241 LIB_HTML, | 241 LIB_HTML, |
242 LIB_INTERNAL, | 242 LIB_INTERNAL, |
243 ]; | 243 ]; |
244 | 244 |
245 final resource.MemoryResourceProvider provider = | 245 static const String librariesContent = r''' |
246 new resource.MemoryResourceProvider(); | 246 const Map<String, LibraryInfo> libraries = const { |
| 247 "async": const LibraryInfo("async/async.dart"), |
| 248 "collection": const LibraryInfo("collection/collection.dart"), |
| 249 "convert": const LibraryInfo("convert/convert.dart"), |
| 250 "core": const LibraryInfo("core/core.dart"), |
| 251 "html": const LibraryInfo("html/dartium/html_dartium.dart"), |
| 252 "math": const LibraryInfo("math/math.dart"), |
| 253 "_internal": const LibraryInfo("internal/internal.dart"), |
| 254 }; |
| 255 '''; |
| 256 |
| 257 final resource.MemoryResourceProvider provider; |
247 | 258 |
248 /** | 259 /** |
249 * The [AnalysisContext] which is used for all of the sources. | 260 * The [AnalysisContext] which is used for all of the sources. |
250 */ | 261 */ |
251 InternalAnalysisContext _analysisContext; | 262 InternalAnalysisContext _analysisContext; |
252 | 263 |
253 MockSdk() { | 264 MockSdk({resource.ResourceProvider resourceProvider}) |
| 265 : provider = resourceProvider ?? new resource.MemoryResourceProvider() { |
254 LIBRARIES.forEach((SdkLibrary library) { | 266 LIBRARIES.forEach((SdkLibrary library) { |
255 provider.newFile(library.path, (library as MockSdkLibrary).content); | 267 provider.newFile(library.path, (library as MockSdkLibrary).content); |
256 }); | 268 }); |
| 269 provider.newFile('/lib/_internal/sdk_library_metadata/lib/libraries.dart', |
| 270 librariesContent); |
257 } | 271 } |
258 | 272 |
259 @override | 273 @override |
260 AnalysisContext get context { | 274 AnalysisContext get context { |
261 if (_analysisContext == null) { | 275 if (_analysisContext == null) { |
262 _analysisContext = new SdkAnalysisContext(null); | 276 _analysisContext = new SdkAnalysisContext(null); |
263 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | 277 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); |
264 _analysisContext.sourceFactory = factory; | 278 _analysisContext.sourceFactory = factory; |
265 } | 279 } |
266 return _analysisContext; | 280 return _analysisContext; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 bool get isInternal => shortName.startsWith('dart:_'); | 389 bool get isInternal => shortName.startsWith('dart:_'); |
376 | 390 |
377 @override | 391 @override |
378 bool get isShared => throw unimplemented; | 392 bool get isShared => throw unimplemented; |
379 | 393 |
380 @override | 394 @override |
381 bool get isVmLibrary => throw unimplemented; | 395 bool get isVmLibrary => throw unimplemented; |
382 | 396 |
383 UnimplementedError get unimplemented => new UnimplementedError(); | 397 UnimplementedError get unimplemented => new UnimplementedError(); |
384 } | 398 } |
OLD | NEW |