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 mocks; | 5 library mocks; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 @MirrorsUsed(targets: 'mocks', override: '*') | 10 @MirrorsUsed(targets: 'mocks', override: '*') |
11 import 'dart:mirrors'; | 11 import 'dart:mirrors'; |
12 | 12 |
13 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 14 import 'package:analyzer/src/generated/sdk.dart'; |
| 15 import 'package:analyzer/src/generated/sdk_io.dart'; |
14 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
15 import 'package:analysis_server/src/analysis_server.dart'; | 17 import 'package:analysis_server/src/analysis_server.dart'; |
16 import 'package:analysis_server/src/channel.dart'; | 18 import 'package:analysis_server/src/channel.dart'; |
17 import 'package:analysis_server/src/protocol.dart'; | 19 import 'package:analysis_server/src/protocol.dart'; |
| 20 import 'package:analysis_server/src/resource.dart' as resource; |
18 import 'package:matcher/matcher.dart'; | 21 import 'package:matcher/matcher.dart'; |
19 import 'package:mock/mock.dart'; | 22 import 'package:mock/mock.dart'; |
20 import 'package:unittest/unittest.dart'; | 23 import 'package:unittest/unittest.dart'; |
21 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 24 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
22 import 'package:analysis_server/src/operation/operation.dart'; | 25 import 'package:analysis_server/src/operation/operation.dart'; |
23 | 26 |
24 /** | 27 /** |
25 * Answer the absolute path the the SDK relative to the currently running | 28 * Answer the absolute path the the SDK relative to the currently running |
26 * script or throw an exception if it cannot be found. | 29 * script or throw an exception if it cannot be found. |
27 */ | 30 */ |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 Response response = item; | 290 Response response = item; |
288 var id = response.id; | 291 var id = response.id; |
289 RequestError error = response.error; | 292 RequestError error = response.error; |
290 mismatchDescription.add('has identifier "$id"'); | 293 mismatchDescription.add('has identifier "$id"'); |
291 if (error == null) { | 294 if (error == null) { |
292 mismatchDescription.add(' and has no error'); | 295 mismatchDescription.add(' and has no error'); |
293 } | 296 } |
294 return mismatchDescription; | 297 return mismatchDescription; |
295 } | 298 } |
296 } | 299 } |
| 300 |
| 301 class MockSdk implements DartSdk { |
| 302 |
| 303 final resource.MemoryResourceProvider provider = new resource.MemoryResourcePr
ovider(); |
| 304 |
| 305 MockSdk() { |
| 306 // TODO(paulberry): Add to this as needed. |
| 307 const Map<String, String> pathToSource = const { |
| 308 "/lib/core/core.dart": ''' |
| 309 library dart.core; |
| 310 class Object {} |
| 311 class Function {} |
| 312 class StackTrace {} |
| 313 class Symbol {} |
| 314 class Type {} |
| 315 |
| 316 class String extends Object {} |
| 317 class bool extends Object {} |
| 318 abstract class num extends Object { |
| 319 num operator +(num other); |
| 320 num operator -(num other); |
| 321 num operator *(num other); |
| 322 num operator /(num other); |
| 323 } |
| 324 abstract class int extends num { |
| 325 int operator -(); |
| 326 } |
| 327 class double extends num {} |
| 328 class DateTime extends Object {} |
| 329 class Null extends Object {} |
| 330 |
| 331 class Deprecated extends Object { |
| 332 final String expires; |
| 333 const Deprecated(this.expires); |
| 334 } |
| 335 const Object deprecated = const Deprecated("next release"); |
| 336 |
| 337 abstract class List<E> extends Object { |
| 338 void add(E value); |
| 339 E operator [](int index); |
| 340 void operator []=(int index, E value); |
| 341 } |
| 342 class Map<K, V> extends Object {} |
| 343 |
| 344 void print(Object object) {} |
| 345 ''', |
| 346 |
| 347 "/lib/html/dartium/html_dartium.dart": ''' |
| 348 library dart.html; |
| 349 class HtmlElement {} |
| 350 ''', |
| 351 |
| 352 "/lib/math/math.dart": ''' |
| 353 library dart.math; |
| 354 ''' |
| 355 }; |
| 356 |
| 357 pathToSource.forEach((String path, String source) { |
| 358 provider.newFile(path, source); |
| 359 }); |
| 360 } |
| 361 |
| 362 // Not used |
| 363 @override |
| 364 AnalysisContext get context => throw unimplemented; |
| 365 |
| 366 @override |
| 367 Source fromEncoding(UriKind kind, Uri uri) { |
| 368 // Not used |
| 369 throw unimplemented; |
| 370 } |
| 371 |
| 372 UnimplementedError get unimplemented => new UnimplementedError(); |
| 373 |
| 374 @override |
| 375 SdkLibrary getSdkLibrary(String dartUri) { |
| 376 // getSdkLibrary() is only used to determine whether a library is internal |
| 377 // to the SDK. The mock SDK doesn't have any internals, so it's safe to |
| 378 // return null. |
| 379 return null; |
| 380 } |
| 381 |
| 382 @override |
| 383 Source mapDartUri(String dartUri) { |
| 384 const Map<String, String> uriToPath = const { |
| 385 "dart:core": "/lib/core/core.dart", |
| 386 "dart:html": "/lib/html/dartium/html_dartium.dart", |
| 387 "dart:math": "/lib/math/math.dart" |
| 388 }; |
| 389 |
| 390 String path = uriToPath[dartUri]; |
| 391 if (path != null) { |
| 392 resource.File file = provider.getResource(path); |
| 393 return file.createSource(UriKind.DART_URI); |
| 394 } |
| 395 |
| 396 // If we reach here then we tried to use a dartUri that's not in the |
| 397 // table above. |
| 398 throw unimplemented; |
| 399 } |
| 400 |
| 401 // Not used. |
| 402 @override |
| 403 List<SdkLibrary> get sdkLibraries => throw unimplemented; |
| 404 |
| 405 // Not used. |
| 406 @override |
| 407 String get sdkVersion => throw unimplemented; |
| 408 |
| 409 // Not used. |
| 410 @override |
| 411 List<String> get uris => throw unimplemented; |
| 412 } |
| 413 |
OLD | NEW |