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

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

Issue 839713002: exclude suggestions from other contexts (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 5 years, 11 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 | « pkg/analysis_server/lib/src/services/completion/dart_completion_cache.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.toplevel; 5 library test.services.completion.toplevel;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/completion/completion_manager.dart' ; 8 import 'package:analysis_server/src/services/completion/completion_manager.dart' ;
9 import 'package:analysis_server/src/services/completion/dart_completion_cache.da rt'; 9 import 'package:analysis_server/src/services/completion/dart_completion_cache.da rt';
10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 10 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
11 import 'package:analysis_server/src/services/completion/imported_computer.dart'; 11 import 'package:analysis_server/src/services/completion/imported_computer.dart';
12 import 'package:analyzer/file_system/file_system.dart';
13 import 'package:analyzer/src/generated/ast.dart';
14 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 15 import 'package:analyzer/src/generated/engine.dart';
16 import 'package:analyzer/src/generated/source.dart';
13 import 'package:unittest/unittest.dart'; 17 import 'package:unittest/unittest.dart';
14 18
19 import '../../abstract_context.dart';
15 import '../../reflective_tests.dart'; 20 import '../../reflective_tests.dart';
16 import 'completion_test_util.dart'; 21 import 'completion_test_util.dart';
17 import 'package:analyzer/src/generated/element.dart';
18 22
19 main() { 23 main() {
20 groupSep = ' | '; 24 groupSep = ' | ';
21 runReflectiveTests(ImportedComputerTest); 25 runReflectiveTests(ImportedComputerTest);
22 } 26 }
23 27
24 @ReflectiveTestCase() 28 @ReflectiveTestCase()
25 class ImportedComputerTest extends AbstractSelectorSuggestionTest { 29 class ImportedComputerTest extends AbstractSelectorSuggestionTest {
26 30
27 void assertCached(String completion) { 31 void assertCached(String completion) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return super.test_Block().then((_) { 144 return super.test_Block().then((_) {
141 expect( 145 expect(
142 request.cache.importKey, 146 request.cache.importKey,
143 'import "/testAB.dart";import "/testCD.dart" hide D;import "/testEEF.d art" show EE;import "/testG.dart" as g;'); 147 'import "/testAB.dart";import "/testCD.dart" hide D;import "/testEEF.d art" show EE;import "/testG.dart" as g;');
144 assertCached('A'); 148 assertCached('A');
145 assertCached('T3'); 149 assertCached('T3');
146 }); 150 });
147 } 151 }
148 152
149 @override 153 @override
150 test_partFile_TypeName() {
151 return super.test_partFile_TypeName().then((_) {
152 expect(
153 request.cache.importKey,
154 'part of libA;');
155 });
156 }
157
158 @override
159 test_partFile_TypeName2() {
160 return super.test_partFile_TypeName2().then((_) {
161 expect(
162 request.cache.importKey,
163 'library libA;import "/testB.dart";part "/testA.dart";');
164 });
165 }
166
167 @override
168 test_Block_inherited_imported() { 154 test_Block_inherited_imported() {
169 return super.test_Block_inherited_imported().then((_) { 155 return super.test_Block_inherited_imported().then((_) {
170 assertCached('E'); 156 assertCached('E');
171 assertCached('F'); 157 assertCached('F');
172 assertNotCached('e1'); 158 assertNotCached('e1');
173 assertNotCached('i2'); 159 assertNotCached('i2');
174 assertNotCached('m1'); 160 assertNotCached('m1');
175 }); 161 });
176 } 162 }
177 163
(...skipping 29 matching lines...) Expand all
207 class Z { }'''); 193 class Z { }''');
208 (computer as ImportedComputer).shouldWaitForLowPrioritySuggestions = false; 194 (computer as ImportedComputer).shouldWaitForLowPrioritySuggestions = false;
209 computeFast(); 195 computeFast();
210 return computeFull((bool result) { 196 return computeFull((bool result) {
211 assertSuggestImportedClass('C'); 197 assertSuggestImportedClass('C');
212 // Assert computer does not wait for or include low priority results 198 // Assert computer does not wait for or include low priority results
213 // from non-imported libraries unless instructed to do so. 199 // from non-imported libraries unless instructed to do so.
214 assertNotSuggested('H'); 200 assertNotSuggested('H');
215 }); 201 });
216 } 202 }
203
204 /**
205 * Ensure that completions in one context don't appear in another
206 */
207 test_multiple_contexts() {
208
209 // Create a 2nd context with source
210 var context2 = AnalysisEngine.instance.createAnalysisContext();
211 context2.sourceFactory =
212 new SourceFactory([AbstractContextTest.SDK_RESOLVER, resourceResolver]);
213 {
214 AnalysisOptionsImpl options =
215 new AnalysisOptionsImpl.con1(context2.analysisOptions);
216 options.enableAsync = true;
217 options.enableEnum = true;
218 context2.analysisOptions = options;
219 }
220 String content2 = 'class ClassFromAnotherContext { }';
221 Source source2 =
222 provider.newFile('/context2/foo.dart', content2).createSource();
223 ChangeSet changeSet = new ChangeSet();
224 changeSet.addedSource(source2);
225 context2.applyChanges(changeSet);
226 context2.setContents(source2, content2);
227
228 // Resolve the source in the 2nd context and update the index
229 var result = context2.performAnalysisTask();
230 while (result.hasMoreWork) {
231 result.changeNotices.forEach((ChangeNotice notice) {
232 CompilationUnit unit = notice.compilationUnit;
233 if (unit != null) {
234 index.indexUnit(context2, unit);
235 }
236 });
237 result = context2.performAnalysisTask();
238 }
239
240 // Check that source in 2nd context does not appear in completion in 1st
241 addSource('/context1/libA.dart', '''
242 library libA;
243 class ClassInLocalContext {int x;}''');
244 testFile = '/context1/completionTest.dart';
245 addTestSource('''
246 import "/context1/libA.dart";
247 import "/foo.dart";
248 main() {C^}
249 ''');
250 computeFast();
251 return computeFull((bool result) {
252 assertSuggestImportedClass('ClassInLocalContext');
253 // Assert computer does not include results from 2nd context.
254 assertNotSuggested('ClassFromAnotherContext');
255 });
256 }
257
258 @override
259 test_partFile_TypeName() {
260 return super.test_partFile_TypeName().then((_) {
261 expect(request.cache.importKey, 'part of libA;');
262 });
263 }
264
265 @override
266 test_partFile_TypeName2() {
267 return super.test_partFile_TypeName2().then((_) {
268 expect(
269 request.cache.importKey,
270 'library libA;import "/testB.dart";part "/testA.dart";');
271 });
272 }
217 } 273 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698