| 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/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/sdk.dart'; | 10 import 'package:analyzer/src/generated/sdk.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; | 11 import 'package:analyzer/src/generated/source.dart'; |
| 12 | 12 |
| 13 | 13 |
| 14 class MockSdk implements DartSdk { | 14 class MockSdk implements DartSdk { |
| 15 final resource.MemoryResourceProvider provider = | |
| 16 new resource.MemoryResourceProvider(); | |
| 17 | |
| 18 static const _MockSdkLibrary LIB_CORE = | 15 static const _MockSdkLibrary LIB_CORE = |
| 19 const _MockSdkLibrary('dart:core', '/lib/core/core.dart', ''' | 16 const _MockSdkLibrary('dart:core', '/lib/core/core.dart', ''' |
| 20 library dart.core; | 17 library dart.core; |
| 21 class Object {} | 18 class Object {} |
| 22 class Function {} | 19 class Function {} |
| 23 class StackTrace {} | 20 class StackTrace {} |
| 24 class Symbol {} | 21 class Symbol {} |
| 25 class Type {} | 22 class Type {} |
| 26 | 23 |
| 27 abstract class Comparable<T> { | 24 abstract class Comparable<T> { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 library dart.html; | 84 library dart.html; |
| 88 class HtmlElement {} | 85 class HtmlElement {} |
| 89 '''); | 86 '''); |
| 90 | 87 |
| 91 static const List<SdkLibrary> LIBRARIES = const [ | 88 static const List<SdkLibrary> LIBRARIES = const [ |
| 92 LIB_CORE, | 89 LIB_CORE, |
| 93 LIB_ASYNC, | 90 LIB_ASYNC, |
| 94 LIB_MATH, | 91 LIB_MATH, |
| 95 LIB_HTML,]; | 92 LIB_HTML,]; |
| 96 | 93 |
| 94 final resource.MemoryResourceProvider provider = |
| 95 new resource.MemoryResourceProvider(); |
| 96 |
| 97 MockSdk() { | 97 MockSdk() { |
| 98 LIBRARIES.forEach((_MockSdkLibrary library) { | 98 LIBRARIES.forEach((_MockSdkLibrary library) { |
| 99 provider.newFile(library.path, library.content); | 99 provider.newFile(library.path, library.content); |
| 100 }); | 100 }); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Not used | |
| 104 @override | 103 @override |
| 105 AnalysisContext get context => throw unimplemented; | 104 AnalysisContext get context => throw unimplemented; |
| 106 | 105 |
| 107 @override | 106 @override |
| 108 List<SdkLibrary> get sdkLibraries => LIBRARIES; | 107 List<SdkLibrary> get sdkLibraries => LIBRARIES; |
| 109 | 108 |
| 110 @override | 109 @override |
| 111 String get sdkVersion => throw unimplemented; | 110 String get sdkVersion => throw unimplemented; |
| 112 | 111 |
| 113 UnimplementedError get unimplemented => new UnimplementedError(); | 112 UnimplementedError get unimplemented => new UnimplementedError(); |
| 114 | 113 |
| 115 @override | 114 @override |
| 116 List<String> get uris => throw unimplemented; | 115 List<String> get uris => throw unimplemented; |
| 117 | 116 |
| 118 // Not used. | |
| 119 @override | 117 @override |
| 120 Source fromEncoding(UriKind kind, Uri uri) { | 118 Source fromFileUri(Uri uri) { |
| 121 resource.Resource file = provider.getResource(uri.path); | 119 resource.Resource file = provider.getResource(uri.path); |
| 122 if (file is resource.File) { | 120 if (file is resource.File) { |
| 123 return file.createSource(kind); | 121 return file.createSource(uri); |
| 124 } | 122 } |
| 125 return null; | 123 return null; |
| 126 } | 124 } |
| 127 | 125 |
| 128 // Not used. | |
| 129 @override | 126 @override |
| 130 SdkLibrary getSdkLibrary(String dartUri) { | 127 SdkLibrary getSdkLibrary(String dartUri) { |
| 131 // getSdkLibrary() is only used to determine whether a library is internal | 128 // getSdkLibrary() is only used to determine whether a library is internal |
| 132 // to the SDK. The mock SDK doesn't have any internals, so it's safe to | 129 // to the SDK. The mock SDK doesn't have any internals, so it's safe to |
| 133 // return null. | 130 // return null. |
| 134 return null; | 131 return null; |
| 135 } | 132 } |
| 136 | 133 |
| 137 // Not used. | |
| 138 @override | 134 @override |
| 139 Source mapDartUri(String dartUri) { | 135 Source mapDartUri(String dartUri) { |
| 140 const Map<String, String> uriToPath = const { | 136 const Map<String, String> uriToPath = const { |
| 141 "dart:core": "/lib/core/core.dart", | 137 "dart:core": "/lib/core/core.dart", |
| 142 "dart:html": "/lib/html/dartium/html_dartium.dart", | 138 "dart:html": "/lib/html/dartium/html_dartium.dart", |
| 143 "dart:async": "/lib/async/async.dart", | 139 "dart:async": "/lib/async/async.dart", |
| 144 "dart:math": "/lib/math/math.dart" | 140 "dart:math": "/lib/math/math.dart" |
| 145 }; | 141 }; |
| 146 | 142 |
| 147 String path = uriToPath[dartUri]; | 143 String path = uriToPath[dartUri]; |
| 148 if (path != null) { | 144 if (path != null) { |
| 149 resource.File file = provider.getResource(path); | 145 resource.File file = provider.getResource(path); |
| 150 return file.createSource(UriKind.DART_URI); | 146 Uri uri = new Uri(scheme: 'dart', path: dartUri.substring(5)); |
| 147 return file.createSource(uri); |
| 151 } | 148 } |
| 152 | 149 |
| 153 // If we reach here then we tried to use a dartUri that's not in the | 150 // If we reach here then we tried to use a dartUri that's not in the |
| 154 // table above. | 151 // table above. |
| 155 throw unimplemented; | 152 throw unimplemented; |
| 156 } | 153 } |
| 157 } | 154 } |
| 158 | 155 |
| 159 | 156 |
| 160 class _MockSdkLibrary implements SdkLibrary { | 157 class _MockSdkLibrary implements SdkLibrary { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 180 bool get isInternal => throw unimplemented; | 177 bool get isInternal => throw unimplemented; |
| 181 | 178 |
| 182 @override | 179 @override |
| 183 bool get isShared => throw unimplemented; | 180 bool get isShared => throw unimplemented; |
| 184 | 181 |
| 185 @override | 182 @override |
| 186 bool get isVmLibrary => throw unimplemented; | 183 bool get isVmLibrary => throw unimplemented; |
| 187 | 184 |
| 188 UnimplementedError get unimplemented => new UnimplementedError(); | 185 UnimplementedError get unimplemented => new UnimplementedError(); |
| 189 } | 186 } |
| OLD | NEW |