| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library testing.mock_sdk; |
| 6 |
| 7 import 'package:analyzer/file_system/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'; |
| 10 import 'package:analyzer/src/generated/sdk.dart'; |
| 11 import 'package:analyzer/src/generated/source.dart'; |
| 12 |
| 13 |
| 14 class MockSdk implements DartSdk { |
| 15 final resource.MemoryResourceProvider provider = |
| 16 new resource.MemoryResourceProvider(); |
| 17 |
| 18 MockSdk() { |
| 19 // TODO(paulberry): Add to this as needed. |
| 20 const Map<String, String> pathToContent = const { |
| 21 "/lib/core/core.dart": ''' |
| 22 library dart.core; |
| 23 class Object {} |
| 24 class Function {} |
| 25 class StackTrace {} |
| 26 class Symbol {} |
| 27 class Type {} |
| 28 |
| 29 class String extends Object {} |
| 30 class bool extends Object {} |
| 31 abstract class num extends Object { |
| 32 num operator +(num other); |
| 33 num operator -(num other); |
| 34 num operator *(num other); |
| 35 num operator /(num other); |
| 36 } |
| 37 abstract class int extends num { |
| 38 int operator -(); |
| 39 } |
| 40 class double extends num {} |
| 41 class DateTime extends Object {} |
| 42 class Null extends Object {} |
| 43 |
| 44 class Deprecated extends Object { |
| 45 final String expires; |
| 46 const Deprecated(this.expires); |
| 47 } |
| 48 const Object deprecated = const Deprecated("next release"); |
| 49 |
| 50 abstract class List<E> extends Object { |
| 51 void add(E value); |
| 52 E operator [](int index); |
| 53 void operator []=(int index, E value); |
| 54 } |
| 55 class Map<K, V> extends Object {} |
| 56 |
| 57 void print(Object object) {} |
| 58 ''', |
| 59 |
| 60 "/lib/html/dartium/html_dartium.dart": ''' |
| 61 library dart.html; |
| 62 class HtmlElement {} |
| 63 ''', |
| 64 |
| 65 "/lib/math/math.dart": ''' |
| 66 library dart.math; |
| 67 ''' |
| 68 }; |
| 69 |
| 70 pathToContent.forEach((String path, String content) { |
| 71 provider.newFile(path, content); |
| 72 }); |
| 73 } |
| 74 |
| 75 // Not used |
| 76 @override |
| 77 AnalysisContext get context => throw unimplemented; |
| 78 |
| 79 @override |
| 80 List<SdkLibrary> get sdkLibraries => throw unimplemented; |
| 81 |
| 82 @override |
| 83 String get sdkVersion => throw unimplemented; |
| 84 |
| 85 UnimplementedError get unimplemented => new UnimplementedError(); |
| 86 |
| 87 @override |
| 88 List<String> get uris => throw unimplemented; |
| 89 |
| 90 // Not used. |
| 91 @override |
| 92 Source fromEncoding(UriKind kind, Uri uri) { |
| 93 resource.Resource file = provider.getResource(uri.path); |
| 94 if (file is resource.File) { |
| 95 return file.createSource(kind); |
| 96 } |
| 97 return null; |
| 98 } |
| 99 |
| 100 // Not used. |
| 101 @override |
| 102 SdkLibrary getSdkLibrary(String dartUri) { |
| 103 // getSdkLibrary() is only used to determine whether a library is internal |
| 104 // to the SDK. The mock SDK doesn't have any internals, so it's safe to |
| 105 // return null. |
| 106 return null; |
| 107 } |
| 108 |
| 109 // Not used. |
| 110 @override |
| 111 Source mapDartUri(String dartUri) { |
| 112 const Map<String, String> uriToPath = const { |
| 113 "dart:core": "/lib/core/core.dart", |
| 114 "dart:html": "/lib/html/dartium/html_dartium.dart", |
| 115 "dart:math": "/lib/math/math.dart" |
| 116 }; |
| 117 |
| 118 String path = uriToPath[dartUri]; |
| 119 if (path != null) { |
| 120 resource.File file = provider.getResource(path); |
| 121 return file.createSource(UriKind.DART_URI); |
| 122 } |
| 123 |
| 124 // If we reach here then we tried to use a dartUri that's not in the |
| 125 // table above. |
| 126 throw unimplemented; |
| 127 } |
| 128 } |
| OLD | NEW |