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.search.top_level_declarations; | 5 library test.search.top_level_declarations; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
(...skipping 21 matching lines...) Expand all Loading... |
32 if (result != null) { | 32 if (result != null) { |
33 fail('Unexpected: kind=$kind name="$name"\nin\n' + results.join('\n')); | 33 fail('Unexpected: kind=$kind name="$name"\nin\n' + results.join('\n')); |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 Future findTopLevelDeclarations(String pattern) async { | 37 Future findTopLevelDeclarations(String pattern) async { |
38 await waitForTasksFinished(); | 38 await waitForTasksFinished(); |
39 Request request = | 39 Request request = |
40 new SearchFindTopLevelDeclarationsParams(pattern).toRequest('0'); | 40 new SearchFindTopLevelDeclarationsParams(pattern).toRequest('0'); |
41 Response response = await waitResponse(request); | 41 Response response = await waitResponse(request); |
| 42 if (response.error != null) { |
| 43 return response.error; |
| 44 } |
42 searchId = | 45 searchId = |
43 new SearchFindTopLevelDeclarationsResult.fromResponse(response).id; | 46 new SearchFindTopLevelDeclarationsResult.fromResponse(response).id; |
44 return waitForSearchResults(); | 47 return waitForSearchResults(); |
45 } | 48 } |
46 | 49 |
47 SearchResult findTopLevelResult(ElementKind kind, String name) { | 50 SearchResult findTopLevelResult(ElementKind kind, String name) { |
48 for (SearchResult result in results) { | 51 for (SearchResult result in results) { |
49 Element element = result.path[0]; | 52 Element element = result.path[0]; |
50 if (element.kind == kind && element.name == name) { | 53 if (element.kind == kind && element.name == name) { |
51 return result; | 54 return result; |
(...skipping 12 matching lines...) Expand all Loading... |
64 class ABC {} | 67 class ABC {} |
65 '''); | 68 '''); |
66 await findTopLevelDeclarations('^[A-E]\$'); | 69 await findTopLevelDeclarations('^[A-E]\$'); |
67 assertHasDeclaration(ElementKind.CLASS, 'A'); | 70 assertHasDeclaration(ElementKind.CLASS, 'A'); |
68 assertHasDeclaration(ElementKind.CLASS, 'B'); | 71 assertHasDeclaration(ElementKind.CLASS, 'B'); |
69 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C'); | 72 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C'); |
70 assertHasDeclaration(ElementKind.FUNCTION, 'D'); | 73 assertHasDeclaration(ElementKind.FUNCTION, 'D'); |
71 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E'); | 74 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E'); |
72 assertNoDeclaration(ElementKind.CLASS, 'ABC'); | 75 assertNoDeclaration(ElementKind.CLASS, 'ABC'); |
73 } | 76 } |
| 77 |
| 78 test_invalidRegex() async { |
| 79 var result = await findTopLevelDeclarations('[A'); |
| 80 expect(result, new isInstanceOf<RequestError>()); |
| 81 } |
74 } | 82 } |
OLD | NEW |