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

Side by Side Diff: pkg/analyzer/test/generated/engine_test.dart

Issue 737673002: add source changed event stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments Created 6 years, 1 month 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/analyzer/lib/src/generated/engine.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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.engine_test; 8 library engine.engine_test;
9 9
10 import 'dart:async';
10 import 'dart:collection'; 11 import 'dart:collection';
11 12
12 import 'package:analyzer/src/generated/ast.dart'; 13 import 'package:analyzer/src/generated/ast.dart';
13 import 'package:analyzer/src/generated/constant.dart'; 14 import 'package:analyzer/src/generated/constant.dart';
14 import 'package:analyzer/src/generated/element.dart'; 15 import 'package:analyzer/src/generated/element.dart';
15 import 'package:analyzer/src/generated/engine.dart'; 16 import 'package:analyzer/src/generated/engine.dart';
16 import 'package:analyzer/src/generated/error.dart'; 17 import 'package:analyzer/src/generated/error.dart';
17 import 'package:analyzer/src/generated/html.dart' as ht; 18 import 'package:analyzer/src/generated/html.dart' as ht;
18 import 'package:analyzer/src/generated/java_core.dart'; 19 import 'package:analyzer/src/generated/java_core.dart';
19 import 'package:analyzer/src/generated/java_engine.dart'; 20 import 'package:analyzer/src/generated/java_engine.dart';
20 import 'package:analyzer/src/generated/java_engine_io.dart'; 21 import 'package:analyzer/src/generated/java_engine_io.dart';
21 import 'package:analyzer/src/generated/parser.dart'; 22 import 'package:analyzer/src/generated/parser.dart';
22 import 'package:analyzer/src/generated/resolver.dart'; 23 import 'package:analyzer/src/generated/resolver.dart';
23 import 'package:analyzer/src/generated/scanner.dart'; 24 import 'package:analyzer/src/generated/scanner.dart';
24 import 'package:analyzer/src/generated/sdk.dart'; 25 import 'package:analyzer/src/generated/sdk.dart';
25 import 'package:analyzer/src/generated/sdk_io.dart'; 26 import 'package:analyzer/src/generated/sdk_io.dart';
26 import 'package:analyzer/src/generated/source_io.dart'; 27 import 'package:analyzer/src/generated/source_io.dart';
27 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 28 import 'package:analyzer/src/generated/testing/ast_factory.dart';
28 import 'package:analyzer/src/generated/testing/element_factory.dart'; 29 import 'package:analyzer/src/generated/testing/element_factory.dart';
29 import 'package:analyzer/src/generated/utilities_collection.dart'; 30 import 'package:analyzer/src/generated/utilities_collection.dart';
31 import 'package:analyzer/src/string_source.dart';
30 import 'package:analyzer/src/task/task_dart.dart'; 32 import 'package:analyzer/src/task/task_dart.dart';
31 import 'package:typed_mock/typed_mock.dart'; 33 import 'package:typed_mock/typed_mock.dart';
32 import 'package:unittest/unittest.dart'; 34 import 'package:unittest/unittest.dart';
35 import 'package:watcher/src/utils.dart';
33 36
34 import '../reflective_tests.dart'; 37 import '../reflective_tests.dart';
35 import 'all_the_rest.dart'; 38 import 'all_the_rest.dart';
36 import 'resolver_test.dart'; 39 import 'resolver_test.dart';
37 import 'test_support.dart'; 40 import 'test_support.dart';
38 41
39 42
40 main() { 43 main() {
41 groupSep = ' | '; 44 groupSep = ' | ';
42 runReflectiveTests(AnalysisCacheTest); 45 runReflectiveTests(AnalysisCacheTest);
43 runReflectiveTests(AnalysisContextImplTest); 46 runReflectiveTests(AnalysisContextImplTest);
44 runReflectiveTests(AnalysisTaskTest); 47 runReflectiveTests(AnalysisTaskTest);
45 runReflectiveTests(AnalysisOptionsImplTest); 48 runReflectiveTests(AnalysisOptionsImplTest);
46 runReflectiveTests(DartEntryTest); 49 runReflectiveTests(DartEntryTest);
47 runReflectiveTests(GenerateDartErrorsTaskTest); 50 runReflectiveTests(GenerateDartErrorsTaskTest);
48 runReflectiveTests(GenerateDartHintsTaskTest); 51 runReflectiveTests(GenerateDartHintsTaskTest);
49 runReflectiveTests(GetContentTaskTest); 52 runReflectiveTests(GetContentTaskTest);
50 runReflectiveTests(HtmlEntryTest); 53 runReflectiveTests(HtmlEntryTest);
51 runReflectiveTests(IncrementalAnalysisCacheTest); 54 runReflectiveTests(IncrementalAnalysisCacheTest);
52 runReflectiveTests(InstrumentedAnalysisContextImplTest); 55 runReflectiveTests(InstrumentedAnalysisContextImplTest);
53 runReflectiveTests(IncrementalAnalysisTaskTest); 56 runReflectiveTests(IncrementalAnalysisTaskTest);
54 runReflectiveTests(ParseDartTaskTest); 57 runReflectiveTests(ParseDartTaskTest);
55 runReflectiveTests(ParseHtmlTaskTest); 58 runReflectiveTests(ParseHtmlTaskTest);
56 runReflectiveTests(PartitionManagerTest); 59 runReflectiveTests(PartitionManagerTest);
57 runReflectiveTests(ResolveDartLibraryTaskTest); 60 runReflectiveTests(ResolveDartLibraryTaskTest);
58 runReflectiveTests(ResolveDartUnitTaskTest); 61 runReflectiveTests(ResolveDartUnitTaskTest);
59 runReflectiveTests(ResolveHtmlTaskTest); 62 runReflectiveTests(ResolveHtmlTaskTest);
60 runReflectiveTests(ScanDartTaskTest); 63 runReflectiveTests(ScanDartTaskTest);
61 runReflectiveTests(SdkCachePartitionTest); 64 runReflectiveTests(SdkCachePartitionTest);
65 runReflectiveTests(SourcesChangedEventTest);
62 runReflectiveTests(UniversalCachePartitionTest); 66 runReflectiveTests(UniversalCachePartitionTest);
63 runReflectiveTests(WorkManagerTest); 67 runReflectiveTests(WorkManagerTest);
64 } 68 }
65 69
66 70
67 class AnalysisCacheTest extends EngineTestCase { 71 class AnalysisCacheTest extends EngineTestCase {
68 void test_creation() { 72 void test_creation() {
69 expect(new AnalysisCache(new List<CachePartition>(0)), isNotNull); 73 expect(new AnalysisCache(new List<CachePartition>(0)), isNotNull);
70 } 74 }
71 75
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 _context.analysisOptions = options; 221 _context.analysisOptions = options;
218 } 222 }
219 223
220 @override 224 @override
221 void tearDown() { 225 void tearDown() {
222 _context = null; 226 _context = null;
223 _sourceFactory = null; 227 _sourceFactory = null;
224 super.tearDown(); 228 super.tearDown();
225 } 229 }
226 230
227 void test_applyChanges_add() { 231 Future test_applyChanges_add() {
232 SourcesChangedListener listener = new SourcesChangedListener();
233 _context.onSourcesChanged.listen(listener.onData);
228 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); 234 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue);
229 Source source = _addSource("/test.dart", "main() {}"); 235 Source source =
236 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
237 ChangeSet changeSet = new ChangeSet();
238 changeSet.addedSource(source);
239 _context.applyChanges(changeSet);
230 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); 240 expect(_context.sourcesNeedingProcessing.contains(source), isTrue);
241 return pumpEventQueue().then((_) {
242 listener.assertEvent(wereSourcesAdded: true);
243 listener.assertNoMoreEvents();
244 });
245 }
246
247 Future test_applyChanges_change() {
248 SourcesChangedListener listener = new SourcesChangedListener();
249 _context.onSourcesChanged.listen(listener.onData);
250 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue);
251 Source source =
252 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
253 ChangeSet changeSet1 = new ChangeSet();
254 changeSet1.addedSource(source);
255 _context.applyChanges(changeSet1);
256 expect(_context.sourcesNeedingProcessing.contains(source), isTrue);
257 Source source2 =
258 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart"));
259 ChangeSet changeSet2 = new ChangeSet();
260 changeSet2.addedSource(source2);
261 changeSet2.changedSource(source);
262 _context.applyChanges(changeSet2);
263 return pumpEventQueue().then((_) {
264 listener.assertEvent(wereSourcesAdded: true);
265 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]);
266 listener.assertNoMoreEvents();
267 });
268 }
269
270 Future test_applyChanges_change_content() {
271 SourcesChangedListener listener = new SourcesChangedListener();
272 _context.onSourcesChanged.listen(listener.onData);
273 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue);
274 Source source =
275 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
276 ChangeSet changeSet1 = new ChangeSet();
277 changeSet1.addedSource(source);
278 _context.applyChanges(changeSet1);
279 expect(_context.sourcesNeedingProcessing.contains(source), isTrue);
280 Source source2 =
281 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart"));
282 ChangeSet changeSet2 = new ChangeSet();
283 changeSet2.addedSource(source2);
284 changeSet2.changedContent(source, 'library test;');
285 _context.applyChanges(changeSet2);
286 return pumpEventQueue().then((_) {
287 listener.assertEvent(wereSourcesAdded: true);
288 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]);
289 listener.assertNoMoreEvents();
290 });
231 } 291 }
232 292
233 void test_applyChanges_change_flush_element() { 293 void test_applyChanges_change_flush_element() {
234 _context = AnalysisContextFactory.contextWithCore(); 294 _context = AnalysisContextFactory.contextWithCore();
235 _sourceFactory = _context.sourceFactory; 295 _sourceFactory = _context.sourceFactory;
236 Source librarySource = _addSource("/lib.dart", r''' 296 Source librarySource = _addSource("/lib.dart", r'''
237 library lib; 297 library lib;
238 int a = 0;'''); 298 int a = 0;''');
239 expect(_context.computeLibraryElement(librarySource), isNotNull); 299 expect(_context.computeLibraryElement(librarySource), isNotNull);
240 _context.setContents(librarySource, r''' 300 _context.setContents(librarySource, r'''
241 library lib; 301 library lib;
242 int aa = 0;'''); 302 int aa = 0;''');
243 expect(_context.getLibraryElement(librarySource), isNull); 303 expect(_context.getLibraryElement(librarySource), isNull);
244 } 304 }
245 305
246 void test_applyChanges_change_multiple() { 306 Future test_applyChanges_change_multiple() {
247 _context = AnalysisContextFactory.contextWithCore(); 307 _context = AnalysisContextFactory.contextWithCore();
308 SourcesChangedListener listener = new SourcesChangedListener();
309 _context.onSourcesChanged.listen(listener.onData);
248 _sourceFactory = _context.sourceFactory; 310 _sourceFactory = _context.sourceFactory;
249 Source librarySource = _addSource("/lib.dart", r''' 311 String libraryContents1 = r'''
250 library lib; 312 library lib;
251 part 'part.dart'; 313 part 'part.dart';
252 int a = 0;'''); 314 int a = 0;''';
253 Source partSource = _addSource("/part.dart", r''' 315 Source librarySource = _addSource("/lib.dart", libraryContents1);
316 String partContents1 = r'''
254 part of lib; 317 part of lib;
255 int b = a;'''); 318 int b = a;''';
319 Source partSource = _addSource("/part.dart", partContents1);
256 _context.computeLibraryElement(librarySource); 320 _context.computeLibraryElement(librarySource);
257 _context.setContents(librarySource, r''' 321 String libraryContents2 = r'''
258 library lib; 322 library lib;
259 part 'part.dart'; 323 part 'part.dart';
260 int aa = 0;'''); 324 int aa = 0;''';
261 _context.setContents(partSource, r''' 325 _context.setContents(librarySource, libraryContents2);
326 String partContents2 = r'''
262 part of lib; 327 part of lib;
263 int b = aa;'''); 328 int b = aa;''';
329 _context.setContents(partSource, partContents2);
264 _context.computeLibraryElement(librarySource); 330 _context.computeLibraryElement(librarySource);
265 CompilationUnit libraryUnit = 331 CompilationUnit libraryUnit =
266 _context.resolveCompilationUnit2(librarySource, librarySource); 332 _context.resolveCompilationUnit2(librarySource, librarySource);
267 CompilationUnit partUnit = 333 CompilationUnit partUnit =
268 _context.resolveCompilationUnit2(partSource, librarySource); 334 _context.resolveCompilationUnit2(partSource, librarySource);
269 TopLevelVariableDeclaration declaration = 335 TopLevelVariableDeclaration declaration =
270 libraryUnit.declarations[0] as TopLevelVariableDeclaration; 336 libraryUnit.declarations[0] as TopLevelVariableDeclaration;
271 Element declarationElement = declaration.variables.variables[0].element; 337 Element declarationElement = declaration.variables.variables[0].element;
272 TopLevelVariableDeclaration use = 338 TopLevelVariableDeclaration use =
273 partUnit.declarations[0] as TopLevelVariableDeclaration; 339 partUnit.declarations[0] as TopLevelVariableDeclaration;
274 Element useElement = 340 Element useElement =
275 (use.variables.variables[0].initializer as SimpleIdentifier).staticEleme nt; 341 (use.variables.variables[0].initializer as SimpleIdentifier).staticEleme nt;
276 expect( 342 expect(
277 (useElement as PropertyAccessorElement).variable, 343 (useElement as PropertyAccessorElement).variable,
278 same(declarationElement)); 344 same(declarationElement));
345 return pumpEventQueue().then((_) {
346 listener.assertEvent(wereSourcesAdded: true);
347 listener.assertEvent(changedSources: [librarySource]);
348 listener.assertEvent(wereSourcesAdded: true);
349 listener.assertEvent(changedSources: [partSource]);
350 listener.assertEvent(changedSources: [librarySource]);
351 listener.assertEvent(changedSources: [partSource]);
352 listener.assertNoMoreEvents();
353 });
354 }
355
356 Future test_applyChanges_change_range() {
357 SourcesChangedListener listener = new SourcesChangedListener();
358 _context.onSourcesChanged.listen(listener.onData);
359 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue);
360 Source source =
361 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
362 ChangeSet changeSet1 = new ChangeSet();
363 changeSet1.addedSource(source);
364 _context.applyChanges(changeSet1);
365 expect(_context.sourcesNeedingProcessing.contains(source), isTrue);
366 Source source2 =
367 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart"));
368 ChangeSet changeSet2 = new ChangeSet();
369 changeSet2.addedSource(source2);
370 changeSet2.changedRange(source, 'library test;', 0, 0, 13);
371 _context.applyChanges(changeSet2);
372 return pumpEventQueue().then((_) {
373 listener.assertEvent(wereSourcesAdded: true);
374 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]);
375 listener.assertNoMoreEvents();
376 });
279 } 377 }
280 378
281 void test_applyChanges_empty() { 379 void test_applyChanges_empty() {
282 _context.applyChanges(new ChangeSet()); 380 _context.applyChanges(new ChangeSet());
283 expect(_context.performAnalysisTask().changeNotices, isNull); 381 expect(_context.performAnalysisTask().changeNotices, isNull);
284 } 382 }
285 383
286 void test_applyChanges_overriddenSource() { 384 void test_applyChanges_overriddenSource() {
287 // Note: addSource adds the source to the contentCache. 385 // Note: addSource adds the source to the contentCache.
288 Source source = _addSource("/test.dart", "library test;"); 386 Source source = _addSource("/test.dart", "library test;");
289 _context.computeErrors(source); 387 _context.computeErrors(source);
290 while (!_context.sourcesNeedingProcessing.isEmpty) { 388 while (!_context.sourcesNeedingProcessing.isEmpty) {
291 _context.performAnalysisTask(); 389 _context.performAnalysisTask();
292 } 390 }
293 // Adding the source as a changedSource should have no effect since 391 // Adding the source as a changedSource should have no effect since
294 // it is already overridden in the content cache. 392 // it is already overridden in the content cache.
295 ChangeSet changeSet = new ChangeSet(); 393 ChangeSet changeSet = new ChangeSet();
296 changeSet.changedSource(source); 394 changeSet.changedSource(source);
297 _context.applyChanges(changeSet); 395 _context.applyChanges(changeSet);
298 expect(_context.sourcesNeedingProcessing, hasLength(0)); 396 expect(_context.sourcesNeedingProcessing, hasLength(0));
299 } 397 }
300 398
301 void test_applyChanges_remove() { 399 Future test_applyChanges_remove() {
302 _context = AnalysisContextFactory.contextWithCore(); 400 _context = AnalysisContextFactory.contextWithCore();
401 SourcesChangedListener listener = new SourcesChangedListener();
402 _context.onSourcesChanged.listen(listener.onData);
303 _sourceFactory = _context.sourceFactory; 403 _sourceFactory = _context.sourceFactory;
304 Source libA = _addSource("/libA.dart", r''' 404 String libAContents = r'''
305 library libA; 405 library libA;
306 import 'libB.dart';'''); 406 import 'libB.dart';''';
307 Source libB = _addSource("/libB.dart", "library libB;"); 407 Source libA = _addSource("/libA.dart", libAContents);
408 String libBContents = "library libB;";
409 Source libB = _addSource("/libB.dart", libBContents);
308 LibraryElement libAElement = _context.computeLibraryElement(libA); 410 LibraryElement libAElement = _context.computeLibraryElement(libA);
309 List<LibraryElement> importedLibraries = libAElement.importedLibraries; 411 List<LibraryElement> importedLibraries = libAElement.importedLibraries;
310 expect(importedLibraries, hasLength(2)); 412 expect(importedLibraries, hasLength(2));
311 _context.computeErrors(libA); 413 _context.computeErrors(libA);
312 _context.computeErrors(libB); 414 _context.computeErrors(libB);
313 expect(_context.sourcesNeedingProcessing, hasLength(0)); 415 expect(_context.sourcesNeedingProcessing, hasLength(0));
314 _context.setContents(libB, null); 416 _context.setContents(libB, null);
315 _removeSource(libB); 417 _removeSource(libB);
316 List<Source> sources = _context.sourcesNeedingProcessing; 418 List<Source> sources = _context.sourcesNeedingProcessing;
317 expect(sources, hasLength(1)); 419 expect(sources, hasLength(1));
318 expect(sources[0], same(libA)); 420 expect(sources[0], same(libA));
319 libAElement = _context.computeLibraryElement(libA); 421 libAElement = _context.computeLibraryElement(libA);
320 importedLibraries = libAElement.importedLibraries; 422 importedLibraries = libAElement.importedLibraries;
321 expect(importedLibraries, hasLength(1)); 423 expect(importedLibraries, hasLength(1));
424 return pumpEventQueue().then((_) {
425 listener.assertEvent(wereSourcesAdded: true);
426 listener.assertEvent(changedSources: [libA]);
427 listener.assertEvent(wereSourcesAdded: true);
428 listener.assertEvent(changedSources: [libB]);
429 listener.assertEvent(changedSources: [libB]);
430 listener.assertEvent(wereSourcesRemovedOrDeleted: true);
431 listener.assertNoMoreEvents();
432 });
322 } 433 }
323 434
324 void test_applyChanges_removeContainer() { 435 Future test_applyChanges_removeContainer() {
325 _context = AnalysisContextFactory.contextWithCore(); 436 _context = AnalysisContextFactory.contextWithCore();
437 SourcesChangedListener listener = new SourcesChangedListener();
438 _context.onSourcesChanged.listen(listener.onData);
326 _sourceFactory = _context.sourceFactory; 439 _sourceFactory = _context.sourceFactory;
327 Source libA = _addSource("/libA.dart", r''' 440 String libAContents = r'''
328 library libA; 441 library libA;
329 import 'libB.dart';'''); 442 import 'libB.dart';''';
330 Source libB = _addSource("/libB.dart", "library libB;"); 443 Source libA = _addSource("/libA.dart", libAContents);
444 String libBContents = "library libB;";
445 Source libB = _addSource("/libB.dart", libBContents);
331 _context.computeLibraryElement(libA); 446 _context.computeLibraryElement(libA);
332 _context.computeErrors(libA); 447 _context.computeErrors(libA);
333 _context.computeErrors(libB); 448 _context.computeErrors(libB);
334 expect(_context.sourcesNeedingProcessing, hasLength(0)); 449 expect(_context.sourcesNeedingProcessing, hasLength(0));
335 ChangeSet changeSet = new ChangeSet(); 450 ChangeSet changeSet = new ChangeSet();
336 changeSet.removedContainer( 451 SourceContainer removedContainer =
337 new _AnalysisContextImplTest_test_applyChanges_removeContainer(libB)); 452 new _AnalysisContextImplTest_test_applyChanges_removeContainer(libB);
453 changeSet.removedContainer(removedContainer);
338 _context.applyChanges(changeSet); 454 _context.applyChanges(changeSet);
339 List<Source> sources = _context.sourcesNeedingProcessing; 455 List<Source> sources = _context.sourcesNeedingProcessing;
340 expect(sources, hasLength(1)); 456 expect(sources, hasLength(1));
341 expect(sources[0], same(libA)); 457 expect(sources[0], same(libA));
458 return pumpEventQueue().then((_) {
459 listener.assertEvent(wereSourcesAdded: true);
460 listener.assertEvent(changedSources: [libA]);
461 listener.assertEvent(wereSourcesAdded: true);
462 listener.assertEvent(changedSources: [libB]);
463 listener.assertEvent(wereSourcesRemovedOrDeleted: true);
464 listener.assertNoMoreEvents();
465 });
342 } 466 }
343 467
344 void test_computeDocumentationComment_block() { 468 void test_computeDocumentationComment_block() {
345 _context = AnalysisContextFactory.contextWithCore(); 469 _context = AnalysisContextFactory.contextWithCore();
346 _sourceFactory = _context.sourceFactory; 470 _sourceFactory = _context.sourceFactory;
347 String comment = "/** Comment */"; 471 String comment = "/** Comment */";
348 Source source = _addSource("/test.dart", """ 472 Source source = _addSource("/test.dart", """
349 $comment 473 $comment
350 class A {}"""); 474 class A {}""");
351 LibraryElement libraryElement = _context.computeLibraryElement(source); 475 LibraryElement libraryElement = _context.computeLibraryElement(source);
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 _context.analysisPriorityOrder = sources; 1742 _context.analysisPriorityOrder = sources;
1619 expect(options.cacheSize > _getPriorityOrder(_context).length, isTrue); 1743 expect(options.cacheSize > _getPriorityOrder(_context).length, isTrue);
1620 } 1744 }
1621 1745
1622 void test_setAnalysisPriorityOrder_nonEmpty() { 1746 void test_setAnalysisPriorityOrder_nonEmpty() {
1623 List<Source> sources = new List<Source>(); 1747 List<Source> sources = new List<Source>();
1624 sources.add(_addSource("/lib.dart", "library lib;")); 1748 sources.add(_addSource("/lib.dart", "library lib;"));
1625 _context.analysisPriorityOrder = sources; 1749 _context.analysisPriorityOrder = sources;
1626 } 1750 }
1627 1751
1628 void test_setChangedContents_libraryWithPart() { 1752 Future test_setChangedContents_libraryWithPart() {
1629 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 1753 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
1630 options.incremental = true; 1754 options.incremental = true;
1631 _context = AnalysisContextFactory.contextWithCoreAndOptions(options); 1755 _context = AnalysisContextFactory.contextWithCoreAndOptions(options);
1756 SourcesChangedListener listener = new SourcesChangedListener();
1757 _context.onSourcesChanged.listen(listener.onData);
1632 _sourceFactory = _context.sourceFactory; 1758 _sourceFactory = _context.sourceFactory;
1633 String oldCode = r''' 1759 String oldCode = r'''
1634 library lib; 1760 library lib;
1635 part 'part.dart'; 1761 part 'part.dart';
1636 int a = 0;'''; 1762 int a = 0;''';
1637 Source librarySource = _addSource("/lib.dart", oldCode); 1763 Source librarySource = _addSource("/lib.dart", oldCode);
1638 Source partSource = _addSource("/part.dart", r''' 1764 String partContents = r'''
1639 part of lib; 1765 part of lib;
1640 int b = a;'''); 1766 int b = a;''';
1767 Source partSource = _addSource("/part.dart", partContents);
1641 LibraryElement element = _context.computeLibraryElement(librarySource); 1768 LibraryElement element = _context.computeLibraryElement(librarySource);
1642 CompilationUnit unit = 1769 CompilationUnit unit =
1643 _context.getResolvedCompilationUnit(librarySource, element); 1770 _context.getResolvedCompilationUnit(librarySource, element);
1644 expect(unit, isNotNull); 1771 expect(unit, isNotNull);
1645 int offset = oldCode.indexOf("int a") + 4; 1772 int offset = oldCode.indexOf("int a") + 4;
1646 String newCode = r''' 1773 String newCode = r'''
1647 library lib; 1774 library lib;
1648 part 'part.dart'; 1775 part 'part.dart';
1649 int ya = 0;'''; 1776 int ya = 0;''';
1650 expect(_getIncrementalAnalysisCache(_context), isNull); 1777 expect(_getIncrementalAnalysisCache(_context), isNull);
1651 _context.setChangedContents(librarySource, newCode, offset, 0, 1); 1778 _context.setChangedContents(librarySource, newCode, offset, 0, 1);
1652 expect(_context.getContents(librarySource).data, newCode); 1779 expect(_context.getContents(librarySource).data, newCode);
1653 IncrementalAnalysisCache incrementalCache = 1780 IncrementalAnalysisCache incrementalCache =
1654 _getIncrementalAnalysisCache(_context); 1781 _getIncrementalAnalysisCache(_context);
1655 expect(incrementalCache.librarySource, librarySource); 1782 expect(incrementalCache.librarySource, librarySource);
1656 expect(incrementalCache.resolvedUnit, same(unit)); 1783 expect(incrementalCache.resolvedUnit, same(unit));
1657 expect( 1784 expect(
1658 _context.getResolvedCompilationUnit2(partSource, librarySource), 1785 _context.getResolvedCompilationUnit2(partSource, librarySource),
1659 isNull); 1786 isNull);
1660 expect(incrementalCache.newContents, newCode); 1787 expect(incrementalCache.newContents, newCode);
1788 return pumpEventQueue().then((_) {
1789 listener.assertEvent(wereSourcesAdded: true);
1790 listener.assertEvent(changedSources: [librarySource]);
1791 listener.assertEvent(wereSourcesAdded: true);
1792 listener.assertEvent(changedSources: [partSource]);
1793 listener.assertEvent(changedSources: [librarySource]);
1794 listener.assertNoMoreEvents();
1795 });
1661 } 1796 }
1662 1797
1663 void test_setChangedContents_notResolved() { 1798 void test_setChangedContents_notResolved() {
1664 _context = AnalysisContextFactory.contextWithCore(); 1799 _context = AnalysisContextFactory.contextWithCore();
1665 AnalysisOptionsImpl options = 1800 AnalysisOptionsImpl options =
1666 new AnalysisOptionsImpl.con1(_context.analysisOptions); 1801 new AnalysisOptionsImpl.con1(_context.analysisOptions);
1667 options.incremental = true; 1802 options.incremental = true;
1668 _context.analysisOptions = options; 1803 _context.analysisOptions = options;
1669 _sourceFactory = _context.sourceFactory; 1804 _sourceFactory = _context.sourceFactory;
1670 String oldCode = r''' 1805 String oldCode = r'''
1671 library lib; 1806 library lib;
1672 int a = 0;'''; 1807 int a = 0;''';
1673 Source librarySource = _addSource("/lib.dart", oldCode); 1808 Source librarySource = _addSource("/lib.dart", oldCode);
1674 int offset = oldCode.indexOf("int a") + 4; 1809 int offset = oldCode.indexOf("int a") + 4;
1675 String newCode = r''' 1810 String newCode = r'''
1676 library lib; 1811 library lib;
1677 int ya = 0;'''; 1812 int ya = 0;''';
1678 _context.setChangedContents(librarySource, newCode, offset, 0, 1); 1813 _context.setChangedContents(librarySource, newCode, offset, 0, 1);
1679 expect(_context.getContents(librarySource).data, newCode); 1814 expect(_context.getContents(librarySource).data, newCode);
1680 expect(_getIncrementalAnalysisCache(_context), isNull); 1815 expect(_getIncrementalAnalysisCache(_context), isNull);
1681 } 1816 }
1682 1817
1683 void test_setContents_libraryWithPart() { 1818 Future test_setContents_libraryWithPart() {
1684 _context = AnalysisContextFactory.contextWithCore(); 1819 _context = AnalysisContextFactory.contextWithCore();
1820 SourcesChangedListener listener = new SourcesChangedListener();
1821 _context.onSourcesChanged.listen(listener.onData);
1685 _sourceFactory = _context.sourceFactory; 1822 _sourceFactory = _context.sourceFactory;
1686 Source librarySource = _addSource("/lib.dart", r''' 1823 String libraryContents1 = r'''
1687 library lib; 1824 library lib;
1688 part 'part.dart'; 1825 part 'part.dart';
1689 int a = 0;'''); 1826 int a = 0;''';
1690 Source partSource = _addSource("/part.dart", r''' 1827 Source librarySource = _addSource("/lib.dart", libraryContents1);
1828 String partContents1 = r'''
1691 part of lib; 1829 part of lib;
1692 int b = a;'''); 1830 int b = a;''';
1831 Source partSource = _addSource("/part.dart", partContents1);
1693 _context.computeLibraryElement(librarySource); 1832 _context.computeLibraryElement(librarySource);
1694 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache( 1833 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache(
1695 librarySource, 1834 librarySource,
1696 librarySource, 1835 librarySource,
1697 null, 1836 null,
1698 null, 1837 null,
1699 null, 1838 null,
1700 0, 1839 0,
1701 0, 1840 0,
1702 0); 1841 0);
1703 _setIncrementalAnalysisCache(_context, incrementalCache); 1842 _setIncrementalAnalysisCache(_context, incrementalCache);
1704 expect(_getIncrementalAnalysisCache(_context), same(incrementalCache)); 1843 expect(_getIncrementalAnalysisCache(_context), same(incrementalCache));
1705 _context.setContents(librarySource, r''' 1844 String libraryContents2 = r'''
1706 library lib; 1845 library lib;
1707 part 'part.dart'; 1846 part 'part.dart';
1708 int aa = 0;'''); 1847 int aa = 0;''';
1848 _context.setContents(librarySource, libraryContents2);
1709 expect( 1849 expect(
1710 _context.getResolvedCompilationUnit2(partSource, librarySource), 1850 _context.getResolvedCompilationUnit2(partSource, librarySource),
1711 isNull); 1851 isNull);
1712 expect(_getIncrementalAnalysisCache(_context), isNull); 1852 expect(_getIncrementalAnalysisCache(_context), isNull);
1853 return pumpEventQueue().then((_) {
1854 listener.assertEvent(wereSourcesAdded: true);
1855 listener.assertEvent(changedSources: [librarySource]);
1856 listener.assertEvent(wereSourcesAdded: true);
1857 listener.assertEvent(changedSources: [partSource]);
1858 listener.assertEvent(changedSources: [librarySource]);
1859 listener.assertNoMoreEvents();
1860 });
1713 } 1861 }
1714 1862
1715 void test_setContents_null() { 1863 void test_setContents_null() {
1716 _context = AnalysisContextFactory.contextWithCore(); 1864 _context = AnalysisContextFactory.contextWithCore();
1717 _sourceFactory = _context.sourceFactory; 1865 _sourceFactory = _context.sourceFactory;
1718 Source librarySource = _addSource("/lib.dart", r''' 1866 Source librarySource = _addSource("/lib.dart", r'''
1719 library lib; 1867 library lib;
1720 int a = 0;'''); 1868 int a = 0;''');
1721 _context.computeLibraryElement(librarySource); 1869 _context.computeLibraryElement(librarySource);
1722 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache( 1870 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache(
(...skipping 4280 matching lines...) Expand 10 before | Expand all | Expand 10 after
6003 Source source = factory.forUri("dart:core"); 6151 Source source = factory.forUri("dart:core");
6004 expect(partition.contains(source), isTrue); 6152 expect(partition.contains(source), isTrue);
6005 } 6153 }
6006 6154
6007 void test_creation() { 6155 void test_creation() {
6008 expect(new SdkCachePartition(null, 8), isNotNull); 6156 expect(new SdkCachePartition(null, 8), isNotNull);
6009 } 6157 }
6010 } 6158 }
6011 6159
6012 6160
6161 class SourcesChangedEventTest {
6162
6163 void test_added() {
6164 var source = new StringSource('', '/test.dart');
6165 var changeSet = new ChangeSet();
6166 changeSet.addedSource(source);
6167 var event = new SourcesChangedEvent(changeSet);
6168 assertEvent(event, wereSourcesAdded: true);
6169 }
6170
6171 void test_changedContent() {
6172 var source = new StringSource('', '/test.dart');
6173 var changeSet = new ChangeSet();
6174 changeSet.changedContent(source, 'library A;');
6175 var event = new SourcesChangedEvent(changeSet);
6176 assertEvent(event, changedSources: [source]);
6177 }
6178
6179 void test_changedContent2() {
6180 var source = new StringSource('', '/test.dart');
6181 var event = new SourcesChangedEvent.changedContent(source, 'library A;');
6182 assertEvent(event, changedSources: [source]);
6183 }
6184
6185 void test_changedRange() {
6186 var source = new StringSource('', '/test.dart');
6187 var changeSet = new ChangeSet();
6188 changeSet.changedRange(source, 'library A;', 0, 0, 13);
6189 var event = new SourcesChangedEvent(changeSet);
6190 assertEvent(event, changedSources: [source]);
6191 }
6192
6193 void test_changedRange2() {
6194 var source = new StringSource('', '/test.dart');
6195 var event = new SourcesChangedEvent.changedRange(
6196 source, 'library A;', 0, 0, 13);
6197 assertEvent(event, changedSources: [source]);
6198 }
6199
6200 void test_changedSources() {
6201 var source = new StringSource('', '/test.dart');
6202 var changeSet = new ChangeSet();
6203 changeSet.changedSource(source);
6204 var event = new SourcesChangedEvent(changeSet);
6205 assertEvent(event, changedSources: [source]);
6206 }
6207
6208 void test_deleted() {
6209 var source = new StringSource('', '/test.dart');
6210 var changeSet = new ChangeSet();
6211 changeSet.deletedSource(source);
6212 var event = new SourcesChangedEvent(changeSet);
6213 assertEvent(event, wereSourcesRemovedOrDeleted: true);
6214 }
6215
6216 void test_empty() {
6217 var changeSet = new ChangeSet();
6218 var event = new SourcesChangedEvent(changeSet);
6219 assertEvent(event);
6220 }
6221
6222 void test_removed() {
6223 var source = new StringSource('', '/test.dart');
6224 var changeSet = new ChangeSet();
6225 changeSet.removedSource(source);
6226 var event = new SourcesChangedEvent(changeSet);
6227 assertEvent(event, wereSourcesRemovedOrDeleted: true);
6228 }
6229
6230 static void assertEvent(SourcesChangedEvent event, {bool wereSourcesAdded: fal se,
6231 List<Source> changedSources: Source.EMPTY_ARRAY,
6232 bool wereSourcesRemovedOrDeleted: false}) {
6233 expect(event.wereSourcesAdded, wereSourcesAdded);
6234 expect(event.changedSources, changedSources);
6235 expect(event.wereSourcesRemovedOrDeleted, wereSourcesRemovedOrDeleted);
6236 }
6237 }
6238
6239
6240 class SourcesChangedListener {
6241 List<SourcesChangedEvent> actualEvents = [];
6242
6243 void assertEvent({bool wereSourcesAdded: false,
6244 List<Source> changedSources: Source.EMPTY_ARRAY,
6245 bool wereSourcesRemovedOrDeleted: false}) {
6246 if (actualEvents.isEmpty) {
6247 fail('Expected event but found none');
6248 }
6249 SourcesChangedEvent actual = actualEvents.removeAt(0);
6250 SourcesChangedEventTest.assertEvent(
6251 actual,
6252 wereSourcesAdded: wereSourcesAdded,
6253 changedSources: changedSources,
6254 wereSourcesRemovedOrDeleted: wereSourcesRemovedOrDeleted);
6255 }
6256
6257 void assertNoMoreEvents() {
6258 expect(actualEvents, []);
6259 }
6260
6261 void onData(SourcesChangedEvent event) {
6262 actualEvents.add(event);
6263 }
6264 }
6265
6266
6013 /** 6267 /**
6014 * Instances of the class `TestAnalysisContext` implement an analysis context in which every 6268 * Instances of the class `TestAnalysisContext` implement an analysis context in which every
6015 * method will cause a test to fail when invoked. 6269 * method will cause a test to fail when invoked.
6016 */ 6270 */
6017 class TestAnalysisContext implements InternalAnalysisContext { 6271 class TestAnalysisContext implements InternalAnalysisContext {
6018 @override 6272 @override
6019 AnalysisOptions get analysisOptions { 6273 AnalysisOptions get analysisOptions {
6020 fail("Unexpected invocation of getAnalysisOptions"); 6274 fail("Unexpected invocation of getAnalysisOptions");
6021 return null; 6275 return null;
6022 } 6276 }
(...skipping 29 matching lines...) Expand all
6052 List<Source> get launchableServerLibrarySources { 6306 List<Source> get launchableServerLibrarySources {
6053 fail("Unexpected invocation of getLaunchableServerLibrarySources"); 6307 fail("Unexpected invocation of getLaunchableServerLibrarySources");
6054 return null; 6308 return null;
6055 } 6309 }
6056 @override 6310 @override
6057 List<Source> get librarySources { 6311 List<Source> get librarySources {
6058 fail("Unexpected invocation of getLibrarySources"); 6312 fail("Unexpected invocation of getLibrarySources");
6059 return null; 6313 return null;
6060 } 6314 }
6061 @override 6315 @override
6316 Stream<SourcesChangedEvent> get onSourcesChanged {
6317 fail("Unexpected invocation of onSourcesChanged");
6318 return null;
6319 }
6320 @override
6062 List<Source> get prioritySources { 6321 List<Source> get prioritySources {
6063 fail("Unexpected invocation of getPrioritySources"); 6322 fail("Unexpected invocation of getPrioritySources");
6064 return null; 6323 return null;
6065 } 6324 }
6066 @override 6325 @override
6067 List<Source> get refactoringUnsafeSources { 6326 List<Source> get refactoringUnsafeSources {
6068 fail("Unexpected invocation of getRefactoringUnsafeSources"); 6327 fail("Unexpected invocation of getRefactoringUnsafeSources");
6069 return null; 6328 return null;
6070 } 6329 }
6071 @override 6330 @override
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
7215 bool contains(Source source) => source == libB; 7474 bool contains(Source source) => source == libB;
7216 } 7475 }
7217 7476
7218 7477
7219 class _UniversalCachePartitionTest_test_setMaxCacheSize implements 7478 class _UniversalCachePartitionTest_test_setMaxCacheSize implements
7220 CacheRetentionPolicy { 7479 CacheRetentionPolicy {
7221 @override 7480 @override
7222 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => 7481 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) =>
7223 RetentionPriority.LOW; 7482 RetentionPriority.LOW;
7224 } 7483 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698