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

Side by Side Diff: pkg/analysis_server/test/domain_completion_test.dart

Issue 901253002: move relevance computation from client to server (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix test Created 5 years, 10 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
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.domain.completion; 5 library test.domain.completion;
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/channel/channel.dart'; 10 import 'package:analysis_server/src/channel/channel.dart';
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 completionOffset = content.indexOf('^'); 255 completionOffset = content.indexOf('^');
256 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); 256 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^');
257 int nextOffset = content.indexOf('^', completionOffset + 1); 257 int nextOffset = content.indexOf('^', completionOffset + 1);
258 expect(nextOffset, equals(-1), reason: 'too many ^'); 258 expect(nextOffset, equals(-1), reason: 'too many ^');
259 return super.addTestFile( 259 return super.addTestFile(
260 content.substring(0, completionOffset) + 260 content.substring(0, completionOffset) +
261 content.substring(completionOffset + 1)); 261 content.substring(completionOffset + 1));
262 } 262 }
263 263
264 void assertHasResult(CompletionSuggestionKind kind, String completion, 264 void assertHasResult(CompletionSuggestionKind kind, String completion,
265 [int relevance = COMPLETION_RELEVANCE_DEFAULT, bool isDeprecated 265 [int relevance = COMPLETION_RELEVANCE_DEFAULT, bool isDeprecated = false,
266 = false, bool isPotential = false]) { 266 bool isPotential = false]) {
267 var cs; 267 var cs;
268 suggestions.forEach((s) { 268 suggestions.forEach((s) {
269 if (s.completion == completion) { 269 if (s.completion == completion) {
270 if (cs == null) { 270 if (cs == null) {
271 cs = s; 271 cs = s;
272 } else { 272 } else {
273 fail('expected exactly one $completion but found > 1'); 273 fail('expected exactly one $completion but found > 1');
274 } 274 }
275 } 275 }
276 }); 276 });
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 assertNoResult('A'); 462 assertNoResult('A');
463 }); 463 });
464 } 464 }
465 465
466 test_locals() { 466 test_locals() {
467 addTestFile('class A {var a; x() {var b;^}}'); 467 addTestFile('class A {var a; x() {var b;^}}');
468 return getSuggestions().then((_) { 468 return getSuggestions().then((_) {
469 expect(replacementOffset, equals(completionOffset)); 469 expect(replacementOffset, equals(completionOffset));
470 expect(replacementLength, equals(0)); 470 expect(replacementLength, equals(0));
471 assertHasResult(CompletionSuggestionKind.INVOCATION, 'A'); 471 assertHasResult(CompletionSuggestionKind.INVOCATION, 'A');
472 assertHasResult(CompletionSuggestionKind.INVOCATION, 'a'); 472 assertHasResult(
473 assertHasResult(CompletionSuggestionKind.INVOCATION, 'b'); 473 CompletionSuggestionKind.INVOCATION,
474 assertHasResult(CompletionSuggestionKind.INVOCATION, 'x'); 474 'a',
475 DART_RELEVANCE_LOCAL_FIELD);
476 assertHasResult(
477 CompletionSuggestionKind.INVOCATION,
478 'b',
479 DART_RELEVANCE_LOCAL_VARIABLE);
480 assertHasResult(
481 CompletionSuggestionKind.INVOCATION,
482 'x',
483 DART_RELEVANCE_LOCAL_METHOD);
475 }); 484 });
476 } 485 }
477 486
478 test_topLevel() { 487 test_topLevel() {
479 addTestFile(''' 488 addTestFile('''
480 typedef foo(); 489 typedef foo();
481 var test = ''; 490 var test = '';
482 main() {tes^t} 491 main() {tes^t}
483 '''); 492 ''');
484 return getSuggestions().then((_) { 493 return getSuggestions().then((_) {
485 expect(replacementOffset, equals(completionOffset - 3)); 494 expect(replacementOffset, equals(completionOffset - 3));
486 expect(replacementLength, equals(4)); 495 expect(replacementLength, equals(4));
487 // Suggestions based upon imported elements are partially filtered 496 // Suggestions based upon imported elements are partially filtered
488 //assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object'); 497 //assertHasResult(CompletionSuggestionKind.INVOCATION, 'Object');
489 assertHasResult(CompletionSuggestionKind.INVOCATION, 'test'); 498 assertHasResult(
499 CompletionSuggestionKind.INVOCATION,
500 'test',
501 DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
490 assertNoResult('HtmlElement'); 502 assertNoResult('HtmlElement');
491 }); 503 });
492 } 504 }
493 } 505 }
494 506
495 class MockCache extends CompletionCache { 507 class MockCache extends CompletionCache {
496 MockCache(AnalysisContext context, Source source) : super(context, source); 508 MockCache(AnalysisContext context, Source source) : super(context, source);
497 } 509 }
498 510
499 class MockCompletionManager implements CompletionManager { 511 class MockCompletionManager implements CompletionManager {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 643
632 void contextsChangedRaw(ContextsChangedEvent newEvent) { 644 void contextsChangedRaw(ContextsChangedEvent newEvent) {
633 super.contextsChanged(newEvent); 645 super.contextsChanged(newEvent);
634 } 646 }
635 647
636 CompletionManager createCompletionManager(AnalysisContext context, 648 CompletionManager createCompletionManager(AnalysisContext context,
637 Source source, SearchEngine searchEngine) { 649 Source source, SearchEngine searchEngine) {
638 return new MockCompletionManager(mockContext, source, searchEngine); 650 return new MockCompletionManager(mockContext, source, searchEngine);
639 } 651 }
640 } 652 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698