OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 analyzer.test.utils; | 5 library analyzer.test.utils; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
11 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 11 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
12 import 'package:analyzer/src/generated/testing/element_search.dart'; | 12 import 'package:analyzer/src/generated/testing/element_search.dart'; |
13 import 'package:front_end/src/base/source.dart'; | 13 import 'package:front_end/src/base/source.dart'; |
14 import 'package:test/test.dart'; | 14 import 'package:test/test.dart'; |
15 | 15 |
16 /** | 16 /** |
17 * Search the [unit] for the [LocalVariableElement] with the given [name]. | 17 * Search the [unit] for the [LocalVariableElement] with the given [name]. |
18 * Fail if there is not exactly one such variable. | 18 * Fail if there is not exactly one such variable. |
19 */ | 19 */ |
| 20 FunctionElement findLocalFunction(CompilationUnit unit, String name) { |
| 21 List<Element> elements = findElementsByName(unit, name); |
| 22 List<Element> functions = |
| 23 elements.where((e) => e is FunctionElement).toList(); |
| 24 expect(functions, hasLength(1)); |
| 25 return functions[0]; |
| 26 } |
| 27 |
| 28 /** |
| 29 * Search the [unit] for the [LocalVariableElement] with the given [name]. |
| 30 * Fail if there is not exactly one such variable. |
| 31 */ |
20 LocalVariableElement findLocalVariable(CompilationUnit unit, String name) { | 32 LocalVariableElement findLocalVariable(CompilationUnit unit, String name) { |
21 List<Element> elements = findElementsByName(unit, name); | 33 List<Element> elements = findElementsByName(unit, name); |
22 List<Element> localVariables = | 34 List<Element> localVariables = |
23 elements.where((e) => e is LocalVariableElement).toList(); | 35 elements.where((e) => e is LocalVariableElement).toList(); |
24 expect(localVariables, hasLength(1)); | 36 expect(localVariables, hasLength(1)); |
25 return localVariables[0]; | 37 return localVariables[0]; |
26 } | 38 } |
27 | 39 |
28 /** | 40 /** |
29 * The type of an assertion which asserts properties of [T]s. | 41 * The type of an assertion which asserts properties of [T]s. |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 Asserter<DartType> argAssert0, Asserter<DartType> argAssert1) => | 328 Asserter<DartType> argAssert0, Asserter<DartType> argAssert1) => |
317 isInstantiationOf(isMap)([argAssert0, argAssert1]); | 329 isInstantiationOf(isMap)([argAssert0, argAssert1]); |
318 | 330 |
319 /** | 331 /** |
320 * Assert that a type is equal to the [expected]. | 332 * Assert that a type is equal to the [expected]. |
321 */ | 333 */ |
322 Asserter<DartType> isType(DartType expected) => (DartType t) { | 334 Asserter<DartType> isType(DartType expected) => (DartType t) { |
323 expect(t, expected); | 335 expect(t, expected); |
324 }; | 336 }; |
325 } | 337 } |
OLD | NEW |