| 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 = | 15 final resource.MemoryResourceProvider provider = |
| 16 new resource.MemoryResourceProvider(); | 16 new resource.MemoryResourceProvider(); |
| 17 | 17 |
| 18 static const _MockSdkLibrary LIB_CORE = |
| 19 const _MockSdkLibrary('dart:core', '/lib/core/core.dart', ''' |
| 20 library dart.core; |
| 21 class Object {} |
| 22 class Function {} |
| 23 class StackTrace {} |
| 24 class Symbol {} |
| 25 class Type {} |
| 26 |
| 27 abstract class Comparable<T> { |
| 28 int compareTo(T other); |
| 29 } |
| 30 |
| 31 class String implements Comparable<String> { |
| 32 } |
| 33 |
| 34 class bool extends Object {} |
| 35 abstract class num implements Comparable<num> { |
| 36 num operator +(num other); |
| 37 num operator -(num other); |
| 38 num operator *(num other); |
| 39 num operator /(num other); |
| 40 int toInt(); |
| 41 } |
| 42 abstract class int extends num { |
| 43 int operator -(); |
| 44 } |
| 45 class double extends num {} |
| 46 class DateTime extends Object {} |
| 47 class Null extends Object {} |
| 48 |
| 49 class Deprecated extends Object { |
| 50 final String expires; |
| 51 const Deprecated(this.expires); |
| 52 } |
| 53 const Object deprecated = const Deprecated("next release"); |
| 54 |
| 55 abstract class List<E> extends Object { |
| 56 void add(E value); |
| 57 E operator [](int index); |
| 58 void operator []=(int index, E value); |
| 59 } |
| 60 class Map<K, V> extends Object {} |
| 61 |
| 62 void print(Object object) {} |
| 63 '''); |
| 64 |
| 65 static const _MockSdkLibrary LIB_ASYNC = |
| 66 const _MockSdkLibrary('dart:async', '/lib/async/async.dart', ''' |
| 67 library dart.async; |
| 68 class Future { |
| 69 static Future wait(List<Future> futures) => null; |
| 70 } |
| 71 |
| 72 class Stream<T> {} |
| 73 '''); |
| 74 |
| 75 static const _MockSdkLibrary LIB_MATH = |
| 76 const _MockSdkLibrary('dart:math', '/lib/math/math.dart', ''' |
| 77 library dart.math; |
| 78 const double E = 2.718281828459045; |
| 79 const double PI = 3.1415926535897932; |
| 80 '''); |
| 81 |
| 82 static const _MockSdkLibrary LIB_HTML = |
| 83 const _MockSdkLibrary('dart:html', '/lib/html/dartium/html_dartium.dart',
''' |
| 84 library dart.html; |
| 85 class HtmlElement {} |
| 86 '''); |
| 87 |
| 88 static const List<SdkLibrary> LIBRARIES = const [ |
| 89 LIB_CORE, |
| 90 LIB_ASYNC, |
| 91 LIB_MATH, |
| 92 LIB_HTML,]; |
| 93 |
| 18 MockSdk() { | 94 MockSdk() { |
| 19 // TODO(paulberry): Add to this as needed. | 95 LIBRARIES.forEach((_MockSdkLibrary library) { |
| 20 const Map<String, String> pathToContent = const { | 96 provider.newFile(library.path, library.content); |
| 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 abstract class Comparable<T> { | |
| 30 int compareTo(T other); | |
| 31 } | |
| 32 | |
| 33 class String implements Comparable<String> { | |
| 34 } | |
| 35 | |
| 36 class bool extends Object {} | |
| 37 abstract class num implements Comparable<num> { | |
| 38 num operator +(num other); | |
| 39 num operator -(num other); | |
| 40 num operator *(num other); | |
| 41 num operator /(num other); | |
| 42 int toInt(); | |
| 43 } | |
| 44 abstract class int extends num { | |
| 45 int operator -(); | |
| 46 } | |
| 47 class double extends num {} | |
| 48 class DateTime extends Object {} | |
| 49 class Null extends Object {} | |
| 50 | |
| 51 class Deprecated extends Object { | |
| 52 final String expires; | |
| 53 const Deprecated(this.expires); | |
| 54 } | |
| 55 const Object deprecated = const Deprecated("next release"); | |
| 56 | |
| 57 abstract class List<E> extends Object { | |
| 58 void add(E value); | |
| 59 E operator [](int index); | |
| 60 void operator []=(int index, E value); | |
| 61 } | |
| 62 class Map<K, V> extends Object {} | |
| 63 | |
| 64 void print(Object object) {} | |
| 65 ''', | |
| 66 | |
| 67 "/lib/html/dartium/html_dartium.dart": ''' | |
| 68 library dart.html; | |
| 69 class HtmlElement {} | |
| 70 ''', | |
| 71 | |
| 72 "/lib/async/async.dart": ''' | |
| 73 library dart.async; | |
| 74 class Future { | |
| 75 static Future wait(List<Future> futures) => null; | |
| 76 } | |
| 77 ''', | |
| 78 | |
| 79 "/lib/math/math.dart": ''' | |
| 80 library dart.math; | |
| 81 const double E = 2.718281828459045; | |
| 82 const double PI = 3.1415926535897932; | |
| 83 ''' | |
| 84 }; | |
| 85 | |
| 86 pathToContent.forEach((String path, String content) { | |
| 87 provider.newFile(path, content); | |
| 88 }); | 97 }); |
| 89 } | 98 } |
| 90 | 99 |
| 91 // Not used | 100 // Not used |
| 92 @override | 101 @override |
| 93 AnalysisContext get context => throw unimplemented; | 102 AnalysisContext get context => throw unimplemented; |
| 94 | 103 |
| 95 @override | 104 @override |
| 96 List<SdkLibrary> get sdkLibraries => throw unimplemented; | 105 List<SdkLibrary> get sdkLibraries => LIBRARIES; |
| 97 | 106 |
| 98 @override | 107 @override |
| 99 String get sdkVersion => throw unimplemented; | 108 String get sdkVersion => throw unimplemented; |
| 100 | 109 |
| 101 UnimplementedError get unimplemented => new UnimplementedError(); | 110 UnimplementedError get unimplemented => new UnimplementedError(); |
| 102 | 111 |
| 103 @override | 112 @override |
| 104 List<String> get uris => throw unimplemented; | 113 List<String> get uris => throw unimplemented; |
| 105 | 114 |
| 106 // Not used. | 115 // Not used. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 136 if (path != null) { | 145 if (path != null) { |
| 137 resource.File file = provider.getResource(path); | 146 resource.File file = provider.getResource(path); |
| 138 return file.createSource(UriKind.DART_URI); | 147 return file.createSource(UriKind.DART_URI); |
| 139 } | 148 } |
| 140 | 149 |
| 141 // 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 |
| 142 // table above. | 151 // table above. |
| 143 throw unimplemented; | 152 throw unimplemented; |
| 144 } | 153 } |
| 145 } | 154 } |
| 155 |
| 156 |
| 157 class _MockSdkLibrary implements SdkLibrary { |
| 158 final String shortName; |
| 159 final String path; |
| 160 final String content; |
| 161 |
| 162 const _MockSdkLibrary(this.shortName, this.path, this.content); |
| 163 |
| 164 @override |
| 165 String get category => throw unimplemented; |
| 166 |
| 167 @override |
| 168 bool get isDart2JsLibrary => throw unimplemented; |
| 169 |
| 170 @override |
| 171 bool get isDocumented => throw unimplemented; |
| 172 |
| 173 @override |
| 174 bool get isImplementation => throw unimplemented; |
| 175 |
| 176 @override |
| 177 bool get isInternal => throw unimplemented; |
| 178 |
| 179 @override |
| 180 bool get isShared => throw unimplemented; |
| 181 |
| 182 @override |
| 183 bool get isVmLibrary => throw unimplemented; |
| 184 |
| 185 UnimplementedError get unimplemented => new UnimplementedError(); |
| 186 } |
| OLD | NEW |