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

Side by Side Diff: pkg/analysis_server/test/services/completion/completion_test_util.dart

Issue 628473002: cleanup/organize/improve completion tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 2 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 | « no previous file | pkg/analysis_server/test/services/completion/imported_computer_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.util; 5 library test.services.completion.util;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element,
10 ElementKind; 10 ElementKind;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 int nextOffset = content.indexOf('^', completionOffset + 1); 46 int nextOffset = content.indexOf('^', completionOffset + 1);
47 expect(nextOffset, equals(-1), reason: 'too many ^'); 47 expect(nextOffset, equals(-1), reason: 'too many ^');
48 content = content.substring(0, completionOffset) + 48 content = content.substring(0, completionOffset) +
49 content.substring(completionOffset + 1); 49 content.substring(completionOffset + 1);
50 testSource = addSource(testFile, content); 50 testSource = addSource(testFile, content);
51 request = 51 request =
52 new DartCompletionRequest(context, searchEngine, testSource, completionO ffset); 52 new DartCompletionRequest(context, searchEngine, testSource, completionO ffset);
53 } 53 }
54 54
55 void assertNotSuggested(String completion) { 55 void assertNotSuggested(String completion) {
56 if (request.suggestions.any((cs) => cs.completion == completion)) { 56 CompletionSuggestion suggestion = request.suggestions.firstWhere(
57 _failWithNodeInfo('did not expect completion: $completion'); 57 (cs) => cs.completion == completion,
58 orElse: () => null);
59 if (suggestion != null) {
60 _failedCompletion(
61 'did not expect completion: $completion\n $suggestion');
58 } 62 }
59 } 63 }
60 64
61 CompletionSuggestion assertSuggest(CompletionSuggestionKind kind, 65 CompletionSuggestion assertSuggest(CompletionSuggestionKind kind,
62 String completion, [CompletionRelevance relevance = CompletionRelevance.DE FAULT, 66 String completion, [CompletionRelevance relevance = CompletionRelevance.DE FAULT,
63 bool isDeprecated = false, bool isPotential = false]) { 67 bool isDeprecated = false, bool isPotential = false]) {
64 CompletionSuggestion cs; 68 CompletionSuggestion cs;
65 request.suggestions.forEach((s) { 69 request.suggestions.forEach((s) {
66 if (s.completion == completion) { 70 if (s.completion == completion) {
67 if (cs == null) { 71 if (cs == null) {
68 cs = s; 72 cs = s;
69 } else { 73 } else {
70 List<CompletionSuggestion> completions = 74 _failedCompletion(
71 request.suggestions.where((s) => s.completion == completion).toLis t(); 75 'expected exactly one $completion',
72 _failWithNodeInfo( 76 request.suggestions.where((s) => s.completion == completion));
73 'expected exactly one $completion but found > 1\n$completions');
74 } 77 }
75 } 78 }
76 }); 79 });
77 if (cs == null) { 80 if (cs == null) {
78 List<CompletionSuggestion> completions = 81 _failedCompletion('expected $completion', request.suggestions);
79 request.suggestions.map((s) => s.completion).toList();
80 _failWithNodeInfo('expected "$completion" but found\n $completions');
81 } 82 }
82 expect(cs.kind, equals(kind)); 83 expect(cs.kind, equals(kind));
83 expect(cs.relevance, equals(relevance)); 84 expect(cs.relevance, equals(relevance));
84 expect(cs.selectionOffset, equals(completion.length)); 85 expect(cs.selectionOffset, equals(completion.length));
85 expect(cs.selectionLength, equals(0)); 86 expect(cs.selectionLength, equals(0));
86 expect(cs.isDeprecated, equals(isDeprecated)); 87 expect(cs.isDeprecated, equals(isDeprecated));
87 expect(cs.isPotential, equals(isPotential)); 88 expect(cs.isPotential, equals(isPotential));
88 return cs; 89 return cs;
89 } 90 }
90 91
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 return computer.computeFull(request); 284 return computer.computeFull(request);
284 } 285 }
285 286
286 @override 287 @override
287 void setUp() { 288 void setUp() {
288 super.setUp(); 289 super.setUp();
289 index = createLocalMemoryIndex(); 290 index = createLocalMemoryIndex();
290 searchEngine = new SearchEngineImpl(index); 291 searchEngine = new SearchEngineImpl(index);
291 } 292 }
292 293
293 void _failWithNodeInfo(String message) { 294 void _failedCompletion(String message,
295 [Iterable<CompletionSuggestion> completions]) {
294 StringBuffer sb = new StringBuffer(message); 296 StringBuffer sb = new StringBuffer(message);
297 if (completions != null) {
298 sb.write('\n found');
299 completions.toList()
300 ..sort((CompletionSuggestion s1, CompletionSuggestion s2) {
301 String c1 = s1.completion.toLowerCase();
302 String c2 = s2.completion.toLowerCase();
303 return c1.compareTo(c2);
304 })
305 ..forEach((CompletionSuggestion suggestion) {
306 sb.write('\n ${suggestion.completion} -> $suggestion');
307 });
308 }
295 if (completionNode != null) { 309 if (completionNode != null) {
296 sb.write('\n in'); 310 sb.write('\n in');
297 AstNode node = completionNode; 311 AstNode node = completionNode;
298 while (node != null) { 312 while (node != null) {
299 sb.write('\n ${node.runtimeType}'); 313 sb.write('\n ${node.runtimeType}');
300 node = node.parent; 314 node = node.parent;
301 } 315 }
302 } 316 }
303 fail(sb.toString()); 317 fail(sb.toString());
304 } 318 }
305 } 319 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/imported_computer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698