| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:analysis_server/protocol/protocol.dart'; | 8 import 'package:analysis_server/protocol/protocol.dart'; |
| 9 import 'package:analysis_server/protocol/protocol_generated.dart'; | 9 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
| 11 import 'package:analysis_server/src/channel/channel.dart'; | 11 import 'package:analysis_server/src/channel/channel.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart'; | |
| 13 import 'package:analyzer/file_system/file_system.dart' as resource; | 12 import 'package:analyzer/file_system/file_system.dart' as resource; |
| 14 import 'package:analyzer/file_system/memory_file_system.dart' as resource; | 13 import 'package:analyzer/file_system/memory_file_system.dart' as resource; |
| 15 import 'package:analyzer/source/package_map_provider.dart'; | 14 import 'package:analyzer/source/package_map_provider.dart'; |
| 16 import 'package:analyzer/source/pub_package_map_provider.dart'; | 15 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 17 import 'package:analyzer/src/generated/engine.dart'; | |
| 18 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 19 import 'package:mockito/mockito.dart'; | 17 import 'package:mockito/mockito.dart'; |
| 20 import 'package:test/test.dart'; | 18 import 'package:test/test.dart'; |
| 21 | 19 |
| 22 /** | 20 /** |
| 23 * Answer the absolute path the SDK relative to the currently running | 21 * Answer the absolute path the SDK relative to the currently running |
| 24 * script or throw an exception if it cannot be found. | 22 * script or throw an exception if it cannot be found. |
| 25 */ | 23 */ |
| 26 String get sdkPath { | 24 String get sdkPath { |
| 27 Uri sdkUri = Platform.script.resolve('../../../sdk/'); | 25 Uri sdkUri = Platform.script.resolve('../../../sdk/'); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 55 */ | 53 */ |
| 56 Future pumpEventQueue([int times = 5000]) { | 54 Future pumpEventQueue([int times = 5000]) { |
| 57 if (times == 0) return new Future.value(); | 55 if (times == 0) return new Future.value(); |
| 58 // We use a delayed future to allow microtask events to finish. The | 56 // We use a delayed future to allow microtask events to finish. The |
| 59 // Future.value or Future() constructors use scheduleMicrotask themselves and | 57 // Future.value or Future() constructors use scheduleMicrotask themselves and |
| 60 // would therefore not wait for microtask callbacks that are scheduled after | 58 // would therefore not wait for microtask callbacks that are scheduled after |
| 61 // invoking this method. | 59 // invoking this method. |
| 62 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); | 60 return new Future.delayed(Duration.ZERO, () => pumpEventQueue(times - 1)); |
| 63 } | 61 } |
| 64 | 62 |
| 65 typedef void MockServerOperationPerformFunction(AnalysisServer server); | |
| 66 | |
| 67 class MockAnalysisContext extends StringTypedMock implements AnalysisContext { | |
| 68 MockAnalysisContext(String name) : super(name); | |
| 69 } | |
| 70 | |
| 71 class MockClassElement extends Mock implements ClassElement { | |
| 72 final ElementKind kind = ElementKind.CLASS; | |
| 73 } | |
| 74 | |
| 75 class MockCompilationUnitElement extends Mock | |
| 76 implements CompilationUnitElement { | |
| 77 final ElementKind kind = ElementKind.COMPILATION_UNIT; | |
| 78 } | |
| 79 | |
| 80 class MockConstructorElement extends Mock implements ConstructorElement { | |
| 81 final kind = ElementKind.CONSTRUCTOR; | |
| 82 } | |
| 83 | |
| 84 class MockElement extends StringTypedMock implements Element { | |
| 85 MockElement([String name = '<element>']) : super(name); | |
| 86 | |
| 87 @override | |
| 88 String get displayName => _toString; | |
| 89 | |
| 90 @override | |
| 91 String get name => _toString; | |
| 92 } | |
| 93 | |
| 94 class MockFieldElement extends Mock implements FieldElement { | |
| 95 final ElementKind kind = ElementKind.FIELD; | |
| 96 } | |
| 97 | |
| 98 class MockFunctionElement extends Mock implements FunctionElement { | |
| 99 final ElementKind kind = ElementKind.FUNCTION; | |
| 100 } | |
| 101 | |
| 102 class MockFunctionTypeAliasElement extends Mock | |
| 103 implements FunctionTypeAliasElement { | |
| 104 final ElementKind kind = ElementKind.FUNCTION_TYPE_ALIAS; | |
| 105 } | |
| 106 | |
| 107 class MockImportElement extends Mock implements ImportElement { | |
| 108 final ElementKind kind = ElementKind.IMPORT; | |
| 109 } | |
| 110 | |
| 111 class MockLibraryElement extends Mock implements LibraryElement { | |
| 112 final ElementKind kind = ElementKind.LIBRARY; | |
| 113 } | |
| 114 | |
| 115 class MockLocalVariableElement extends Mock implements LocalVariableElement { | |
| 116 final ElementKind kind = ElementKind.LOCAL_VARIABLE; | |
| 117 } | |
| 118 | |
| 119 class MockLogger extends Mock implements Logger {} | |
| 120 | |
| 121 class MockMethodElement extends StringTypedMock implements MethodElement { | |
| 122 final kind = ElementKind.METHOD; | |
| 123 MockMethodElement([String name = 'method']) : super(name); | |
| 124 } | |
| 125 | |
| 126 /** | 63 /** |
| 127 * A mock [PackageMapProvider]. | 64 * A mock [PackageMapProvider]. |
| 128 */ | 65 */ |
| 129 class MockPackageMapProvider implements PubPackageMapProvider { | 66 class MockPackageMapProvider implements PubPackageMapProvider { |
| 130 /** | 67 /** |
| 131 * Package map that will be returned by the next call to [computePackageMap]. | 68 * Package map that will be returned by the next call to [computePackageMap]. |
| 132 */ | 69 */ |
| 133 Map<String, List<resource.Folder>> packageMap = | 70 Map<String, List<resource.Folder>> packageMap = |
| 134 <String, List<resource.Folder>>{}; | 71 <String, List<resource.Folder>>{}; |
| 135 | 72 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 156 } | 93 } |
| 157 return new PackageMapInfo(packageMap, dependencies); | 94 return new PackageMapInfo(packageMap, dependencies); |
| 158 } | 95 } |
| 159 | 96 |
| 160 noSuchMethod(Invocation invocation) { | 97 noSuchMethod(Invocation invocation) { |
| 161 // No other methods should be called. | 98 // No other methods should be called. |
| 162 return super.noSuchMethod(invocation); | 99 return super.noSuchMethod(invocation); |
| 163 } | 100 } |
| 164 } | 101 } |
| 165 | 102 |
| 166 class MockParameterElement extends Mock implements ParameterElement { | |
| 167 final ElementKind kind = ElementKind.PARAMETER; | |
| 168 } | |
| 169 | |
| 170 class MockPropertyAccessorElement extends Mock | |
| 171 implements PropertyAccessorElement { | |
| 172 final ElementKind kind; | |
| 173 MockPropertyAccessorElement(this.kind); | |
| 174 } | |
| 175 | |
| 176 /** | 103 /** |
| 177 * A mock [ServerCommunicationChannel] for testing [AnalysisServer]. | 104 * A mock [ServerCommunicationChannel] for testing [AnalysisServer]. |
| 178 */ | 105 */ |
| 179 class MockServerChannel implements ServerCommunicationChannel { | 106 class MockServerChannel implements ServerCommunicationChannel { |
| 180 StreamController<Request> requestController = new StreamController<Request>(); | 107 StreamController<Request> requestController = new StreamController<Request>(); |
| 181 StreamController<Response> responseController = | 108 StreamController<Response> responseController = |
| 182 new StreamController<Response>.broadcast(); | 109 new StreamController<Response>.broadcast(); |
| 183 StreamController<Notification> notificationController = | 110 StreamController<Notification> notificationController = |
| 184 new StreamController<Notification>(sync: true); | 111 new StreamController<Notification>(sync: true); |
| 185 | 112 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 212 |
| 286 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 213 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 287 | 214 |
| 288 Stream<T> where(bool test(dynamic t)) => stream.where((T data) => test(data)); | 215 Stream<T> where(bool test(dynamic t)) => stream.where((T data) => test(data)); |
| 289 } | 216 } |
| 290 | 217 |
| 291 class MockSource extends StringTypedMock implements Source { | 218 class MockSource extends StringTypedMock implements Source { |
| 292 MockSource([String name = 'mocked.dart']) : super(name); | 219 MockSource([String name = 'mocked.dart']) : super(name); |
| 293 } | 220 } |
| 294 | 221 |
| 295 class MockTopLevelVariableElement extends Mock | |
| 296 implements TopLevelVariableElement { | |
| 297 final ElementKind kind = ElementKind.TOP_LEVEL_VARIABLE; | |
| 298 } | |
| 299 | |
| 300 class MockTypeParameterElement extends Mock implements TypeParameterElement { | |
| 301 final ElementKind kind = ElementKind.TYPE_PARAMETER; | |
| 302 } | |
| 303 | |
| 304 class NoResponseException implements Exception { | |
| 305 /** | |
| 306 * The request that was not responded to. | |
| 307 */ | |
| 308 final Request request; | |
| 309 | |
| 310 NoResponseException(this.request); | |
| 311 | |
| 312 String toString() { | |
| 313 return "NoResponseException after request ${request.toJson()}"; | |
| 314 } | |
| 315 } | |
| 316 | |
| 317 class StringTypedMock extends Mock { | 222 class StringTypedMock extends Mock { |
| 318 String _toString; | 223 String _toString; |
| 319 | 224 |
| 320 StringTypedMock(this._toString); | 225 StringTypedMock(this._toString); |
| 321 | 226 |
| 322 @override | 227 @override |
| 323 String toString() { | 228 String toString() { |
| 324 if (_toString != null) { | 229 if (_toString != null) { |
| 325 return _toString; | 230 return _toString; |
| 326 } | 231 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 } | 311 } |
| 407 return mismatchDescription; | 312 return mismatchDescription; |
| 408 } | 313 } |
| 409 | 314 |
| 410 @override | 315 @override |
| 411 bool matches(item, Map matchState) { | 316 bool matches(item, Map matchState) { |
| 412 Response response = item; | 317 Response response = item; |
| 413 return response != null && response.id == _id && response.error == null; | 318 return response != null && response.id == _id && response.error == null; |
| 414 } | 319 } |
| 415 } | 320 } |
| OLD | NEW |