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 test.computer.element; | |
6 | |
7 import 'dart:mirrors'; | 5 import 'dart:mirrors'; |
8 | 6 |
9 import 'package:analysis_server/src/constants.dart'; | 7 import 'package:analysis_server/src/constants.dart'; |
10 import 'package:analysis_server/src/protocol_server.dart'; | 8 import 'package:analysis_server/src/protocol_server.dart'; |
11 import 'package:analysis_server/src/services/search/search_engine.dart'; | 9 import 'package:analysis_server/src/services/search/search_engine.dart'; |
12 import 'package:analyzer/dart/ast/ast.dart' as engine; | 10 import 'package:analyzer/dart/ast/ast.dart' as engine; |
13 import 'package:analyzer/dart/element/element.dart' as engine; | 11 import 'package:analyzer/dart/element/element.dart' as engine; |
14 import 'package:analyzer/dart/element/type.dart' as engine; | 12 import 'package:analyzer/dart/element/type.dart' as engine; |
15 import 'package:analyzer/error/error.dart' as engine; | 13 import 'package:analyzer/error/error.dart' as engine; |
16 import 'package:analyzer/src/error/codes.dart' as engine; | 14 import 'package:analyzer/src/error/codes.dart' as engine; |
17 import 'package:analyzer/src/generated/source.dart' as engine; | 15 import 'package:analyzer/src/generated/source.dart' as engine; |
| 16 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
18 import 'package:test/test.dart'; | 17 import 'package:test/test.dart'; |
19 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
20 import 'package:typed_mock/typed_mock.dart'; | 19 import 'package:typed_mock/typed_mock.dart'; |
21 | 20 |
22 import 'mocks.dart'; | 21 import 'mocks.dart'; |
23 | 22 |
24 main() { | 23 main() { |
25 defineReflectiveSuite(() { | 24 defineReflectiveSuite(() { |
26 defineReflectiveTests(AnalysisErrorTest); | 25 defineReflectiveTests(AnalysisErrorTest); |
27 defineReflectiveTests(EnumTest); | 26 defineReflectiveTests(EnumTest); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // use SearchResultKind inside the analysis server? | 147 // use SearchResultKind inside the analysis server? |
149 new EnumTester<MatchKind, SearchResultKind>() | 148 new EnumTester<MatchKind, SearchResultKind>() |
150 .run(newSearchResultKind_fromEngine); | 149 .run(newSearchResultKind_fromEngine); |
151 } | 150 } |
152 } | 151 } |
153 | 152 |
154 /** | 153 /** |
155 * Helper class for testing the correspondence between an analysis engine enum | 154 * Helper class for testing the correspondence between an analysis engine enum |
156 * and an analysis server API enum. | 155 * and an analysis server API enum. |
157 */ | 156 */ |
158 class EnumTester<EngineEnum, ApiEnum extends Enum> { | 157 class EnumTester<EngineEnum, ApiEnum> { |
159 /** | 158 /** |
160 * Test that the function [convert] properly converts all possible values of | 159 * Test that the function [convert] properly converts all possible values of |
161 * [EngineEnum] to an [ApiEnum] with the same name, with the exceptions noted | 160 * [EngineEnum] to an [ApiEnum] with the same name, with the exceptions noted |
162 * in [exceptions]. For each key in [exceptions], if the corresponding value | 161 * in [exceptions]. For each key in [exceptions], if the corresponding value |
163 * is null, then we check that converting the given key results in an error. | 162 * is null, then we check that converting the given key results in an error. |
164 * If the corresponding value is an [ApiEnum], then we check that converting | 163 * If the corresponding value is an [ApiEnum], then we check that converting |
165 * the given key results in the given value. | 164 * the given key results in the given value. |
166 */ | 165 */ |
167 void run(ApiEnum convert(EngineEnum value), | 166 void run(ApiEnum convert(EngineEnum value), |
168 {Map<EngineEnum, ApiEnum> exceptions: const {}}) { | 167 {Map<EngineEnum, ApiEnum> exceptions: const {}}) { |
(...skipping 14 matching lines...) Expand all Loading... |
183 if (expectedResult == null) { | 182 if (expectedResult == null) { |
184 expect(() { | 183 expect(() { |
185 convert(engineValue); | 184 convert(engineValue); |
186 }, throws); | 185 }, throws); |
187 } else { | 186 } else { |
188 ApiEnum apiValue = convert(engineValue); | 187 ApiEnum apiValue = convert(engineValue); |
189 expect(apiValue, equals(expectedResult)); | 188 expect(apiValue, equals(expectedResult)); |
190 } | 189 } |
191 } else { | 190 } else { |
192 ApiEnum apiValue = convert(engineValue); | 191 ApiEnum apiValue = convert(engineValue); |
193 expect(apiValue.name, equals(enumName)); | 192 expect((apiValue as dynamic).name, equals(enumName)); |
194 } | 193 } |
195 }); | 194 }); |
196 } | 195 } |
197 } | 196 } |
OLD | NEW |