| 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 static const _MockSdkLibrary LIB_CORE = | 15 static const _MockSdkLibrary LIB_CORE = |
| 16 const _MockSdkLibrary('core', '/lib/core/core.dart', ''' | 16 const _MockSdkLibrary('dart:core', '/lib/core/core.dart', ''' |
| 17 library dart.core; | 17 library dart.core; |
| 18 | 18 |
| 19 import 'dart:async'; |
| 20 |
| 19 class Object { | 21 class Object { |
| 20 bool operator ==(other) => identical(this, other); | 22 bool operator ==(other) => identical(this, other); |
| 21 } | 23 } |
| 22 | 24 |
| 23 class Function {} | 25 class Function {} |
| 24 class StackTrace {} | 26 class StackTrace {} |
| 25 class Symbol {} | 27 class Symbol {} |
| 26 class Type {} | 28 class Type {} |
| 27 | 29 |
| 28 abstract class Comparable<T> { | 30 abstract class Comparable<T> { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 void operator []=(int index, E value); | 66 void operator []=(int index, E value); |
| 65 } | 67 } |
| 66 class Map<K, V> extends Object {} | 68 class Map<K, V> extends Object {} |
| 67 | 69 |
| 68 external bool identical(Object a, Object b); | 70 external bool identical(Object a, Object b); |
| 69 | 71 |
| 70 void print(Object object) {} | 72 void print(Object object) {} |
| 71 '''); | 73 '''); |
| 72 | 74 |
| 73 static const _MockSdkLibrary LIB_ASYNC = | 75 static const _MockSdkLibrary LIB_ASYNC = |
| 74 const _MockSdkLibrary('async', '/lib/async/async.dart', ''' | 76 const _MockSdkLibrary('dart:async', '/lib/async/async.dart', ''' |
| 75 library dart.async; | 77 library dart.async; |
| 78 |
| 79 import 'dart:math'; |
| 80 |
| 76 class Future { | 81 class Future { |
| 77 static Future wait(List<Future> futures) => null; | 82 static Future wait(List<Future> futures) => null; |
| 78 } | 83 } |
| 79 | 84 |
| 80 class Stream<T> {} | 85 class Stream<T> {} |
| 81 '''); | 86 '''); |
| 82 | 87 |
| 83 static const _MockSdkLibrary LIB_MATH = | 88 static const _MockSdkLibrary LIB_MATH = |
| 84 const _MockSdkLibrary('math', '/lib/math/math.dart', ''' | 89 const _MockSdkLibrary('dart:math', '/lib/math/math.dart', ''' |
| 85 library dart.math; | 90 library dart.math; |
| 86 const double E = 2.718281828459045; | 91 const double E = 2.718281828459045; |
| 87 const double PI = 3.1415926535897932; | 92 const double PI = 3.1415926535897932; |
| 88 num min(num a, num b) => 0; | 93 num min(num a, num b) => 0; |
| 89 num max(num a, num b) => 0; | 94 num max(num a, num b) => 0; |
| 90 class Random {} | 95 class Random {} |
| 91 '''); | 96 '''); |
| 92 | 97 |
| 93 static const _MockSdkLibrary LIB_HTML = | 98 static const _MockSdkLibrary LIB_HTML = |
| 94 const _MockSdkLibrary('html', '/lib/html/dartium/html_dartium.dart', ''' | 99 const _MockSdkLibrary('dart:html', '/lib/html/dartium/html_dartium.dart',
''' |
| 95 library dart.html; | 100 library dart.html; |
| 96 class HtmlElement {} | 101 class HtmlElement {} |
| 97 '''); | 102 '''); |
| 98 | 103 |
| 99 static const List<SdkLibrary> LIBRARIES = const [ | 104 static const List<SdkLibrary> LIBRARIES = const [ |
| 100 LIB_CORE, | 105 LIB_CORE, |
| 101 LIB_ASYNC, | 106 LIB_ASYNC, |
| 102 LIB_MATH, | 107 LIB_MATH, |
| 103 LIB_HTML,]; | 108 LIB_HTML,]; |
| 104 | 109 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 131 String libPath = '/lib'; | 136 String libPath = '/lib'; |
| 132 if (!filePath.startsWith("$libPath/")) { | 137 if (!filePath.startsWith("$libPath/")) { |
| 133 return null; | 138 return null; |
| 134 } | 139 } |
| 135 for (SdkLibrary library in LIBRARIES) { | 140 for (SdkLibrary library in LIBRARIES) { |
| 136 String libraryPath = library.path; | 141 String libraryPath = library.path; |
| 137 if (filePath.replaceAll('\\', '/') == libraryPath) { | 142 if (filePath.replaceAll('\\', '/') == libraryPath) { |
| 138 String path = library.shortName; | 143 String path = library.shortName; |
| 139 try { | 144 try { |
| 140 resource.File file = provider.getResource(uri.path); | 145 resource.File file = provider.getResource(uri.path); |
| 141 Uri dartUri = new Uri(scheme: 'dart', path: library.shortName); | 146 Uri dartUri = new Uri(scheme: 'dart', path: path); |
| 142 return file.createSource(dartUri); | 147 return file.createSource(dartUri); |
| 143 } catch (exception) { | 148 } catch (exception) { |
| 144 return null; | 149 return null; |
| 145 } | 150 } |
| 146 } | 151 } |
| 147 if (filePath.startsWith("$libraryPath/")) { | 152 if (filePath.startsWith("$libraryPath/")) { |
| 148 String pathInLibrary = filePath.substring(libraryPath.length + 1); | 153 String pathInLibrary = filePath.substring(libraryPath.length + 1); |
| 149 String path = '${library.shortName}/${pathInLibrary}'; | 154 String path = '${library.shortName}/${pathInLibrary}'; |
| 150 try { | 155 try { |
| 151 resource.File file = provider.getResource(uri.path); | 156 resource.File file = provider.getResource(uri.path); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 bool get isInternal => throw unimplemented; | 218 bool get isInternal => throw unimplemented; |
| 214 | 219 |
| 215 @override | 220 @override |
| 216 bool get isShared => throw unimplemented; | 221 bool get isShared => throw unimplemented; |
| 217 | 222 |
| 218 @override | 223 @override |
| 219 bool get isVmLibrary => throw unimplemented; | 224 bool get isVmLibrary => throw unimplemented; |
| 220 | 225 |
| 221 UnimplementedError get unimplemented => new UnimplementedError(); | 226 UnimplementedError get unimplemented => new UnimplementedError(); |
| 222 } | 227 } |
| OLD | NEW |