| 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 'package:analysis_server/src/constants.dart'; | |
| 8 import 'package:analysis_server/src/protocol.dart'; | 7 import 'package:analysis_server/src/protocol.dart'; |
| 9 import 'package:analysis_server/src/protocol2.dart' show | 8 import 'package:analysis_server/src/protocol2.dart' show |
| 10 SearchFindTopLevelDeclarationsParams; | 9 SearchFindTopLevelDeclarationsParams, ElementKind, |
| 10 SearchFindTopLevelDeclarationsResult; |
| 11 import 'package:analysis_server/src/search/search_result.dart'; | 11 import 'package:analysis_server/src/search/search_result.dart'; |
| 12 import 'package:analysis_testing/reflective_tests.dart'; | 12 import 'package:analysis_testing/reflective_tests.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 14 | 14 |
| 15 import 'abstract_search_domain.dart'; | 15 import 'abstract_search_domain.dart'; |
| 16 import 'dart:async'; | 16 import 'dart:async'; |
| 17 import 'package:analysis_server/src/computer/element.dart'; | 17 import 'package:analysis_server/src/computer/element.dart'; |
| 18 | 18 |
| 19 | 19 |
| 20 main() { | 20 main() { |
| 21 groupSep = ' | '; | 21 groupSep = ' | '; |
| 22 runReflectiveTests(TopLevelDeclarationsTest); | 22 runReflectiveTests(TopLevelDeclarationsTest); |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 @ReflectiveTestCase() | 26 @ReflectiveTestCase() |
| 27 class TopLevelDeclarationsTest extends AbstractSearchDomainTest { | 27 class TopLevelDeclarationsTest extends AbstractSearchDomainTest { |
| 28 Future findTopLevelDeclarations(String pattern) { | 28 Future findTopLevelDeclarations(String pattern) { |
| 29 return waitForTasksFinished().then((_) { | 29 return waitForTasksFinished().then((_) { |
| 30 Request request = new SearchFindTopLevelDeclarationsParams( | 30 Request request = new SearchFindTopLevelDeclarationsParams( |
| 31 pattern).toRequest('0'); | 31 pattern).toRequest('0'); |
| 32 Response response = handleSuccessfulRequest(request); | 32 Response response = handleSuccessfulRequest(request); |
| 33 searchId = response.getResult(ID); | 33 searchId = new SearchFindTopLevelDeclarationsResult.fromResponse( |
| 34 response).id; |
| 34 results.clear(); | 35 results.clear(); |
| 35 return waitForSearchResults(); | 36 return waitForSearchResults(); |
| 36 }); | 37 }); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void assertHasDeclaration(ElementKind kind, String name) { | 40 void assertHasDeclaration(ElementKind kind, String name) { |
| 40 result = findTopLevelResult(kind, name); | 41 result = findTopLevelResult(kind, name); |
| 41 if (result == null) { | 42 if (result == null) { |
| 42 fail('Not found: kind=$kind name="$name"\nin\n' + results.join('\n')); | 43 fail('Not found: kind=$kind name="$name"\nin\n' + results.join('\n')); |
| 43 } | 44 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 72 return findTopLevelDeclarations('^[A-E]\$').then((_) { | 73 return findTopLevelDeclarations('^[A-E]\$').then((_) { |
| 73 assertHasDeclaration(ElementKind.CLASS, 'A'); | 74 assertHasDeclaration(ElementKind.CLASS, 'A'); |
| 74 assertHasDeclaration(ElementKind.CLASS, 'B'); | 75 assertHasDeclaration(ElementKind.CLASS, 'B'); |
| 75 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C'); | 76 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C'); |
| 76 assertHasDeclaration(ElementKind.FUNCTION, 'D'); | 77 assertHasDeclaration(ElementKind.FUNCTION, 'D'); |
| 77 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E'); | 78 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E'); |
| 78 assertNoDeclaration(ElementKind.CLASS, 'ABC'); | 79 assertNoDeclaration(ElementKind.CLASS, 'ABC'); |
| 79 }); | 80 }); |
| 80 } | 81 } |
| 81 } | 82 } |
| OLD | NEW |