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

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

Issue 620013002: improve completion test failure message by adding node info (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | 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
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, Ele mentKind; 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element,
10 ElementKind;
10 import 'package:analysis_server/src/protocol.dart' hide Element; 11 import 'package:analysis_server/src/protocol.dart' hide Element;
11 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 12 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
12 import 'package:analysis_server/src/services/index/index.dart'; 13 import 'package:analysis_server/src/services/index/index.dart';
13 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 14 import 'package:analysis_server/src/services/index/local_memory_index.dart';
14 import 'package:analysis_server/src/services/search/search_engine_internal.dart' ; 15 import 'package:analysis_server/src/services/search/search_engine_internal.dart' ;
15 import 'package:analyzer/src/generated/ast.dart'; 16 import 'package:analyzer/src/generated/ast.dart';
16 import 'package:analyzer/src/generated/element.dart'; 17 import 'package:analyzer/src/generated/element.dart';
17 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
18 import 'package:analyzer/src/generated/source.dart'; 19 import 'package:analyzer/src/generated/source.dart';
19 import 'package:unittest/unittest.dart'; 20 import 'package:unittest/unittest.dart';
(...skipping 24 matching lines...) Expand all
44 expect(nextOffset, equals(-1), reason: 'too many ^'); 45 expect(nextOffset, equals(-1), reason: 'too many ^');
45 content = content.substring(0, completionOffset) + 46 content = content.substring(0, completionOffset) +
46 content.substring(completionOffset + 1); 47 content.substring(completionOffset + 1);
47 testSource = addSource(testFile, content); 48 testSource = addSource(testFile, content);
48 request = 49 request =
49 new DartCompletionRequest(context, searchEngine, testSource, completionO ffset); 50 new DartCompletionRequest(context, searchEngine, testSource, completionO ffset);
50 } 51 }
51 52
52 void assertNotSuggested(String completion) { 53 void assertNotSuggested(String completion) {
53 if (request.suggestions.any((cs) => cs.completion == completion)) { 54 if (request.suggestions.any((cs) => cs.completion == completion)) {
54 fail('did not expect completion: $completion'); 55 _failWithNodeInfo('did not expect completion: $completion');
55 } 56 }
56 } 57 }
57 58
58 CompletionSuggestion assertSuggest(CompletionSuggestionKind kind, 59 CompletionSuggestion assertSuggest(CompletionSuggestionKind kind,
59 String completion, [CompletionRelevance relevance = CompletionRelevance.DE FAULT, 60 String completion, [CompletionRelevance relevance = CompletionRelevance.DE FAULT,
60 bool isDeprecated = false, bool isPotential = false]) { 61 bool isDeprecated = false, bool isPotential = false]) {
61 CompletionSuggestion cs; 62 CompletionSuggestion cs;
62 request.suggestions.forEach((s) { 63 request.suggestions.forEach((s) {
63 if (s.completion == completion) { 64 if (s.completion == completion) {
64 if (cs == null) { 65 if (cs == null) {
65 cs = s; 66 cs = s;
66 } else { 67 } else {
67 List<CompletionSuggestion> matchSuggestions = 68 List<CompletionSuggestion> completions =
68 request.suggestions.where((s) => s.completion == completion).toLis t(); 69 request.suggestions.where((s) => s.completion == completion).toLis t();
69 fail( 70 _failWithNodeInfo(
70 'expected exactly one $completion but found > 1\n $matchSuggestion s'); 71 'expected exactly one $completion but found > 1\n$completions');
71 } 72 }
72 } 73 }
73 }); 74 });
74 if (cs == null) { 75 if (cs == null) {
75 List<CompletionSuggestion> completions = 76 List<CompletionSuggestion> completions =
76 request.suggestions.map((s) => s.completion).toList(); 77 request.suggestions.map((s) => s.completion).toList();
77 fail('expected "$completion" but found\n $completions'); 78 _failWithNodeInfo('expected "$completion" but found\n $completions');
78 } 79 }
79 expect(cs.kind, equals(kind)); 80 expect(cs.kind, equals(kind));
80 expect(cs.relevance, equals(relevance)); 81 expect(cs.relevance, equals(relevance));
81 expect(cs.selectionOffset, equals(completion.length)); 82 expect(cs.selectionOffset, equals(completion.length));
82 expect(cs.selectionLength, equals(0)); 83 expect(cs.selectionLength, equals(0));
83 expect(cs.isDeprecated, equals(isDeprecated)); 84 expect(cs.isDeprecated, equals(isDeprecated));
84 expect(cs.isPotential, equals(isPotential)); 85 expect(cs.isPotential, equals(isPotential));
85 return cs; 86 return cs;
86 } 87 }
87 88
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 278 }
278 return computer.computeFull(request); 279 return computer.computeFull(request);
279 } 280 }
280 281
281 @override 282 @override
282 void setUp() { 283 void setUp() {
283 super.setUp(); 284 super.setUp();
284 index = createLocalMemoryIndex(); 285 index = createLocalMemoryIndex();
285 searchEngine = new SearchEngineImpl(index); 286 searchEngine = new SearchEngineImpl(index);
286 } 287 }
288
289 void _failWithNodeInfo(String message) {
290 StringBuffer sb = new StringBuffer(message);
291 CompilationUnit unit = context.parseCompilationUnit(testSource);
292 if (unit != null) {
293 AstNode node = new NodeLocator.con1(completionOffset).searchWithin(unit);
scheglov 2014/10/02 02:28:08 We could remember the node in "computeFull".
danrubel 2014/10/02 16:27:17 Good suggestion. Done.
294 if (node != null) {
295 sb.write('\n in');
296 while (node != null) {
297 sb.write('\n ${node.runtimeType}');
298 node = node.parent;
299 }
300 }
301 }
302 fail(sb.toString());
303 }
287 } 304 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698