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 import 'package:analysis_server/plugin/protocol/protocol.dart' | 10 import 'package:analysis_server/plugin/protocol/protocol.dart' |
11 hide Element, ElementKind; | 11 hide Element, ElementKind; |
12 import 'package:analysis_server/src/analysis_server.dart'; | 12 import 'package:analysis_server/src/analysis_server.dart'; |
13 import 'package:analysis_server/src/channel/channel.dart'; | 13 import 'package:analysis_server/src/channel/channel.dart'; |
14 import 'package:analysis_server/src/operation/operation.dart'; | 14 import 'package:analysis_server/src/operation/operation.dart'; |
15 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 15 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
16 import 'package:analyzer/dart/element/element.dart'; | 16 import 'package:analyzer/dart/element/element.dart'; |
17 import 'package:analyzer/file_system/file_system.dart' as resource; | |
18 import 'package:analyzer/file_system/memory_file_system.dart' as resource; | |
19 import 'package:analyzer/source/package_map_provider.dart'; | |
20 import 'package:analyzer/source/pub_package_map_provider.dart'; | |
21 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
22 import 'package:analyzer/src/generated/source.dart'; | 18 import 'package:analyzer/src/generated/source.dart'; |
23 import 'package:typed_mock/typed_mock.dart'; | 19 import 'package:typed_mock/typed_mock.dart'; |
24 import 'package:unittest/unittest.dart'; | 20 import 'package:unittest/unittest.dart'; |
25 | 21 |
26 /** | 22 /** |
27 * Answer the absolute path the SDK relative to the currently running | 23 * Answer the absolute path the SDK relative to the currently running |
28 * script or throw an exception if it cannot be found. | 24 * script or throw an exception if it cannot be found. |
29 */ | 25 */ |
30 String get sdkPath { | 26 String get sdkPath { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 final ElementKind kind = ElementKind.LOCAL_VARIABLE; | 117 final ElementKind kind = ElementKind.LOCAL_VARIABLE; |
122 } | 118 } |
123 | 119 |
124 class MockLogger extends TypedMock implements Logger {} | 120 class MockLogger extends TypedMock implements Logger {} |
125 | 121 |
126 class MockMethodElement extends StringTypedMock implements MethodElement { | 122 class MockMethodElement extends StringTypedMock implements MethodElement { |
127 final kind = ElementKind.METHOD; | 123 final kind = ElementKind.METHOD; |
128 MockMethodElement([String name = 'method']) : super(name); | 124 MockMethodElement([String name = 'method']) : super(name); |
129 } | 125 } |
130 | 126 |
131 /** | |
132 * A mock [PackageMapProvider]. | |
133 */ | |
134 class MockPackageMapProvider implements PubPackageMapProvider { | |
135 /** | |
136 * Package map that will be returned by the next call to [computePackageMap]. | |
137 */ | |
138 Map<String, List<resource.Folder>> packageMap = | |
139 <String, List<resource.Folder>>{}; | |
140 | |
141 /** | |
142 * Package maps that will be returned by the next call to [computePackageMap]. | |
143 */ | |
144 Map<String, Map<String, List<resource.Folder>>> packageMaps = null; | |
145 | |
146 /** | |
147 * Dependency list that will be returned by the next call to [computePackageMa
p]. | |
148 */ | |
149 Set<String> dependencies = new Set<String>(); | |
150 | |
151 /** | |
152 * Number of times [computePackageMap] has been called. | |
153 */ | |
154 int computeCount = 0; | |
155 | |
156 @override | |
157 PackageMapInfo computePackageMap(resource.Folder folder) { | |
158 ++computeCount; | |
159 if (packageMaps != null) { | |
160 return new PackageMapInfo(packageMaps[folder.path], dependencies); | |
161 } | |
162 return new PackageMapInfo(packageMap, dependencies); | |
163 } | |
164 | |
165 noSuchMethod(Invocation invocation) { | |
166 // No other methods should be called. | |
167 return super.noSuchMethod(invocation); | |
168 } | |
169 } | |
170 | |
171 class MockParameterElement extends TypedMock implements ParameterElement { | 127 class MockParameterElement extends TypedMock implements ParameterElement { |
172 final ElementKind kind = ElementKind.PARAMETER; | 128 final ElementKind kind = ElementKind.PARAMETER; |
173 } | 129 } |
174 | 130 |
175 class MockPropertyAccessorElement extends TypedMock | 131 class MockPropertyAccessorElement extends TypedMock |
176 implements PropertyAccessorElement { | 132 implements PropertyAccessorElement { |
177 final ElementKind kind; | 133 final ElementKind kind; |
178 MockPropertyAccessorElement(this.kind); | 134 MockPropertyAccessorElement(this.kind); |
179 } | 135 } |
180 | 136 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 } | 387 } |
432 return mismatchDescription; | 388 return mismatchDescription; |
433 } | 389 } |
434 | 390 |
435 @override | 391 @override |
436 bool matches(item, Map matchState) { | 392 bool matches(item, Map matchState) { |
437 Response response = item; | 393 Response response = item; |
438 return response != null && response.id == _id && response.error == null; | 394 return response != null && response.id == _id && response.error == null; |
439 } | 395 } |
440 } | 396 } |
OLD | NEW |