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; |
52 } | 55 } |
53 } | 56 } |
54 return null; | 57 return null; |
55 } | 58 } |
56 | 59 |
57 test_startEndPattern() async { | 60 setUp() { |
61 super.setUp(); | |
62 | |
58 addTestFile(''' | 63 addTestFile(''' |
scheglov
2016/07/14 00:18:07
This test file is specifically for the correspondi
| |
59 class A {} // A | 64 class A {} // A |
60 class B = Object with A; | 65 class B = Object with A; |
61 typedef C(); | 66 typedef C(); |
62 D() {} | 67 D() {} |
63 var E = null; | 68 var E = null; |
64 class ABC {} | 69 class ABC {} |
65 '''); | 70 '''); |
71 } | |
72 | |
73 test_startEndPattern() async { | |
66 await findTopLevelDeclarations('^[A-E]\$'); | 74 await findTopLevelDeclarations('^[A-E]\$'); |
67 assertHasDeclaration(ElementKind.CLASS, 'A'); | 75 assertHasDeclaration(ElementKind.CLASS, 'A'); |
68 assertHasDeclaration(ElementKind.CLASS, 'B'); | 76 assertHasDeclaration(ElementKind.CLASS, 'B'); |
69 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C'); | 77 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C'); |
70 assertHasDeclaration(ElementKind.FUNCTION, 'D'); | 78 assertHasDeclaration(ElementKind.FUNCTION, 'D'); |
71 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E'); | 79 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E'); |
72 assertNoDeclaration(ElementKind.CLASS, 'ABC'); | 80 assertNoDeclaration(ElementKind.CLASS, 'ABC'); |
73 } | 81 } |
82 | |
83 test_invalidRegex() async { | |
84 var result = await findTopLevelDeclarations('[A'); | |
85 expect(true, result is RequestError); | |
Brian Wilkerson
2016/07/13 23:42:37
The arguments are backward. The better way to writ
scheglov
2016/07/14 00:18:07
See also isResponseFailure in mocks.dart
| |
86 } | |
74 } | 87 } |
OLD | NEW |