Chromium Code Reviews| 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 import 'package:path/path.dart'; | |
| 12 | 13 |
| 13 | 14 |
| 14 class MockSdk implements DartSdk { | 15 class MockSdk implements DartSdk { |
| 15 static const _MockSdkLibrary LIB_CORE = | 16 static const _MockSdkLibrary LIB_CORE = |
| 16 const _MockSdkLibrary('dart:core', '/lib/core/core.dart', ''' | 17 const _MockSdkLibrary('core', '/lib/core/core.dart', ''' |
| 17 library dart.core; | 18 library dart.core; |
| 18 | 19 |
| 19 class Object { | 20 class Object { |
| 20 bool operator ==(other) => identical(this, other); | 21 bool operator ==(other) => identical(this, other); |
| 21 } | 22 } |
| 22 | 23 |
| 23 class Function {} | 24 class Function {} |
| 24 class StackTrace {} | 25 class StackTrace {} |
| 25 class Symbol {} | 26 class Symbol {} |
| 26 class Type {} | 27 class Type {} |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 void operator []=(int index, E value); | 63 void operator []=(int index, E value); |
| 63 } | 64 } |
| 64 class Map<K, V> extends Object {} | 65 class Map<K, V> extends Object {} |
| 65 | 66 |
| 66 external bool identical(Object a, Object b); | 67 external bool identical(Object a, Object b); |
| 67 | 68 |
| 68 void print(Object object) {} | 69 void print(Object object) {} |
| 69 '''); | 70 '''); |
| 70 | 71 |
| 71 static const _MockSdkLibrary LIB_ASYNC = | 72 static const _MockSdkLibrary LIB_ASYNC = |
| 72 const _MockSdkLibrary('dart:async', '/lib/async/async.dart', ''' | 73 const _MockSdkLibrary('async', '/lib/async/async.dart', ''' |
|
Brian Wilkerson
2014/08/06 22:07:55
If this is the name of the library, then it should
scheglov
2014/08/06 22:13:06
It's a short library name, not a library identifie
| |
| 73 library dart.async; | 74 library dart.async; |
| 74 class Future { | 75 class Future { |
| 75 static Future wait(List<Future> futures) => null; | 76 static Future wait(List<Future> futures) => null; |
| 76 } | 77 } |
| 77 | 78 |
| 78 class Stream<T> {} | 79 class Stream<T> {} |
| 79 '''); | 80 '''); |
| 80 | 81 |
| 81 static const _MockSdkLibrary LIB_MATH = | 82 static const _MockSdkLibrary LIB_MATH = |
| 82 const _MockSdkLibrary('dart:math', '/lib/math/math.dart', ''' | 83 const _MockSdkLibrary('math', '/lib/math/math.dart', ''' |
| 83 library dart.math; | 84 library dart.math; |
| 84 const double E = 2.718281828459045; | 85 const double E = 2.718281828459045; |
| 85 const double PI = 3.1415926535897932; | 86 const double PI = 3.1415926535897932; |
| 86 num min(num a, num b) => 0; | 87 num min(num a, num b) => 0; |
| 87 num max(num a, num b) => 0; | 88 num max(num a, num b) => 0; |
| 88 '''); | 89 '''); |
| 89 | 90 |
| 90 static const _MockSdkLibrary LIB_HTML = | 91 static const _MockSdkLibrary LIB_HTML = |
| 91 const _MockSdkLibrary('dart:html', '/lib/html/dartium/html_dartium.dart', ''' | 92 const _MockSdkLibrary('html', '/lib/html/dartium/html_dartium.dart', ''' |
| 92 library dart.html; | 93 library dart.html; |
| 93 class HtmlElement {} | 94 class HtmlElement {} |
| 94 '''); | 95 '''); |
| 95 | 96 |
| 96 static const List<SdkLibrary> LIBRARIES = const [ | 97 static const List<SdkLibrary> LIBRARIES = const [ |
| 97 LIB_CORE, | 98 LIB_CORE, |
| 98 LIB_ASYNC, | 99 LIB_ASYNC, |
| 99 LIB_MATH, | 100 LIB_MATH, |
| 100 LIB_HTML,]; | 101 LIB_HTML,]; |
| 101 | 102 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 117 @override | 118 @override |
| 118 String get sdkVersion => throw unimplemented; | 119 String get sdkVersion => throw unimplemented; |
| 119 | 120 |
| 120 UnimplementedError get unimplemented => new UnimplementedError(); | 121 UnimplementedError get unimplemented => new UnimplementedError(); |
| 121 | 122 |
| 122 @override | 123 @override |
| 123 List<String> get uris => throw unimplemented; | 124 List<String> get uris => throw unimplemented; |
| 124 | 125 |
| 125 @override | 126 @override |
| 126 Source fromFileUri(Uri uri) { | 127 Source fromFileUri(Uri uri) { |
| 127 resource.Resource file = provider.getResource(uri.path); | 128 String filePath = uri.path; |
| 128 if (file is resource.File) { | 129 String libPath = '/lib'; |
| 129 return file.createSource(uri); | 130 if (!filePath.startsWith("$libPath/")) { |
| 131 return null; | |
| 132 } | |
| 133 for (SdkLibrary library in LIBRARIES) { | |
| 134 String libraryPath = library.path; | |
| 135 if (filePath.replaceAll('\\', '/') == libraryPath) { | |
| 136 String path = library.shortName; | |
| 137 try { | |
| 138 resource.File file = provider.getResource(uri.path); | |
| 139 Uri dartUri = new Uri(scheme: 'dart', path: library.shortName); | |
| 140 return file.createSource(dartUri); | |
| 141 } catch (exception) { | |
| 142 return null; | |
| 143 } | |
| 144 } | |
| 145 if (filePath.startsWith("$libraryPath/")) { | |
| 146 String pathInLibrary = filePath.substring(libraryPath.length + 1); | |
| 147 String path = '${library.shortName}/${pathInLibrary}'; | |
| 148 try { | |
| 149 resource.File file = provider.getResource(uri.path); | |
| 150 Uri dartUri = new Uri(scheme: 'dart', path: path); | |
| 151 return file.createSource(dartUri); | |
| 152 } catch (exception) { | |
| 153 return null; | |
| 154 } | |
| 155 } | |
| 130 } | 156 } |
| 131 return null; | 157 return null; |
| 132 } | 158 } |
| 133 | 159 |
| 134 @override | 160 @override |
| 135 SdkLibrary getSdkLibrary(String dartUri) { | 161 SdkLibrary getSdkLibrary(String dartUri) { |
| 136 // getSdkLibrary() is only used to determine whether a library is internal | 162 // getSdkLibrary() is only used to determine whether a library is internal |
| 137 // to the SDK. The mock SDK doesn't have any internals, so it's safe to | 163 // to the SDK. The mock SDK doesn't have any internals, so it's safe to |
| 138 // return null. | 164 // return null. |
| 139 return null; | 165 return null; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 bool get isInternal => throw unimplemented; | 211 bool get isInternal => throw unimplemented; |
| 186 | 212 |
| 187 @override | 213 @override |
| 188 bool get isShared => throw unimplemented; | 214 bool get isShared => throw unimplemented; |
| 189 | 215 |
| 190 @override | 216 @override |
| 191 bool get isVmLibrary => throw unimplemented; | 217 bool get isVmLibrary => throw unimplemented; |
| 192 | 218 |
| 193 UnimplementedError get unimplemented => new UnimplementedError(); | 219 UnimplementedError get unimplemented => new UnimplementedError(); |
| 194 } | 220 } |
| OLD | NEW |