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

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

Issue 407833002: more progress implementing analysis server code completion (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge and address comments 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
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/constants.dart'; 9 import 'package:analysis_server/src/constants.dart';
10 import 'package:analysis_server/src/domain_completion.dart'; 10 import 'package:analysis_server/src/domain_completion.dart';
11 import 'package:analysis_server/src/protocol.dart'; 11 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analysis_services/completion/completion_suggestion.dart';
13 import 'package:analysis_services/constants.dart';
12 import 'package:analysis_services/index/index.dart' show Index; 14 import 'package:analysis_services/index/index.dart' show Index;
13 import 'package:analysis_services/index/local_memory_index.dart'; 15 import 'package:analysis_services/index/local_memory_index.dart';
14 import 'package:analysis_testing/reflective_tests.dart'; 16 import 'package:analysis_testing/reflective_tests.dart';
15 import 'package:unittest/unittest.dart'; 17 import 'package:unittest/unittest.dart';
16 18
17 import 'analysis_abstract.dart'; 19 import 'analysis_abstract.dart';
18 20
19 main() { 21 main() {
20 group('completion', () { 22 group('completion', () {
21 runReflectiveTests(CompletionTest); 23 runReflectiveTests(CompletionTest);
(...skipping 10 matching lines...) Expand all
32 String addTestFile(String content) { 34 String addTestFile(String content) {
33 completionOffset = content.indexOf('^'); 35 completionOffset = content.indexOf('^');
34 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); 36 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^');
35 int nextOffset = content.indexOf('^', completionOffset + 1); 37 int nextOffset = content.indexOf('^', completionOffset + 1);
36 expect(nextOffset, equals(-1), reason: 'too many ^'); 38 expect(nextOffset, equals(-1), reason: 'too many ^');
37 return super.addTestFile( 39 return super.addTestFile(
38 content.substring(0, completionOffset) 40 content.substring(0, completionOffset)
39 + content.substring(completionOffset + 1)); 41 + content.substring(completionOffset + 1));
40 } 42 }
41 43
42 void assertHasResult(String completion) { 44 void assertHasResult(CompletionSuggestionKind kind,
45 CompletionRelevance relevance, String completion,
46 bool isDeprecated, bool isPotential) {
43 var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse: () { 47 var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse: () {
44 var completions = suggestions.map((s) => s.completion).toList(); 48 var completions = suggestions.map((s) => s.completion).toList();
45 fail('expected "$completion" but found\n $completions'); 49 fail('expected "$completion" but found\n $completions');
46 }); 50 });
51 expect(cs.kind, equals(kind));
52 expect(cs.relevance, equals(relevance));
53 expect(cs.selectionOffset, equals(completion.length));
54 expect(cs.selectionLength, equals(0));
55 expect(cs.isDeprecated, equals(isDeprecated));
56 expect(cs.isPotential, equals(isPotential));
47 } 57 }
48 58
49 void assertValidId(String id) { 59 void assertValidId(String id) {
50 expect(id, isNotNull); 60 expect(id, isNotNull);
51 expect(id.isNotEmpty, isTrue); 61 expect(id.isNotEmpty, isTrue);
52 } 62 }
53 63
54 @override 64 @override
55 Index createIndex() { 65 Index createIndex() {
56 return createLocalMemoryIndex(); 66 return createLocalMemoryIndex();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 107 }
98 return new Future.delayed(Duration.ZERO, waitForSuggestions); 108 return new Future.delayed(Duration.ZERO, waitForSuggestions);
99 } 109 }
100 110
101 test_suggestions() { 111 test_suggestions() {
102 addTestFile(''' 112 addTestFile('''
103 import 'dart:html'; 113 import 'dart:html';
104 main() {^} 114 main() {^}
105 '''); 115 ''');
106 return getSuggestions().then((_) { 116 return getSuggestions().then((_) {
107 assertHasResult('Object'); 117 assertHasResult(CompletionSuggestionKind.CLASS,
108 assertHasResult('HtmlElement'); 118 CompletionRelevance.DEFAULT, 'Object', false, false);
119 assertHasResult(CompletionSuggestionKind.CLASS,
120 CompletionRelevance.DEFAULT, 'HtmlElement', false, false);
109 }); 121 });
110 } 122 }
111 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698