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

Side by Side Diff: pkg/analysis_server/test/search/abstract_search_domain.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
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.abstract_search_domain;
6
7 import 'dart:async';
8
9 import 'package:analysis_server/src/computer/element.dart';
10 import 'package:analysis_server/src/constants.dart';
11 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analysis_server/src/search/search_domain.dart';
13 import 'package:analysis_server/src/search/search_result.dart';
14 import 'package:analysis_services/index/index.dart' show Index;
15 import 'package:analysis_services/index/local_memory_index.dart';
16 import 'package:unittest/unittest.dart';
17
18 import '../analysis_abstract.dart';
19
20
21 class AbstractSearchDomainTest extends AbstractAnalysisTest {
22 String searchId;
23 bool searchDone = false;
24 List<SearchResult> results = <SearchResult>[];
25 SearchResult result;
26
27 void assertHasResult(SearchResultKind kind, String search, [int length]) {
28 int offset = findOffset(search);
29 if (length == null) {
30 length = findIdentifierLength(search);
31 }
32 findResult(kind, testFile, offset, length, true);
33 }
34
35 void assertNoResult(SearchResultKind kind, String search, [int length]) {
36 int offset = findOffset(search);
37 if (length == null) {
38 length = findIdentifierLength(search);
39 }
40 findResult(kind, testFile, offset, length, false);
41 }
42
43 @override
44 Index createIndex() {
45 return createLocalMemoryIndex();
46 }
47
48 void findResult(SearchResultKind kind, String file, int offset, int length,
49 bool expected) {
50 for (SearchResult result in results) {
51 Location location = result.location;
52 if (result.kind == kind &&
53 location.file == file &&
54 location.offset == offset &&
55 location.length == length) {
56 if (!expected) {
57 fail('Unexpected result $result in\n' + results.join('\n'));
58 }
59 this.result = result;
60 return;
61 }
62 }
63 if (expected) {
64 fail(
65 'Not found: "search" kind=$kind offset=$offset length=$length\nin\n' +
66 results.join('\n'));
67 }
68 }
69
70 String getPathString(List<Element> path) {
71 return path.map((Element element) {
72 return '${element.kind} ${element.name}';
73 }).join('\n');
74 }
75
76 void processNotification(Notification notification) {
77 if (notification.event == SEARCH_RESULTS) {
78 String id = notification.getParameter(ID);
79 if (id == searchId) {
80 for (Map<String, Object> json in notification.getParameter(RESULTS)) {
81 results.add(new SearchResult.fromJson(json));
82 }
83 searchDone = notification.getParameter(LAST);
84 }
85 }
86 }
87
88 @override
89 void setUp() {
90 super.setUp();
91 createProject();
92 handler = new SearchDomainHandler(server);
93 }
94
95 Future waitForSearchResults() {
96 if (searchDone) {
97 return new Future.value();
98 }
99 return new Future.delayed(Duration.ZERO, waitForSearchResults);
100 }
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698