Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: pkg/analysis_server/test/search/top_level_declarations_test.dart

Issue 399483002: Implementation for 'search.findTopLevelDeclarations' API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/test/search/test_all.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.search.top_level_declarations;
6
7 import 'package:analysis_server/src/constants.dart';
8 import 'package:analysis_server/src/protocol.dart';
9 import 'package:analysis_server/src/search/search_result.dart';
10 import 'package:analysis_testing/reflective_tests.dart';
11 import 'package:unittest/unittest.dart';
12
13 import 'abstract_search_domain.dart';
14 import 'dart:async';
15 import 'package:analysis_server/src/computer/element.dart';
16
17
18 main() {
19 groupSep = ' | ';
20 group('findTopLevelDeclarations', () {
21 runReflectiveTests(TopLevelDeclarationsTest);
22 });
23 }
24
25
26 @ReflectiveTestCase()
27 class TopLevelDeclarationsTest extends AbstractSearchDomainTest {
28 Future findTopLevelDeclarations(String pattern) {
29 return waitForTasksFinished().then((_) {
30 Request request = new Request('0', SEARCH_FIND_TOP_LEVEL_DECLARATIONS);
31 request.setParameter(PATTERN, pattern);
32 Response response = handleSuccessfulRequest(request);
33 searchId = response.getResult(ID);
34 results.clear();
35 return waitForSearchResults();
36 });
37 }
38
39 void assertHasDeclaration(ElementKind kind, String name) {
40 result = findTopLevelResult(kind, name);
41 if (result == null) {
42 fail('Not found: kind=$kind name="$name"\nin\n' + results.join('\n'));
43 }
44 }
45
46 void assertNoDeclaration(ElementKind kind, String name) {
47 result = findTopLevelResult(kind, name);
48 if (result != null) {
49 fail('Unexpected: kind=$kind name="$name"\nin\n' + results.join('\n'));
50 }
51 }
52
53 SearchResult findTopLevelResult(ElementKind kind, String name) {
54 for (SearchResult result in results) {
55 Element element = result.path[0];
56 if (element.kind == kind && element.name == name) {
57 return result;
58 }
59 }
60 return null;
61 }
62
63 test_startEndPattern() {
64 addTestFile('''
65 class A {} // A
66 class B = Object with A;
67 typedef C();
68 D() {}
69 var E = null;
70 class ABC {}
71 ''');
72 return findTopLevelDeclarations('^[A-E]\$').then((_) {
73 assertHasDeclaration(ElementKind.CLASS, 'A');
74 assertHasDeclaration(ElementKind.CLASS, 'B');
75 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C');
76 assertHasDeclaration(ElementKind.FUNCTION, 'D');
77 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E');
78 assertNoDeclaration(ElementKind.CLASS, 'ABC');
79 });
80 }
81 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/search/test_all.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698