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 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:analysis_server/src/analysis_server.dart'; | 13 import 'package:analysis_server/src/analysis_server.dart'; |
| 14 import 'package:analysis_server/src/channel.dart'; | 14 import 'package:analysis_server/src/channel.dart'; |
| 15 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 15 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 16 import 'package:analysis_server/src/operation/operation.dart'; | 16 import 'package:analysis_server/src/operation/operation.dart'; |
| 17 import 'package:analysis_server/src/package_map_provider.dart'; | 17 import 'package:analysis_server/src/package_map_provider.dart'; |
| 18 import 'package:analysis_server/src/protocol.dart'; | 18 import 'package:analysis_server/src/protocol.dart'; |
| 19 import 'package:analysis_server/src/resource.dart' as resource; | 19 import 'package:analysis_server/src/resource.dart' as pres; |
|
Brian Wilkerson
2014/06/25 20:57:18
I don't know what "pres" means. I think prefixes s
scheglov
2014/06/25 21:13:38
Renamed back.
Problem is that later I declared a l
| |
| 20 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
| 21 import 'package:analyzer/src/generated/sdk.dart'; | 21 import 'package:analyzer/src/generated/sdk.dart'; |
| 22 import 'package:analyzer/src/generated/source.dart'; | 22 import 'package:analyzer/src/generated/source.dart'; |
| 23 import 'package:matcher/matcher.dart'; | 23 import 'package:matcher/matcher.dart'; |
| 24 import 'package:mock/mock.dart'; | 24 import 'package:mock/mock.dart'; |
| 25 import 'package:unittest/unittest.dart'; | 25 import 'package:unittest/unittest.dart'; |
| 26 import 'package:analyzer/src/generated/index.dart'; | |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Answer the absolute path the the SDK relative to the currently running | 29 * Answer the absolute path the the SDK relative to the currently running |
| 29 * script or throw an exception if it cannot be found. | 30 * script or throw an exception if it cannot be found. |
| 30 */ | 31 */ |
| 31 String get sdkPath { | 32 String get sdkPath { |
| 32 Uri sdkUri = Platform.script.resolve('../../../sdk/'); | 33 Uri sdkUri = Platform.script.resolve('../../../sdk/'); |
| 33 | 34 |
| 34 // Verify the directory exists | 35 // Verify the directory exists |
| 35 Directory sdkDir = new Directory.fromUri(sdkUri); | 36 Directory sdkDir = new Directory.fromUri(sdkUri); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 | 208 |
| 208 @override | 209 @override |
| 209 AnalysisContext get context => null; | 210 AnalysisContext get context => null; |
| 210 | 211 |
| 211 @override | 212 @override |
| 212 bool get isContinue => false; | 213 bool get isContinue => false; |
| 213 | 214 |
| 214 @override | 215 @override |
| 215 void sendNotices(AnalysisServer server, List<ChangeNotice> notices) { | 216 void sendNotices(AnalysisServer server, List<ChangeNotice> notices) { |
| 216 } | 217 } |
| 218 | |
| 219 @override | |
| 220 void updateIndex(Index index, List<ChangeNotice> notices) { | |
| 221 } | |
| 217 } | 222 } |
| 218 | 223 |
| 219 | 224 |
| 220 /** | 225 /** |
| 221 * A [Matcher] that check that the given [Response] has an expected identifier | 226 * A [Matcher] that check that the given [Response] has an expected identifier |
| 222 * and no error. | 227 * and no error. |
| 223 */ | 228 */ |
| 224 Matcher isResponseSuccess(String id) => new _IsResponseSuccess(id); | 229 Matcher isResponseSuccess(String id) => new _IsResponseSuccess(id); |
| 225 | 230 |
| 226 /** | 231 /** |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 mismatchDescription.add('has identifier "$id"'); | 298 mismatchDescription.add('has identifier "$id"'); |
| 294 if (error == null) { | 299 if (error == null) { |
| 295 mismatchDescription.add(' and has no error'); | 300 mismatchDescription.add(' and has no error'); |
| 296 } | 301 } |
| 297 return mismatchDescription; | 302 return mismatchDescription; |
| 298 } | 303 } |
| 299 } | 304 } |
| 300 | 305 |
| 301 class MockSdk implements DartSdk { | 306 class MockSdk implements DartSdk { |
| 302 | 307 |
| 303 final resource.MemoryResourceProvider provider = new resource.MemoryResourcePr ovider(); | 308 final pres.MemoryResourceProvider provider = new pres.MemoryResourceProvider() ; |
| 304 | 309 |
| 305 MockSdk() { | 310 MockSdk() { |
| 306 // TODO(paulberry): Add to this as needed. | 311 // TODO(paulberry): Add to this as needed. |
| 307 const Map<String, String> pathToSource = const { | 312 const Map<String, String> pathToContent = const { |
| 308 "/lib/core/core.dart": ''' | 313 "/lib/core/core.dart": ''' |
| 309 library dart.core; | 314 library dart.core; |
| 310 class Object {} | 315 class Object {} |
| 311 class Function {} | 316 class Function {} |
| 312 class StackTrace {} | 317 class StackTrace {} |
| 313 class Symbol {} | 318 class Symbol {} |
| 314 class Type {} | 319 class Type {} |
| 315 | 320 |
| 316 class String extends Object {} | 321 class String extends Object {} |
| 317 class bool extends Object {} | 322 class bool extends Object {} |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 347 "/lib/html/dartium/html_dartium.dart": ''' | 352 "/lib/html/dartium/html_dartium.dart": ''' |
| 348 library dart.html; | 353 library dart.html; |
| 349 class HtmlElement {} | 354 class HtmlElement {} |
| 350 ''', | 355 ''', |
| 351 | 356 |
| 352 "/lib/math/math.dart": ''' | 357 "/lib/math/math.dart": ''' |
| 353 library dart.math; | 358 library dart.math; |
| 354 ''' | 359 ''' |
| 355 }; | 360 }; |
| 356 | 361 |
| 357 pathToSource.forEach((String path, String source) { | 362 pathToContent.forEach((String path, String content) { |
| 358 provider.newFile(path, source); | 363 provider.newFile(path, content); |
| 359 }); | 364 }); |
| 360 } | 365 } |
| 361 | 366 |
| 362 // Not used | 367 // Not used |
| 363 @override | 368 @override |
| 364 AnalysisContext get context => throw unimplemented; | 369 AnalysisContext get context => throw unimplemented; |
| 365 | 370 |
| 366 @override | 371 @override |
| 367 Source fromEncoding(UriKind kind, Uri uri) { | 372 Source fromEncoding(UriKind kind, Uri uri) { |
| 368 // Not used | 373 pres.Resource resource = provider.getResource(uri.path); |
| 369 throw unimplemented; | 374 if (resource is pres.File) { |
| 375 return resource.createSource(kind); | |
| 376 } | |
| 377 return null; | |
| 370 } | 378 } |
| 371 | 379 |
| 372 UnimplementedError get unimplemented => new UnimplementedError(); | 380 UnimplementedError get unimplemented => new UnimplementedError(); |
| 373 | 381 |
| 374 @override | 382 @override |
| 375 SdkLibrary getSdkLibrary(String dartUri) { | 383 SdkLibrary getSdkLibrary(String dartUri) { |
| 376 // getSdkLibrary() is only used to determine whether a library is internal | 384 // 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 | 385 // to the SDK. The mock SDK doesn't have any internals, so it's safe to |
| 378 // return null. | 386 // return null. |
| 379 return null; | 387 return null; |
| 380 } | 388 } |
| 381 | 389 |
| 382 @override | 390 @override |
| 383 Source mapDartUri(String dartUri) { | 391 Source mapDartUri(String dartUri) { |
| 384 const Map<String, String> uriToPath = const { | 392 const Map<String, String> uriToPath = const { |
| 385 "dart:core": "/lib/core/core.dart", | 393 "dart:core": "/lib/core/core.dart", |
| 386 "dart:html": "/lib/html/dartium/html_dartium.dart", | 394 "dart:html": "/lib/html/dartium/html_dartium.dart", |
| 387 "dart:math": "/lib/math/math.dart" | 395 "dart:math": "/lib/math/math.dart" |
| 388 }; | 396 }; |
| 389 | 397 |
| 390 String path = uriToPath[dartUri]; | 398 String path = uriToPath[dartUri]; |
| 391 if (path != null) { | 399 if (path != null) { |
| 392 resource.File file = provider.getResource(path); | 400 pres.File file = provider.getResource(path); |
| 393 return file.createSource(UriKind.DART_URI); | 401 return file.createSource(UriKind.DART_URI); |
| 394 } | 402 } |
| 395 | 403 |
| 396 // If we reach here then we tried to use a dartUri that's not in the | 404 // If we reach here then we tried to use a dartUri that's not in the |
| 397 // table above. | 405 // table above. |
| 398 throw unimplemented; | 406 throw unimplemented; |
| 399 } | 407 } |
| 400 | 408 |
| 401 // Not used. | 409 // Not used. |
| 402 @override | 410 @override |
| 403 List<SdkLibrary> get sdkLibraries => throw unimplemented; | 411 List<SdkLibrary> get sdkLibraries => throw unimplemented; |
| 404 | 412 |
| 405 // Not used. | 413 // Not used. |
| 406 @override | 414 @override |
| 407 String get sdkVersion => throw unimplemented; | 415 String get sdkVersion => throw unimplemented; |
| 408 | 416 |
| 409 // Not used. | 417 // Not used. |
| 410 @override | 418 @override |
| 411 List<String> get uris => throw unimplemented; | 419 List<String> get uris => throw unimplemented; |
| 412 } | 420 } |
| 413 | 421 |
| 414 /** | 422 /** |
| 415 * A mock [PackageMapProvider]. | 423 * A mock [PackageMapProvider]. |
| 416 */ | 424 */ |
| 417 class MockPackageMapProvider implements PackageMapProvider { | 425 class MockPackageMapProvider implements PackageMapProvider { |
| 418 Map<String, List<resource.Folder>> packageMap = <String, List<resource.Folder> >{}; | 426 Map<String, List<pres.Folder>> packageMap = <String, List<pres.Folder>>{}; |
| 419 | 427 |
| 420 @override | 428 @override |
| 421 Map<String, List<resource.Folder>> computePackageMap(resource.Folder folder) { | 429 Map<String, List<pres.Folder>> computePackageMap(pres.Folder folder) { |
| 422 return packageMap; | 430 return packageMap; |
| 423 } | 431 } |
| 424 } | 432 } |
| OLD | NEW |