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

Side by Side Diff: pkg/analyzer/test/src/context/mock_sdk.dart

Issue 2408633003: Tweaks for MockSdk and test ContextBuilder.findSdk() and dart:html. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « pkg/analyzer/test/src/context/builder_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 analyzer.test.src.context.mock_sdk; 5 library analyzer.test.src.context.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/cache.dart'; 9 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/context/context.dart'; 10 import 'package:analyzer/src/context/context.dart';
11 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; 11 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine;
12 import 'package:analyzer/src/generated/sdk.dart'; 12 import 'package:analyzer/src/generated/sdk.dart';
13 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
14 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; 14 import 'package:analyzer/src/summary/idl.dart' show PackageBundle;
15 import 'package:analyzer/src/summary/summary_file_builder.dart'; 15 import 'package:analyzer/src/summary/summary_file_builder.dart';
16 16
17 const String librariesContent = r''' 17 const String librariesContent = r'''
18 const Map<String, LibraryInfo> libraries = const { 18 const Map<String, LibraryInfo> libraries = const {
19 "async": const LibraryInfo("async/async.dart"), 19 "async": const LibraryInfo("async/async.dart"),
20 "collection": const LibraryInfo("collection/collection.dart"), 20 "collection": const LibraryInfo("collection/collection.dart"),
21 "convert": const LibraryInfo("convert/convert.dart"), 21 "convert": const LibraryInfo("convert/convert.dart"),
22 "core": const LibraryInfo("core/core.dart"), 22 "core": const LibraryInfo("core/core.dart"),
23 "html": const LibraryInfo("html/dartium/html_dartium.dart"), 23 "html": const LibraryInfo(
24 "html/dartium/html_dartium.dart",
25 dart2jsPath: "html/dart2js/html_dart2js.dart"),
24 "math": const LibraryInfo("math/math.dart"), 26 "math": const LibraryInfo("math/math.dart"),
25 "_foreign_helper": const LibraryInfo("_internal/js_runtime/lib/foreign_helper. dart"), 27 "_foreign_helper": const LibraryInfo("_internal/js_runtime/lib/foreign_helper. dart"),
26 }; 28 };
27 '''; 29 ''';
28 30
29 const String sdkRoot = '/sdk'; 31 const String sdkRoot = '/sdk';
30 32
31 const _MockSdkLibrary _LIB_ASYNC = const _MockSdkLibrary( 33 const _MockSdkLibrary _LIB_ASYNC = const _MockSdkLibrary(
32 'dart:async', 34 'dart:async',
33 '$sdkRoot/lib/async/async.dart', 35 '$sdkRoot/lib/async/async.dart',
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 'dart:_foreign_helper', 260 'dart:_foreign_helper',
259 '$sdkRoot/lib/_foreign_helper/_foreign_helper.dart', 261 '$sdkRoot/lib/_foreign_helper/_foreign_helper.dart',
260 ''' 262 '''
261 library dart._foreign_helper; 263 library dart._foreign_helper;
262 264
263 JS(String typeDescription, String codeTemplate, 265 JS(String typeDescription, String codeTemplate,
264 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11]) 266 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11])
265 {} 267 {}
266 '''); 268 ''');
267 269
268 const _MockSdkLibrary _LIB_HTML = const _MockSdkLibrary( 270 const _MockSdkLibrary _LIB_HTML_DART2JS = const _MockSdkLibrary(
271 'dart:html',
272 '$sdkRoot/lib/html/dart2js/html_dart2js.dart',
273 '''
274 library dart.html;
275 class HtmlElement {}
276 ''');
277
278 const _MockSdkLibrary _LIB_HTML_DARTIUM = const _MockSdkLibrary(
269 'dart:html', 279 'dart:html',
270 '$sdkRoot/lib/html/dartium/html_dartium.dart', 280 '$sdkRoot/lib/html/dartium/html_dartium.dart',
271 ''' 281 '''
272 library dart.html; 282 library dart.html;
273 class HtmlElement {} 283 class HtmlElement {}
274 '''); 284 ''');
275 285
276 const _MockSdkLibrary _LIB_MATH = const _MockSdkLibrary( 286 const _MockSdkLibrary _LIB_MATH = const _MockSdkLibrary(
277 'dart:math', 287 'dart:math',
278 '$sdkRoot/lib/math/math.dart', 288 '$sdkRoot/lib/math/math.dart',
(...skipping 17 matching lines...) Expand all
296 } 306 }
297 '''); 307 ''');
298 308
299 const List<SdkLibrary> _LIBRARIES = const [ 309 const List<SdkLibrary> _LIBRARIES = const [
300 _LIB_CORE, 310 _LIB_CORE,
301 _LIB_ASYNC, 311 _LIB_ASYNC,
302 _LIB_COLLECTION, 312 _LIB_COLLECTION,
303 _LIB_CONVERT, 313 _LIB_CONVERT,
304 _LIB_FOREIGN_HELPER, 314 _LIB_FOREIGN_HELPER,
305 _LIB_MATH, 315 _LIB_MATH,
306 _LIB_HTML, 316 _LIB_HTML_DART2JS,
317 _LIB_HTML_DARTIUM,
307 ]; 318 ];
308 319
309 class MockSdk implements DartSdk { 320 class MockSdk implements DartSdk {
310 static const Map<String, String> FULL_URI_MAP = const { 321 static const Map<String, String> FULL_URI_MAP = const {
311 "dart:core": "$sdkRoot/lib/core/core.dart", 322 "dart:core": "$sdkRoot/lib/core/core.dart",
312 "dart:html": "$sdkRoot/lib/html/dartium/html_dartium.dart", 323 "dart:html": "$sdkRoot/lib/html/dartium/html_dartium.dart",
313 "dart:async": "$sdkRoot/lib/async/async.dart", 324 "dart:async": "$sdkRoot/lib/async/async.dart",
314 "dart:async/stream.dart": "$sdkRoot/lib/async/stream.dart", 325 "dart:async/stream.dart": "$sdkRoot/lib/async/stream.dart",
315 "dart:collection": "$sdkRoot/lib/collection/collection.dart", 326 "dart:collection": "$sdkRoot/lib/collection/collection.dart",
316 "dart:convert": "$sdkRoot/lib/convert/convert.dart", 327 "dart:convert": "$sdkRoot/lib/convert/convert.dart",
(...skipping 27 matching lines...) Expand all
344 : provider = resourceProvider ?? new resource.MemoryResourceProvider(), 355 : provider = resourceProvider ?? new resource.MemoryResourceProvider(),
345 sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE], 356 sdkLibraries = dartAsync ? _LIBRARIES : [_LIB_CORE],
346 uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP { 357 uriMap = dartAsync ? FULL_URI_MAP : NO_ASYNC_URI_MAP {
347 for (_MockSdkLibrary library in sdkLibraries) { 358 for (_MockSdkLibrary library in sdkLibraries) {
348 provider.newFile(provider.convertPath(library.path), library.content); 359 provider.newFile(provider.convertPath(library.path), library.content);
349 library.parts.forEach((String path, String content) { 360 library.parts.forEach((String path, String content) {
350 provider.newFile(provider.convertPath(path), content); 361 provider.newFile(provider.convertPath(path), content);
351 }); 362 });
352 } 363 }
353 provider.newFile( 364 provider.newFile(
354 provider 365 provider.convertPath(
355 .convertPath('/_internal/sdk_library_metadata/lib/libraries.dart'), 366 '$sdkRoot/lib/_internal/sdk_library_metadata/lib/libraries.dart'),
356 librariesContent); 367 librariesContent);
357 } 368 }
358 369
359 @override 370 @override
360 AnalysisContextImpl get context { 371 AnalysisContextImpl get context {
361 if (_analysisContext == null) { 372 if (_analysisContext == null) {
362 _analysisContext = new _SdkAnalysisContext(this); 373 _analysisContext = new _SdkAnalysisContext(this);
363 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); 374 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]);
364 _analysisContext.sourceFactory = factory; 375 _analysisContext.sourceFactory = factory;
365 } 376 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 510
500 @override 511 @override
501 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { 512 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) {
502 if (factory == null) { 513 if (factory == null) {
503 return super.createCacheFromSourceFactory(factory); 514 return super.createCacheFromSourceFactory(factory);
504 } 515 }
505 return new AnalysisCache( 516 return new AnalysisCache(
506 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 517 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
507 } 518 }
508 } 519 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/context/builder_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698