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.services.completion.suggestion; | 5 library test.services.completion.suggestion; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 int count = 0; | 87 int count = 0; |
88 bool done = false; | 88 bool done = false; |
89 AnalysisServer server = new AnalysisServerMock(searchEngine: searchEngine); | 89 AnalysisServer server = new AnalysisServerMock(searchEngine: searchEngine); |
90 CompletionRequest completionRequest = | 90 CompletionRequest completionRequest = |
91 new CompletionRequestImpl(server, context, source, 0); | 91 new CompletionRequestImpl(server, context, source, 0); |
92 manager.results(completionRequest).listen((CompletionResult r) { | 92 manager.results(completionRequest).listen((CompletionResult r) { |
93 bool isLast = r is CompletionResultImpl ? r.isLast : true; | 93 bool isLast = r is CompletionResultImpl ? r.isLast : true; |
94 switch (++count) { | 94 switch (++count) { |
95 case 1: | 95 case 1: |
96 contributor1.assertCalls(context, source, 0, searchEngine); | 96 contributor1.assertCalls(context, source, 0, searchEngine); |
| 97 expect(contributor1.fastCount, equals(1)); |
| 98 expect(contributor1.fullCount, equals(0)); |
97 contributor2.assertCalls(context, source, 0, searchEngine); | 99 contributor2.assertCalls(context, source, 0, searchEngine); |
98 expect(isLast, isFalse); | 100 expect(contributor2.fastCount, equals(1)); |
99 expect(r.suggestions, hasLength(1)); | 101 expect(contributor2.fullCount, equals(1)); |
100 expect(r.suggestions, contains(suggestion1)); | |
101 resolveLibrary(); | |
102 break; | |
103 case 2: | |
104 contributor1.assertFull(0); | |
105 contributor2.assertFull(1); | |
106 expect(isLast, isTrue); | 102 expect(isLast, isTrue); |
107 expect(r.suggestions, hasLength(2)); | 103 expect(r.suggestions, hasLength(2)); |
108 expect(r.suggestions, contains(suggestion1)); | 104 expect(r.suggestions, contains(suggestion1)); |
109 expect(r.suggestions, contains(suggestion2)); | 105 expect(r.suggestions, contains(suggestion2)); |
| 106 resolveLibrary(); |
110 break; | 107 break; |
111 default: | 108 default: |
112 fail('unexpected'); | 109 fail('unexpected'); |
113 } | 110 } |
114 }, onDone: () { | 111 }, onDone: () { |
115 done = true; | 112 done = true; |
116 expect(count, equals(2)); | 113 // There is only one notification |
| 114 expect(count, equals(1)); |
117 }); | 115 }); |
118 return pumpEventQueue().then((_) { | 116 return pumpEventQueue().then((_) { |
119 expect(done, isTrue); | 117 expect(done, isTrue); |
120 }); | 118 }); |
121 } | 119 } |
122 | 120 |
123 test_compute_fastOnly() { | 121 test_compute_fastOnly() { |
124 contributor1 = new MockCompletionContributor(suggestion1, null); | 122 contributor1 = new MockCompletionContributor(suggestion1, null); |
125 contributor2 = new MockCompletionContributor(suggestion2, null); | 123 contributor2 = new MockCompletionContributor(suggestion2, null); |
126 manager.contributors = [contributor1, contributor2]; | 124 manager.contributors = [contributor1, contributor2]; |
127 int count = 0; | 125 int count = 0; |
128 bool done = false; | 126 bool done = false; |
129 AnalysisServer server = new AnalysisServerMock(searchEngine: searchEngine); | 127 AnalysisServer server = new AnalysisServerMock(searchEngine: searchEngine); |
130 CompletionRequest completionRequest = | 128 CompletionRequest completionRequest = |
131 new CompletionRequestImpl(server, context, source, 0); | 129 new CompletionRequestImpl(server, context, source, 0); |
132 manager.results(completionRequest).listen((CompletionResult r) { | 130 manager.results(completionRequest).listen((CompletionResult r) { |
133 bool isLast = r is CompletionResultImpl ? r.isLast : true; | 131 bool isLast = r is CompletionResultImpl ? r.isLast : true; |
134 switch (++count) { | 132 switch (++count) { |
135 case 1: | 133 case 1: |
136 contributor1.assertCalls(context, source, 0, searchEngine); | 134 contributor1.assertCalls(context, source, 0, searchEngine); |
| 135 expect(contributor1.fastCount, equals(1)); |
| 136 expect(contributor1.fullCount, equals(0)); |
137 contributor2.assertCalls(context, source, 0, searchEngine); | 137 contributor2.assertCalls(context, source, 0, searchEngine); |
| 138 expect(contributor2.fastCount, equals(1)); |
| 139 expect(contributor2.fullCount, equals(0)); |
138 expect(isLast, isTrue); | 140 expect(isLast, isTrue); |
139 expect(r.suggestions, hasLength(2)); | 141 expect(r.suggestions, hasLength(2)); |
140 expect(r.suggestions, contains(suggestion1)); | 142 expect(r.suggestions, contains(suggestion1)); |
141 expect(r.suggestions, contains(suggestion2)); | 143 expect(r.suggestions, contains(suggestion2)); |
142 break; | 144 break; |
143 default: | 145 default: |
144 fail('unexpected'); | 146 fail('unexpected'); |
145 } | 147 } |
146 }, onDone: () { | 148 }, onDone: () { |
147 done = true; | 149 done = true; |
(...skipping 15 matching lines...) Expand all Loading... |
163 | 165 |
164 class MockCompletionContributor extends DartCompletionContributor { | 166 class MockCompletionContributor extends DartCompletionContributor { |
165 final CompletionSuggestion fastSuggestion; | 167 final CompletionSuggestion fastSuggestion; |
166 final CompletionSuggestion fullSuggestion; | 168 final CompletionSuggestion fullSuggestion; |
167 int fastCount = 0; | 169 int fastCount = 0; |
168 int fullCount = 0; | 170 int fullCount = 0; |
169 DartCompletionRequest request; | 171 DartCompletionRequest request; |
170 | 172 |
171 MockCompletionContributor(this.fastSuggestion, this.fullSuggestion); | 173 MockCompletionContributor(this.fastSuggestion, this.fullSuggestion); |
172 | 174 |
173 assertCalls(AnalysisContext context, Source source, int offset, | 175 assertCalls(AnalysisContext context, Source source, int offset, SearchEngine s
earchEngine) { |
174 SearchEngine searchEngine) { | |
175 expect(request.context, equals(context)); | 176 expect(request.context, equals(context)); |
176 expect(request.source, equals(source)); | 177 expect(request.source, equals(source)); |
177 expect(request.offset, equals(offset)); | 178 expect(request.offset, equals(offset)); |
178 expect(request.searchEngine, equals(searchEngine)); | 179 expect(request.searchEngine, equals(searchEngine)); |
179 expect(this.fastCount, equals(1)); | |
180 expect(this.fullCount, equals(0)); | |
181 } | 180 } |
182 | 181 |
183 assertFull(int fullCount) { | 182 assertFull(int fullCount) { |
184 expect(this.fastCount, equals(1)); | 183 expect(this.fastCount, equals(1)); |
185 expect(this.fullCount, equals(fullCount)); | 184 expect(this.fullCount, equals(fullCount)); |
186 } | 185 } |
187 | 186 |
188 @override | 187 @override |
189 bool computeFast(DartCompletionRequest request) { | 188 bool computeFast(DartCompletionRequest request) { |
190 this.request = request; | 189 this.request = request; |
191 fastCount++; | 190 fastCount++; |
192 if (fastSuggestion != null) { | 191 if (fastSuggestion != null) { |
193 request.addSuggestion(fastSuggestion); | 192 request.addSuggestion(fastSuggestion); |
194 } | 193 } |
195 return fastSuggestion != null; | 194 return fastSuggestion != null; |
196 } | 195 } |
197 | 196 |
198 @override | 197 @override |
199 Future<bool> computeFull(DartCompletionRequest request) { | 198 Future<bool> computeFull(DartCompletionRequest request) { |
200 this.request = request; | 199 this.request = request; |
201 fullCount++; | 200 fullCount++; |
202 if (fullSuggestion != null) { | 201 if (fullSuggestion != null) { |
203 request.addSuggestion(fullSuggestion); | 202 request.addSuggestion(fullSuggestion); |
204 } | 203 } |
205 return new Future.value(fullSuggestion != null); | 204 return new Future.value(fullSuggestion != null); |
206 } | 205 } |
207 } | 206 } |
OLD | NEW |