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

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

Issue 1317023002: show all available import completion suggestions - fixes #23955 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years, 3 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
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/import_uri_contributor.dart ('k') | 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.contributor.dart.importuri; 5 library test.services.completion.contributor.dart.importuri;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/completion/import_uri_contributor.d art'; 10 import 'package:analysis_server/src/services/completion/import_uri_contributor.d art';
11 import 'package:path/path.dart'; 11 import 'package:path/path.dart';
12 import 'package:test_reflective_loader/test_reflective_loader.dart'; 12 import 'package:test_reflective_loader/test_reflective_loader.dart';
13 import 'package:unittest/unittest.dart'; 13 import 'package:unittest/unittest.dart';
14 14
15 import '../../utils.dart'; 15 import '../../utils.dart';
16 import 'completion_test_util.dart'; 16 import 'completion_test_util.dart';
17 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
17 18
18 main() { 19 main() {
19 initializeTestEnvironment(); 20 initializeTestEnvironment();
20 defineReflectiveTests(ImportUriContributorTest); 21 defineReflectiveTests(ImportUriContributorTest);
21 } 22 }
22 23
23 @reflectiveTest 24 @reflectiveTest
24 class ImportUriContributorTest extends AbstractCompletionTest { 25 class ImportUriContributorTest extends AbstractCompletionTest {
25 @override 26 @override
26 void setUpContributor() { 27 void setUpContributor() {
(...skipping 17 matching lines...) Expand all
44 assertSuggest('dart:', csKind: CompletionSuggestionKind.IMPORT); 45 assertSuggest('dart:', csKind: CompletionSuggestionKind.IMPORT);
45 assertSuggest('package:', csKind: CompletionSuggestionKind.IMPORT); 46 assertSuggest('package:', csKind: CompletionSuggestionKind.IMPORT);
46 } 47 }
47 48
48 test_import_dart() { 49 test_import_dart() {
49 addTestSource('import "d^" import'); 50 addTestSource('import "d^" import');
50 computeFast(); 51 computeFast();
51 expect(request.replacementOffset, completionOffset - 1); 52 expect(request.replacementOffset, completionOffset - 1);
52 expect(request.replacementLength, 1); 53 expect(request.replacementLength, 1);
53 assertSuggest('dart:', csKind: CompletionSuggestionKind.IMPORT); 54 assertSuggest('dart:', csKind: CompletionSuggestionKind.IMPORT);
54 assertNotSuggested('dart:core'); 55 assertSuggest('dart:core',
56 csKind: CompletionSuggestionKind.IMPORT, relevance: DART_RELEVANCE_LOW);
55 assertNotSuggested('dart:_internal'); 57 assertNotSuggested('dart:_internal');
56 assertSuggest('dart:async', csKind: CompletionSuggestionKind.IMPORT); 58 assertSuggest('dart:async', csKind: CompletionSuggestionKind.IMPORT);
57 assertSuggest('dart:math', csKind: CompletionSuggestionKind.IMPORT); 59 assertSuggest('dart:math', csKind: CompletionSuggestionKind.IMPORT);
58 } 60 }
59 61
60 test_import_dart2() { 62 test_import_dart2() {
61 addTestSource('import "dart:async"; import "d^"'); 63 addTestSource('import "dart:async"; import "d^"');
62 computeFast(); 64 computeFast();
63 expect(request.replacementOffset, completionOffset - 1); 65 expect(request.replacementOffset, completionOffset - 1);
64 expect(request.replacementLength, 1); 66 expect(request.replacementLength, 1);
65 assertSuggest('dart:', csKind: CompletionSuggestionKind.IMPORT); 67 assertSuggest('dart:', csKind: CompletionSuggestionKind.IMPORT);
66 assertNotSuggested('dart:core'); 68 assertSuggest('dart:core',
69 csKind: CompletionSuggestionKind.IMPORT, relevance: DART_RELEVANCE_LOW);
67 assertNotSuggested('dart:_internal'); 70 assertNotSuggested('dart:_internal');
68 assertNotSuggested('dart:async'); 71 assertSuggest('dart:async', csKind: CompletionSuggestionKind.IMPORT);
69 assertSuggest('dart:math', csKind: CompletionSuggestionKind.IMPORT); 72 assertSuggest('dart:math', csKind: CompletionSuggestionKind.IMPORT);
70 } 73 }
71 74
72 test_import_file() { 75 test_import_file() {
73 // TODO(danrubel) fix file uri suggestions on Windows 76 // TODO(danrubel) fix file uri suggestions on Windows
74 if (Platform.isWindows) return; 77 if (Platform.isWindows) return;
75 testFile = '/proj/completion.dart'; 78 testFile = '/proj/completion.dart';
76 addSource('/proj/other.dart', 'library other;'); 79 addSource('/proj/other.dart', 'library other;');
77 addSource('/proj/foo/bar.dart', 'library bar;'); 80 addSource('/proj/foo/bar.dart', 'library bar;');
78 addSource('/blat.dart', 'library blat;'); 81 addSource('/blat.dart', 'library blat;');
79 addTestSource('import "^" import'); 82 addTestSource('import "^" import');
80 computeFast(); 83 computeFast();
81 expect(request.replacementOffset, completionOffset); 84 expect(request.replacementOffset, completionOffset);
82 expect(request.replacementLength, 0); 85 expect(request.replacementLength, 0);
83 assertNotSuggested('completion.dart'); 86 assertNotSuggested('completion.dart');
84 assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT); 87 assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT);
85 assertNotSuggested('foo'); 88 assertNotSuggested('foo');
86 assertSuggest('foo${separator}', csKind: CompletionSuggestionKind.IMPORT); 89 assertSuggest('foo/', csKind: CompletionSuggestionKind.IMPORT);
87 assertNotSuggested('foo${separator}bar.dart'); 90 assertNotSuggested('foo/bar.dart');
88 assertNotSuggested('..${separator}blat.dart'); 91 assertNotSuggested('../blat.dart');
89 } 92 }
90 93
91 test_import_file2() { 94 test_import_file2() {
92 // TODO(danrubel) fix file uri suggestions on Windows 95 // TODO(danrubel) fix file uri suggestions on Windows
93 if (Platform.isWindows) return; 96 if (Platform.isWindows) return;
94 testFile = '/proj/completion.dart'; 97 testFile = '/proj/completion.dart';
95 addSource('/proj/other.dart', 'library other;'); 98 addSource('/proj/other.dart', 'library other;');
96 addSource('/proj/foo/bar.dart', 'library bar;'); 99 addSource('/proj/foo/bar.dart', 'library bar;');
97 addSource('/blat.dart', 'library blat;'); 100 addSource('/blat.dart', 'library blat;');
98 addTestSource('import "..^" import'); 101 addTestSource('import "..^" import');
99 computeFast(); 102 computeFast();
100 expect(request.replacementOffset, completionOffset - 2); 103 expect(request.replacementOffset, completionOffset - 2);
101 expect(request.replacementLength, 2); 104 expect(request.replacementLength, 2);
102 assertNotSuggested('completion.dart'); 105 assertNotSuggested('completion.dart');
103 assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT); 106 assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT);
104 assertNotSuggested('foo'); 107 assertNotSuggested('foo');
105 assertSuggest('foo${separator}', csKind: CompletionSuggestionKind.IMPORT); 108 assertSuggest('foo/', csKind: CompletionSuggestionKind.IMPORT);
106 assertNotSuggested('foo${separator}bar.dart'); 109 assertNotSuggested('foo/bar.dart');
107 assertNotSuggested('..${separator}blat.dart'); 110 assertNotSuggested('../blat.dart');
108 } 111 }
109 112
110 test_import_file_child() { 113 test_import_file_child() {
111 // TODO(danrubel) fix file uri suggestions on Windows 114 // TODO(danrubel) fix file uri suggestions on Windows
112 if (Platform.isWindows) return; 115 if (Platform.isWindows) return;
113 testFile = '/proj/completion.dart'; 116 testFile = '/proj/completion.dart';
114 addSource('/proj/other.dart', 'library other;'); 117 addSource('/proj/other.dart', 'library other;');
115 addSource('/proj/foo/bar.dart', 'library bar;'); 118 addSource('/proj/foo/bar.dart', 'library bar;');
116 addSource('/blat.dart', 'library blat;'); 119 addSource('/blat.dart', 'library blat;');
117 addTestSource('import "foo/^" import'); 120 addTestSource('import "foo/^" import');
118 computeFast(); 121 computeFast();
119 expect(request.replacementOffset, completionOffset - 4); 122 expect(request.replacementOffset, completionOffset - 4);
120 expect(request.replacementLength, 4); 123 expect(request.replacementLength, 4);
121 assertNotSuggested('completion.dart'); 124 assertNotSuggested('completion.dart');
122 assertNotSuggested('other.dart'); 125 assertNotSuggested('other.dart');
123 assertNotSuggested('foo'); 126 assertNotSuggested('foo');
124 assertNotSuggested('foo${separator}'); 127 assertNotSuggested('foo/');
125 assertSuggest('foo${separator}bar.dart', 128 assertSuggest('foo/bar.dart', csKind: CompletionSuggestionKind.IMPORT);
126 csKind: CompletionSuggestionKind.IMPORT); 129 assertNotSuggested('../blat.dart');
127 assertNotSuggested('..${separator}blat.dart');
128 } 130 }
129 131
130 test_import_file_parent() { 132 test_import_file_parent() {
131 // TODO(danrubel) fix file uri suggestions on Windows 133 // TODO(danrubel) fix file uri suggestions on Windows
132 if (Platform.isWindows) return; 134 if (Platform.isWindows) return;
133 testFile = '/proj/completion.dart'; 135 testFile = '/proj/completion.dart';
134 addSource('/proj/other.dart', 'library other;'); 136 addSource('/proj/other.dart', 'library other;');
135 addSource('/proj/foo/bar.dart', 'library bar;'); 137 addSource('/proj/foo/bar.dart', 'library bar;');
136 addSource('/blat.dart', 'library blat;'); 138 addSource('/blat.dart', 'library blat;');
137 addTestSource('import "../^" import'); 139 addTestSource('import "../^" import');
138 computeFast(); 140 computeFast();
139 expect(request.replacementOffset, completionOffset - 3); 141 expect(request.replacementOffset, completionOffset - 3);
140 expect(request.replacementLength, 3); 142 expect(request.replacementLength, 3);
141 assertNotSuggested('completion.dart'); 143 assertNotSuggested('completion.dart');
142 assertNotSuggested('other.dart'); 144 assertNotSuggested('other.dart');
143 assertNotSuggested('foo'); 145 assertNotSuggested('foo');
144 assertNotSuggested('foo${separator}'); 146 assertNotSuggested('foo/');
145 assertNotSuggested('foo${separator}bar.dart'); 147 assertNotSuggested('foo/bar.dart');
146 assertSuggest('..${separator}blat.dart', 148 assertSuggest('../blat.dart', csKind: CompletionSuggestionKind.IMPORT);
147 csKind: CompletionSuggestionKind.IMPORT);
148 } 149 }
149 150
150 test_import_package() { 151 test_import_package() {
151 addPackageSource('foo', 'foo.dart', 'library foo;'); 152 addPackageSource('foo', 'foo.dart', 'library foo;');
152 addPackageSource('foo', 'baz/too.dart', 'library too;'); 153 addPackageSource('foo', 'baz/too.dart', 'library too;');
153 addPackageSource('bar', 'bar.dart', 'library bar;'); 154 addPackageSource('bar', 'bar.dart', 'library bar;');
154 addTestSource('import "p^" import'); 155 addTestSource('import "p^" import');
155 computeFast(); 156 computeFast();
156 expect(request.replacementOffset, completionOffset - 1); 157 expect(request.replacementOffset, completionOffset - 1);
157 expect(request.replacementLength, 1); 158 expect(request.replacementLength, 1);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 addSource('/proj/other.dart', 'library other;'); 212 addSource('/proj/other.dart', 'library other;');
212 addSource('/proj/foo/bar.dart', 'library bar;'); 213 addSource('/proj/foo/bar.dart', 'library bar;');
213 addSource('/blat.dart', 'library blat;'); 214 addSource('/blat.dart', 'library blat;');
214 addTestSource('library x; part "^" import'); 215 addTestSource('library x; part "^" import');
215 computeFast(); 216 computeFast();
216 expect(request.replacementOffset, completionOffset); 217 expect(request.replacementOffset, completionOffset);
217 expect(request.replacementLength, 0); 218 expect(request.replacementLength, 0);
218 assertNotSuggested('completion.dart'); 219 assertNotSuggested('completion.dart');
219 assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT); 220 assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT);
220 assertNotSuggested('foo'); 221 assertNotSuggested('foo');
221 assertSuggest('foo${separator}', csKind: CompletionSuggestionKind.IMPORT); 222 assertSuggest('foo/', csKind: CompletionSuggestionKind.IMPORT);
222 assertNotSuggested('foo${separator}bar.dart'); 223 assertNotSuggested('foo/bar.dart');
223 assertNotSuggested('..${separator}blat.dart'); 224 assertNotSuggested('../blat.dart');
224 } 225 }
225 226
226 test_part_file2() { 227 test_part_file2() {
227 // TODO(danrubel) fix file uri suggestions on Windows 228 // TODO(danrubel) fix file uri suggestions on Windows
228 if (Platform.isWindows) return; 229 if (Platform.isWindows) return;
229 testFile = '/proj/completion.dart'; 230 testFile = '/proj/completion.dart';
230 addSource('/proj/other.dart', 'library other;'); 231 addSource('/proj/other.dart', 'library other;');
231 addSource('/proj/foo/bar.dart', 'library bar;'); 232 addSource('/proj/foo/bar.dart', 'library bar;');
232 addSource('/blat.dart', 'library blat;'); 233 addSource('/blat.dart', 'library blat;');
233 addTestSource('library x; part "..^" import'); 234 addTestSource('library x; part "..^" import');
234 computeFast(); 235 computeFast();
235 expect(request.replacementOffset, completionOffset - 2); 236 expect(request.replacementOffset, completionOffset - 2);
236 expect(request.replacementLength, 2); 237 expect(request.replacementLength, 2);
237 assertNotSuggested('completion.dart'); 238 assertNotSuggested('completion.dart');
238 assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT); 239 assertSuggest('other.dart', csKind: CompletionSuggestionKind.IMPORT);
239 assertNotSuggested('foo'); 240 assertNotSuggested('foo');
240 assertSuggest('foo${separator}', csKind: CompletionSuggestionKind.IMPORT); 241 assertSuggest('foo/', csKind: CompletionSuggestionKind.IMPORT);
241 assertNotSuggested('foo${separator}bar.dart'); 242 assertNotSuggested('foo/bar.dart');
242 assertNotSuggested('..${separator}blat.dart'); 243 assertNotSuggested('../blat.dart');
243 } 244 }
244 245
245 test_part_file_child() { 246 test_part_file_child() {
246 // TODO(danrubel) fix file uri suggestions on Windows 247 // TODO(danrubel) fix file uri suggestions on Windows
247 if (Platform.isWindows) return; 248 if (Platform.isWindows) return;
248 testFile = '/proj/completion.dart'; 249 testFile = '/proj/completion.dart';
249 addSource('/proj/other.dart', 'library other;'); 250 addSource('/proj/other.dart', 'library other;');
250 addSource('/proj/foo/bar.dart', 'library bar;'); 251 addSource('/proj/foo/bar.dart', 'library bar;');
251 addSource('/blat.dart', 'library blat;'); 252 addSource('/blat.dart', 'library blat;');
252 addTestSource('library x; part "foo/^" import'); 253 addTestSource('library x; part "foo/^" import');
253 computeFast(); 254 computeFast();
254 expect(request.replacementOffset, completionOffset - 4); 255 expect(request.replacementOffset, completionOffset - 4);
255 expect(request.replacementLength, 4); 256 expect(request.replacementLength, 4);
256 assertNotSuggested('completion.dart'); 257 assertNotSuggested('completion.dart');
257 assertNotSuggested('other.dart'); 258 assertNotSuggested('other.dart');
258 assertNotSuggested('foo'); 259 assertNotSuggested('foo');
259 assertNotSuggested('foo${separator}'); 260 assertNotSuggested('foo/');
260 assertSuggest('foo${separator}bar.dart', 261 assertSuggest('foo/bar.dart', csKind: CompletionSuggestionKind.IMPORT);
261 csKind: CompletionSuggestionKind.IMPORT); 262 assertNotSuggested('../blat.dart');
262 assertNotSuggested('..${separator}blat.dart');
263 } 263 }
264 264
265 test_part_file_parent() { 265 test_part_file_parent() {
266 // TODO(danrubel) fix file uri suggestions on Windows 266 // TODO(danrubel) fix file uri suggestions on Windows
267 if (Platform.isWindows) return; 267 if (Platform.isWindows) return;
268 testFile = '/proj/completion.dart'; 268 testFile = '/proj/completion.dart';
269 addSource('/proj/other.dart', 'library other;'); 269 addSource('/proj/other.dart', 'library other;');
270 addSource('/proj/foo/bar.dart', 'library bar;'); 270 addSource('/proj/foo/bar.dart', 'library bar;');
271 addSource('/blat.dart', 'library blat;'); 271 addSource('/blat.dart', 'library blat;');
272 addTestSource('library x; part "../^" import'); 272 addTestSource('library x; part "../^" import');
273 computeFast(); 273 computeFast();
274 expect(request.replacementOffset, completionOffset - 3); 274 expect(request.replacementOffset, completionOffset - 3);
275 expect(request.replacementLength, 3); 275 expect(request.replacementLength, 3);
276 assertNotSuggested('completion.dart'); 276 assertNotSuggested('completion.dart');
277 assertNotSuggested('other.dart'); 277 assertNotSuggested('other.dart');
278 assertNotSuggested('foo'); 278 assertNotSuggested('foo');
279 assertNotSuggested('foo${separator}'); 279 assertNotSuggested('foo/');
280 assertNotSuggested('foo${separator}bar.dart'); 280 assertNotSuggested('foo/bar.dart');
281 assertSuggest('..${separator}blat.dart', 281 assertSuggest('../blat.dart', csKind: CompletionSuggestionKind.IMPORT);
282 csKind: CompletionSuggestionKind.IMPORT);
283 } 282 }
284 } 283 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/import_uri_contributor.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698