| 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 class MockSdk implements DartSdk { | 13 class MockSdk implements DartSdk { |
| 14 static const _MockSdkLibrary LIB_CORE = const _MockSdkLibrary('dart:core', | 14 static const _MockSdkLibrary LIB_CORE = const _MockSdkLibrary('dart:core', |
| 15 '/lib/core/core.dart', ''' | 15 '/lib/core/core.dart', ''' |
| 16 library dart.core; | 16 library dart.core; |
| 17 | 17 |
| 18 import 'dart:async'; | 18 import 'dart:async'; |
| 19 import 'dart:_internal'; |
| 19 | 20 |
| 20 class Object { | 21 class Object { |
| 21 bool operator ==(other) => identical(this, other); | 22 bool operator ==(other) => identical(this, other); |
| 22 String toString() => 'a string'; | 23 String toString() => 'a string'; |
| 23 int get hashCode => 0; | 24 int get hashCode => 0; |
| 24 } | 25 } |
| 25 | 26 |
| 26 class Function {} | 27 class Function {} |
| 27 class StackTrace {} | 28 class StackTrace {} |
| 28 class Symbol {} | 29 class Symbol {} |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 138 |
| 138 static const _MockSdkLibrary LIB_MATH = const _MockSdkLibrary('dart:math', | 139 static const _MockSdkLibrary LIB_MATH = const _MockSdkLibrary('dart:math', |
| 139 '/lib/math/math.dart', ''' | 140 '/lib/math/math.dart', ''' |
| 140 library dart.math; | 141 library dart.math; |
| 141 const double E = 2.718281828459045; | 142 const double E = 2.718281828459045; |
| 142 const double PI = 3.1415926535897932; | 143 const double PI = 3.1415926535897932; |
| 143 const double LN10 = 2.302585092994046; | 144 const double LN10 = 2.302585092994046; |
| 144 num min(num a, num b) => 0; | 145 num min(num a, num b) => 0; |
| 145 num max(num a, num b) => 0; | 146 num max(num a, num b) => 0; |
| 146 external double cos(num x); | 147 external double cos(num x); |
| 148 external num pow(num x, num exponent); |
| 147 external double sin(num x); | 149 external double sin(num x); |
| 148 external double sqrt(num x); | 150 external double sqrt(num x); |
| 149 class Random { | 151 class Random { |
| 150 bool nextBool() => true; | 152 bool nextBool() => true; |
| 151 double nextDouble() => 2.0; | 153 double nextDouble() => 2.0; |
| 152 int nextInt() => 1; | 154 int nextInt() => 1; |
| 153 } | 155 } |
| 154 '''); | 156 '''); |
| 155 | 157 |
| 156 static const _MockSdkLibrary LIB_HTML = const _MockSdkLibrary('dart:html', | 158 static const _MockSdkLibrary LIB_HTML = const _MockSdkLibrary('dart:html', |
| 157 '/lib/html/dartium/html_dartium.dart', ''' | 159 '/lib/html/dartium/html_dartium.dart', ''' |
| 158 library dart.html; | 160 library dart.html; |
| 159 class HtmlElement {} | 161 class HtmlElement {} |
| 160 '''); | 162 '''); |
| 161 | 163 |
| 164 static const _MockSdkLibrary LIB_INTERNAL = const _MockSdkLibrary( |
| 165 'dart:_internal', '/lib/internal/internal.dart', ''' |
| 166 library dart._internal; |
| 167 external void printToConsole(String line); |
| 168 '''); |
| 169 |
| 162 static const List<SdkLibrary> LIBRARIES = const [ | 170 static const List<SdkLibrary> LIBRARIES = const [ |
| 163 LIB_CORE, | 171 LIB_CORE, |
| 164 LIB_ASYNC, | 172 LIB_ASYNC, |
| 165 LIB_COLLECTION, | 173 LIB_COLLECTION, |
| 166 LIB_CONVERT, | 174 LIB_CONVERT, |
| 167 LIB_MATH, | 175 LIB_MATH, |
| 168 LIB_HTML, | 176 LIB_HTML, |
| 177 LIB_INTERNAL, |
| 169 ]; | 178 ]; |
| 170 | 179 |
| 171 final resource.MemoryResourceProvider provider = | 180 final resource.MemoryResourceProvider provider = |
| 172 new resource.MemoryResourceProvider(); | 181 new resource.MemoryResourceProvider(); |
| 173 | 182 |
| 174 /** | 183 /** |
| 175 * The [AnalysisContext] which is used for all of the sources. | 184 * The [AnalysisContext] which is used for all of the sources. |
| 176 */ | 185 */ |
| 177 InternalAnalysisContext _analysisContext; | 186 InternalAnalysisContext _analysisContext; |
| 178 | 187 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 266 } |
| 258 | 267 |
| 259 @override | 268 @override |
| 260 Source mapDartUri(String dartUri) { | 269 Source mapDartUri(String dartUri) { |
| 261 const Map<String, String> uriToPath = const { | 270 const Map<String, String> uriToPath = const { |
| 262 "dart:core": "/lib/core/core.dart", | 271 "dart:core": "/lib/core/core.dart", |
| 263 "dart:html": "/lib/html/dartium/html_dartium.dart", | 272 "dart:html": "/lib/html/dartium/html_dartium.dart", |
| 264 "dart:async": "/lib/async/async.dart", | 273 "dart:async": "/lib/async/async.dart", |
| 265 "dart:collection": "/lib/collection/collection.dart", | 274 "dart:collection": "/lib/collection/collection.dart", |
| 266 "dart:convert": "/lib/convert/convert.dart", | 275 "dart:convert": "/lib/convert/convert.dart", |
| 267 "dart:math": "/lib/math/math.dart" | 276 "dart:math": "/lib/math/math.dart", |
| 277 "dart:_internal": "/lib/internal/internal.dart", |
| 268 }; | 278 }; |
| 269 | 279 |
| 270 String path = uriToPath[dartUri]; | 280 String path = uriToPath[dartUri]; |
| 271 if (path != null) { | 281 if (path != null) { |
| 272 resource.File file = provider.getResource(path); | 282 resource.File file = provider.getResource(path); |
| 273 Uri uri = new Uri(scheme: 'dart', path: dartUri.substring(5)); | 283 Uri uri = new Uri(scheme: 'dart', path: dartUri.substring(5)); |
| 274 return file.createSource(uri); | 284 return file.createSource(uri); |
| 275 } | 285 } |
| 276 | 286 |
| 277 // If we reach here then we tried to use a dartUri that's not in the | 287 // If we reach here then we tried to use a dartUri that's not in the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 293 @override | 303 @override |
| 294 bool get isDart2JsLibrary => throw unimplemented; | 304 bool get isDart2JsLibrary => throw unimplemented; |
| 295 | 305 |
| 296 @override | 306 @override |
| 297 bool get isDocumented => throw unimplemented; | 307 bool get isDocumented => throw unimplemented; |
| 298 | 308 |
| 299 @override | 309 @override |
| 300 bool get isImplementation => throw unimplemented; | 310 bool get isImplementation => throw unimplemented; |
| 301 | 311 |
| 302 @override | 312 @override |
| 303 bool get isInternal => throw unimplemented; | 313 bool get isInternal => shortName.startsWith('dart:_'); |
| 304 | 314 |
| 305 @override | 315 @override |
| 306 bool get isShared => throw unimplemented; | 316 bool get isShared => throw unimplemented; |
| 307 | 317 |
| 308 @override | 318 @override |
| 309 bool get isVmLibrary => throw unimplemented; | 319 bool get isVmLibrary => throw unimplemented; |
| 310 | 320 |
| 311 UnimplementedError get unimplemented => new UnimplementedError(); | 321 UnimplementedError get unimplemented => new UnimplementedError(); |
| 312 } | 322 } |
| OLD | NEW |