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

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: 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
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';
30 import 'package:analyzer/src/task/task_dart.dart'; 31 import 'package:analyzer/src/task/task_dart.dart';
31 import 'package:typed_mock/typed_mock.dart'; 32 import 'package:typed_mock/typed_mock.dart';
32 import 'package:unittest/unittest.dart'; 33 import 'package:unittest/unittest.dart';
34 import 'package:watcher/src/utils.dart';
33 35
34 import '../reflective_tests.dart'; 36 import '../reflective_tests.dart';
35 import 'all_the_rest.dart'; 37 import 'all_the_rest.dart';
36 import 'resolver_test.dart'; 38 import 'resolver_test.dart';
37 import 'test_support.dart'; 39 import 'test_support.dart';
38 40
39 41
40 main() { 42 main() {
41 groupSep = ' | '; 43 groupSep = ' | ';
42 runReflectiveTests(AnalysisCacheTest); 44 runReflectiveTests(AnalysisCacheTest);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 _context.analysisOptions = options; 219 _context.analysisOptions = options;
218 } 220 }
219 221
220 @override 222 @override
221 void tearDown() { 223 void tearDown() {
222 _context = null; 224 _context = null;
223 _sourceFactory = null; 225 _sourceFactory = null;
224 super.tearDown(); 226 super.tearDown();
225 } 227 }
226 228
227 void test_applyChanges_add() { 229 Future test_applyChanges_add() {
230 SourcesChangedListener listener = new SourcesChangedListener();
231 _context.onSourcesChanged.listen(listener.onData);
228 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); 232 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue);
229 Source source = _addSource("/test.dart", "main() {}"); 233 Source source =
234 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
235 ChangeSet changeSet = new ChangeSet();
236 changeSet.addedSource(source);
237 _context.applyChanges(changeSet);
230 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); 238 expect(_context.sourcesNeedingProcessing.contains(source), isTrue);
239 return pumpEventQueue().then((_) {
240 listener.assertChangeSet(changeSet);
241 listener.assertNoMoreEvents();
242 });
243 }
244
245 Future test_applyChanges_change() {
246 SourcesChangedListener listener = new SourcesChangedListener();
247 _context.onSourcesChanged.listen(listener.onData);
248 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue);
249 Source source =
250 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
251 ChangeSet changeSet1 = new ChangeSet();
252 changeSet1.addedSource(source);
253 _context.applyChanges(changeSet1);
254 expect(_context.sourcesNeedingProcessing.contains(source), isTrue);
255 Source source2 =
256 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart"));
257 ChangeSet changeSet2 = new ChangeSet();
258 changeSet2.addedSource(source2);
259 changeSet2.changedSource(source);
260 _context.applyChanges(changeSet2);
261 return pumpEventQueue().then((_) {
262 listener.assertChangeSet(changeSet1);
263 listener.assertChangeSet(changeSet2);
264 listener.assertNoMoreEvents();
265 });
266 }
267
268 Future test_applyChanges_change_content() {
269 SourcesChangedListener listener = new SourcesChangedListener();
270 _context.onSourcesChanged.listen(listener.onData);
271 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue);
272 Source source =
273 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
274 ChangeSet changeSet1 = new ChangeSet();
275 changeSet1.addedSource(source);
276 _context.applyChanges(changeSet1);
277 expect(_context.sourcesNeedingProcessing.contains(source), isTrue);
278 Source source2 =
279 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart"));
280 ChangeSet changeSet2 = new ChangeSet();
281 changeSet2.addedSource(source2);
282 changeSet2.changedContent(source, 'library test;');
283 _context.applyChanges(changeSet2);
284 return pumpEventQueue().then((_) {
285 listener.assertChangeSet(changeSet1);
286 listener.assertChangeSet(changeSet2);
287 listener.assertNoMoreEvents();
288 });
231 } 289 }
232 290
233 void test_applyChanges_change_flush_element() { 291 void test_applyChanges_change_flush_element() {
234 _context = AnalysisContextFactory.contextWithCore(); 292 _context = AnalysisContextFactory.contextWithCore();
235 _sourceFactory = _context.sourceFactory; 293 _sourceFactory = _context.sourceFactory;
236 Source librarySource = _addSource("/lib.dart", r''' 294 Source librarySource = _addSource("/lib.dart", r'''
237 library lib; 295 library lib;
238 int a = 0;'''); 296 int a = 0;''');
239 expect(_context.computeLibraryElement(librarySource), isNotNull); 297 expect(_context.computeLibraryElement(librarySource), isNotNull);
240 _context.setContents(librarySource, r''' 298 _context.setContents(librarySource, r'''
241 library lib; 299 library lib;
242 int aa = 0;'''); 300 int aa = 0;''');
243 expect(_context.getLibraryElement(librarySource), isNull); 301 expect(_context.getLibraryElement(librarySource), isNull);
244 } 302 }
245 303
246 void test_applyChanges_change_multiple() { 304 Future test_applyChanges_change_multiple() {
247 _context = AnalysisContextFactory.contextWithCore(); 305 _context = AnalysisContextFactory.contextWithCore();
306 SourcesChangedListener listener = new SourcesChangedListener();
307 _context.onSourcesChanged.listen(listener.onData);
248 _sourceFactory = _context.sourceFactory; 308 _sourceFactory = _context.sourceFactory;
249 Source librarySource = _addSource("/lib.dart", r''' 309 String libraryContents1 = r'''
250 library lib; 310 library lib;
251 part 'part.dart'; 311 part 'part.dart';
252 int a = 0;'''); 312 int a = 0;''';
253 Source partSource = _addSource("/part.dart", r''' 313 Source librarySource = _addSource("/lib.dart", libraryContents1);
314 String partContents1 = r'''
254 part of lib; 315 part of lib;
255 int b = a;'''); 316 int b = a;''';
317 Source partSource = _addSource("/part.dart", partContents1);
256 _context.computeLibraryElement(librarySource); 318 _context.computeLibraryElement(librarySource);
257 _context.setContents(librarySource, r''' 319 String libraryContents2 = r'''
258 library lib; 320 library lib;
259 part 'part.dart'; 321 part 'part.dart';
260 int aa = 0;'''); 322 int aa = 0;''';
261 _context.setContents(partSource, r''' 323 _context.setContents(librarySource, libraryContents2);
324 String partContents2 = r'''
262 part of lib; 325 part of lib;
263 int b = aa;'''); 326 int b = aa;''';
327 _context.setContents(partSource, partContents2);
264 _context.computeLibraryElement(librarySource); 328 _context.computeLibraryElement(librarySource);
265 CompilationUnit libraryUnit = 329 CompilationUnit libraryUnit =
266 _context.resolveCompilationUnit2(librarySource, librarySource); 330 _context.resolveCompilationUnit2(librarySource, librarySource);
267 CompilationUnit partUnit = 331 CompilationUnit partUnit =
268 _context.resolveCompilationUnit2(partSource, librarySource); 332 _context.resolveCompilationUnit2(partSource, librarySource);
269 TopLevelVariableDeclaration declaration = 333 TopLevelVariableDeclaration declaration =
270 libraryUnit.declarations[0] as TopLevelVariableDeclaration; 334 libraryUnit.declarations[0] as TopLevelVariableDeclaration;
271 Element declarationElement = declaration.variables.variables[0].element; 335 Element declarationElement = declaration.variables.variables[0].element;
272 TopLevelVariableDeclaration use = 336 TopLevelVariableDeclaration use =
273 partUnit.declarations[0] as TopLevelVariableDeclaration; 337 partUnit.declarations[0] as TopLevelVariableDeclaration;
274 Element useElement = 338 Element useElement =
275 (use.variables.variables[0].initializer as SimpleIdentifier).staticEleme nt; 339 (use.variables.variables[0].initializer as SimpleIdentifier).staticEleme nt;
276 expect( 340 expect(
277 (useElement as PropertyAccessorElement).variable, 341 (useElement as PropertyAccessorElement).variable,
278 same(declarationElement)); 342 same(declarationElement));
343 return pumpEventQueue().then((_) {
344 listener.assertChanges(added: [librarySource]);
345 listener.assertChanges(changedContents: {
346 librarySource: libraryContents1
347 });
348 listener.assertChanges(added: [partSource]);
349 listener.assertChanges(changedContents: {
350 partSource: partContents1
351 });
352 listener.assertChanges(changedContents: {
353 librarySource: libraryContents2
354 });
355 listener.assertChanges(changedContents: {
356 partSource: partContents2
357 });
358 listener.assertNoMoreEvents();
359 });
360 }
361
362 Future test_applyChanges_change_range() {
363 SourcesChangedListener listener = new SourcesChangedListener();
364 _context.onSourcesChanged.listen(listener.onData);
365 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue);
366 Source source =
367 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
368 ChangeSet changeSet1 = new ChangeSet();
369 changeSet1.addedSource(source);
370 _context.applyChanges(changeSet1);
371 expect(_context.sourcesNeedingProcessing.contains(source), isTrue);
372 Source source2 =
373 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart"));
374 ChangeSet changeSet2 = new ChangeSet();
375 changeSet2.addedSource(source2);
376 changeSet2.changedRange(source, 'library test;', 0, 0, 13);
377 _context.applyChanges(changeSet2);
378 return pumpEventQueue().then((_) {
379 listener.assertChangeSet(changeSet1);
380 listener.assertChangeSet(changeSet2);
381 listener.assertNoMoreEvents();
382 });
279 } 383 }
280 384
281 void test_applyChanges_empty() { 385 void test_applyChanges_empty() {
282 _context.applyChanges(new ChangeSet()); 386 _context.applyChanges(new ChangeSet());
283 expect(_context.performAnalysisTask().changeNotices, isNull); 387 expect(_context.performAnalysisTask().changeNotices, isNull);
284 } 388 }
285 389
286 void test_applyChanges_overriddenSource() { 390 void test_applyChanges_overriddenSource() {
287 // Note: addSource adds the source to the contentCache. 391 // Note: addSource adds the source to the contentCache.
288 Source source = _addSource("/test.dart", "library test;"); 392 Source source = _addSource("/test.dart", "library test;");
289 _context.computeErrors(source); 393 _context.computeErrors(source);
290 while (!_context.sourcesNeedingProcessing.isEmpty) { 394 while (!_context.sourcesNeedingProcessing.isEmpty) {
291 _context.performAnalysisTask(); 395 _context.performAnalysisTask();
292 } 396 }
293 // Adding the source as a changedSource should have no effect since 397 // Adding the source as a changedSource should have no effect since
294 // it is already overridden in the content cache. 398 // it is already overridden in the content cache.
295 ChangeSet changeSet = new ChangeSet(); 399 ChangeSet changeSet = new ChangeSet();
296 changeSet.changedSource(source); 400 changeSet.changedSource(source);
297 _context.applyChanges(changeSet); 401 _context.applyChanges(changeSet);
298 expect(_context.sourcesNeedingProcessing, hasLength(0)); 402 expect(_context.sourcesNeedingProcessing, hasLength(0));
299 } 403 }
300 404
301 void test_applyChanges_remove() { 405 Future test_applyChanges_remove() {
302 _context = AnalysisContextFactory.contextWithCore(); 406 _context = AnalysisContextFactory.contextWithCore();
407 SourcesChangedListener listener = new SourcesChangedListener();
408 _context.onSourcesChanged.listen(listener.onData);
303 _sourceFactory = _context.sourceFactory; 409 _sourceFactory = _context.sourceFactory;
304 Source libA = _addSource("/libA.dart", r''' 410 String libAContents = r'''
305 library libA; 411 library libA;
306 import 'libB.dart';'''); 412 import 'libB.dart';''';
307 Source libB = _addSource("/libB.dart", "library libB;"); 413 Source libA = _addSource("/libA.dart", libAContents);
414 String libBContents = "library libB;";
415 Source libB = _addSource("/libB.dart", libBContents);
308 LibraryElement libAElement = _context.computeLibraryElement(libA); 416 LibraryElement libAElement = _context.computeLibraryElement(libA);
309 List<LibraryElement> importedLibraries = libAElement.importedLibraries; 417 List<LibraryElement> importedLibraries = libAElement.importedLibraries;
310 expect(importedLibraries, hasLength(2)); 418 expect(importedLibraries, hasLength(2));
311 _context.computeErrors(libA); 419 _context.computeErrors(libA);
312 _context.computeErrors(libB); 420 _context.computeErrors(libB);
313 expect(_context.sourcesNeedingProcessing, hasLength(0)); 421 expect(_context.sourcesNeedingProcessing, hasLength(0));
314 _context.setContents(libB, null); 422 _context.setContents(libB, null);
315 _removeSource(libB); 423 _removeSource(libB);
316 List<Source> sources = _context.sourcesNeedingProcessing; 424 List<Source> sources = _context.sourcesNeedingProcessing;
317 expect(sources, hasLength(1)); 425 expect(sources, hasLength(1));
318 expect(sources[0], same(libA)); 426 expect(sources[0], same(libA));
319 libAElement = _context.computeLibraryElement(libA); 427 libAElement = _context.computeLibraryElement(libA);
320 importedLibraries = libAElement.importedLibraries; 428 importedLibraries = libAElement.importedLibraries;
321 expect(importedLibraries, hasLength(1)); 429 expect(importedLibraries, hasLength(1));
430 return pumpEventQueue().then((_) {
431 listener.assertChanges(added: [libA]);
432 listener.assertChanges(changedContents: {
433 libA: libAContents
434 });
435 listener.assertChanges(added: [libB]);
436 listener.assertChanges(changedContents: {
437 libB: libBContents
438 });
439 listener.assertChanges(changedContents: {
440 libB: null
441 });
442 listener.assertChanges(removedSources: [libB]);
443 listener.assertNoMoreEvents();
444 });
322 } 445 }
323 446
324 void test_applyChanges_removeContainer() { 447 Future test_applyChanges_removeContainer() {
325 _context = AnalysisContextFactory.contextWithCore(); 448 _context = AnalysisContextFactory.contextWithCore();
449 SourcesChangedListener listener = new SourcesChangedListener();
450 _context.onSourcesChanged.listen(listener.onData);
326 _sourceFactory = _context.sourceFactory; 451 _sourceFactory = _context.sourceFactory;
327 Source libA = _addSource("/libA.dart", r''' 452 String libAContents = r'''
328 library libA; 453 library libA;
329 import 'libB.dart';'''); 454 import 'libB.dart';''';
330 Source libB = _addSource("/libB.dart", "library libB;"); 455 Source libA = _addSource("/libA.dart", libAContents);
456 String libBContents = "library libB;";
457 Source libB = _addSource("/libB.dart", libBContents);
331 _context.computeLibraryElement(libA); 458 _context.computeLibraryElement(libA);
332 _context.computeErrors(libA); 459 _context.computeErrors(libA);
333 _context.computeErrors(libB); 460 _context.computeErrors(libB);
334 expect(_context.sourcesNeedingProcessing, hasLength(0)); 461 expect(_context.sourcesNeedingProcessing, hasLength(0));
335 ChangeSet changeSet = new ChangeSet(); 462 ChangeSet changeSet = new ChangeSet();
336 changeSet.removedContainer( 463 SourceContainer removedContainer =
337 new _AnalysisContextImplTest_test_applyChanges_removeContainer(libB)); 464 new _AnalysisContextImplTest_test_applyChanges_removeContainer(libB);
465 changeSet.removedContainer(removedContainer);
338 _context.applyChanges(changeSet); 466 _context.applyChanges(changeSet);
339 List<Source> sources = _context.sourcesNeedingProcessing; 467 List<Source> sources = _context.sourcesNeedingProcessing;
340 expect(sources, hasLength(1)); 468 expect(sources, hasLength(1));
341 expect(sources[0], same(libA)); 469 expect(sources[0], same(libA));
470 return pumpEventQueue().then((_) {
471 listener.assertChanges(added: [libA]);
472 listener.assertChanges(changedContents: {
473 libA: libAContents
474 });
475 listener.assertChanges(added: [libB]);
476 listener.assertChanges(changedContents: {
477 libB: libBContents
478 });
479 listener.assertChanges(removedContainers: [removedContainer]);
480 listener.assertNoMoreEvents();
481 });
342 } 482 }
343 483
344 void test_computeDocumentationComment_block() { 484 void test_computeDocumentationComment_block() {
345 _context = AnalysisContextFactory.contextWithCore(); 485 _context = AnalysisContextFactory.contextWithCore();
346 _sourceFactory = _context.sourceFactory; 486 _sourceFactory = _context.sourceFactory;
347 String comment = "/** Comment */"; 487 String comment = "/** Comment */";
348 Source source = _addSource("/test.dart", """ 488 Source source = _addSource("/test.dart", """
349 $comment 489 $comment
350 class A {}"""); 490 class A {}""");
351 LibraryElement libraryElement = _context.computeLibraryElement(source); 491 LibraryElement libraryElement = _context.computeLibraryElement(source);
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 _context.analysisPriorityOrder = sources; 1758 _context.analysisPriorityOrder = sources;
1619 expect(options.cacheSize > _getPriorityOrder(_context).length, isTrue); 1759 expect(options.cacheSize > _getPriorityOrder(_context).length, isTrue);
1620 } 1760 }
1621 1761
1622 void test_setAnalysisPriorityOrder_nonEmpty() { 1762 void test_setAnalysisPriorityOrder_nonEmpty() {
1623 List<Source> sources = new List<Source>(); 1763 List<Source> sources = new List<Source>();
1624 sources.add(_addSource("/lib.dart", "library lib;")); 1764 sources.add(_addSource("/lib.dart", "library lib;"));
1625 _context.analysisPriorityOrder = sources; 1765 _context.analysisPriorityOrder = sources;
1626 } 1766 }
1627 1767
1628 void test_setChangedContents_libraryWithPart() { 1768 Future test_setChangedContents_libraryWithPart() {
1629 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 1769 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
1630 options.incremental = true; 1770 options.incremental = true;
1631 _context = AnalysisContextFactory.contextWithCoreAndOptions(options); 1771 _context = AnalysisContextFactory.contextWithCoreAndOptions(options);
1772 SourcesChangedListener listener = new SourcesChangedListener();
1773 _context.onSourcesChanged.listen(listener.onData);
1632 _sourceFactory = _context.sourceFactory; 1774 _sourceFactory = _context.sourceFactory;
1633 String oldCode = r''' 1775 String oldCode = r'''
1634 library lib; 1776 library lib;
1635 part 'part.dart'; 1777 part 'part.dart';
1636 int a = 0;'''; 1778 int a = 0;''';
1637 Source librarySource = _addSource("/lib.dart", oldCode); 1779 Source librarySource = _addSource("/lib.dart", oldCode);
1638 Source partSource = _addSource("/part.dart", r''' 1780 String partContents = r'''
1639 part of lib; 1781 part of lib;
1640 int b = a;'''); 1782 int b = a;''';
1783 Source partSource = _addSource("/part.dart", partContents);
1641 LibraryElement element = _context.computeLibraryElement(librarySource); 1784 LibraryElement element = _context.computeLibraryElement(librarySource);
1642 CompilationUnit unit = 1785 CompilationUnit unit =
1643 _context.getResolvedCompilationUnit(librarySource, element); 1786 _context.getResolvedCompilationUnit(librarySource, element);
1644 expect(unit, isNotNull); 1787 expect(unit, isNotNull);
1645 int offset = oldCode.indexOf("int a") + 4; 1788 int offset = oldCode.indexOf("int a") + 4;
1646 String newCode = r''' 1789 String newCode = r'''
1647 library lib; 1790 library lib;
1648 part 'part.dart'; 1791 part 'part.dart';
1649 int ya = 0;'''; 1792 int ya = 0;''';
1650 expect(_getIncrementalAnalysisCache(_context), isNull); 1793 expect(_getIncrementalAnalysisCache(_context), isNull);
1651 _context.setChangedContents(librarySource, newCode, offset, 0, 1); 1794 _context.setChangedContents(librarySource, newCode, offset, 0, 1);
1652 expect(_context.getContents(librarySource).data, newCode); 1795 expect(_context.getContents(librarySource).data, newCode);
1653 IncrementalAnalysisCache incrementalCache = 1796 IncrementalAnalysisCache incrementalCache =
1654 _getIncrementalAnalysisCache(_context); 1797 _getIncrementalAnalysisCache(_context);
1655 expect(incrementalCache.librarySource, librarySource); 1798 expect(incrementalCache.librarySource, librarySource);
1656 expect(incrementalCache.resolvedUnit, same(unit)); 1799 expect(incrementalCache.resolvedUnit, same(unit));
1657 expect( 1800 expect(
1658 _context.getResolvedCompilationUnit2(partSource, librarySource), 1801 _context.getResolvedCompilationUnit2(partSource, librarySource),
1659 isNull); 1802 isNull);
1660 expect(incrementalCache.newContents, newCode); 1803 expect(incrementalCache.newContents, newCode);
1804 return pumpEventQueue().then((_) {
1805 listener.assertChanges(added: [librarySource]);
1806 listener.assertChanges(changedContents: {
1807 librarySource: oldCode
1808 });
1809 listener.assertChanges(added: [partSource]);
1810 listener.assertChanges(changedContents: {
1811 partSource: partContents
1812 });
1813 listener.assertChanges(changedRanges: {
1814 librarySource: new ChangeSet_ContentChange(newCode, offset, 0, 1)
1815 });
1816 listener.assertNoMoreEvents();
1817 });
1661 } 1818 }
1662 1819
1663 void test_setChangedContents_notResolved() { 1820 void test_setChangedContents_notResolved() {
1664 _context = AnalysisContextFactory.contextWithCore(); 1821 _context = AnalysisContextFactory.contextWithCore();
1665 AnalysisOptionsImpl options = 1822 AnalysisOptionsImpl options =
1666 new AnalysisOptionsImpl.con1(_context.analysisOptions); 1823 new AnalysisOptionsImpl.con1(_context.analysisOptions);
1667 options.incremental = true; 1824 options.incremental = true;
1668 _context.analysisOptions = options; 1825 _context.analysisOptions = options;
1669 _sourceFactory = _context.sourceFactory; 1826 _sourceFactory = _context.sourceFactory;
1670 String oldCode = r''' 1827 String oldCode = r'''
1671 library lib; 1828 library lib;
1672 int a = 0;'''; 1829 int a = 0;''';
1673 Source librarySource = _addSource("/lib.dart", oldCode); 1830 Source librarySource = _addSource("/lib.dart", oldCode);
1674 int offset = oldCode.indexOf("int a") + 4; 1831 int offset = oldCode.indexOf("int a") + 4;
1675 String newCode = r''' 1832 String newCode = r'''
1676 library lib; 1833 library lib;
1677 int ya = 0;'''; 1834 int ya = 0;''';
1678 _context.setChangedContents(librarySource, newCode, offset, 0, 1); 1835 _context.setChangedContents(librarySource, newCode, offset, 0, 1);
1679 expect(_context.getContents(librarySource).data, newCode); 1836 expect(_context.getContents(librarySource).data, newCode);
1680 expect(_getIncrementalAnalysisCache(_context), isNull); 1837 expect(_getIncrementalAnalysisCache(_context), isNull);
1681 } 1838 }
1682 1839
1683 void test_setContents_libraryWithPart() { 1840 Future test_setContents_libraryWithPart() {
1684 _context = AnalysisContextFactory.contextWithCore(); 1841 _context = AnalysisContextFactory.contextWithCore();
1842 SourcesChangedListener listener = new SourcesChangedListener();
1843 _context.onSourcesChanged.listen(listener.onData);
1685 _sourceFactory = _context.sourceFactory; 1844 _sourceFactory = _context.sourceFactory;
1686 Source librarySource = _addSource("/lib.dart", r''' 1845 String libraryContents1 = r'''
1687 library lib; 1846 library lib;
1688 part 'part.dart'; 1847 part 'part.dart';
1689 int a = 0;'''); 1848 int a = 0;''';
1690 Source partSource = _addSource("/part.dart", r''' 1849 Source librarySource = _addSource("/lib.dart", libraryContents1);
1850 String partContents1 = r'''
1691 part of lib; 1851 part of lib;
1692 int b = a;'''); 1852 int b = a;''';
1853 Source partSource = _addSource("/part.dart", partContents1);
1693 _context.computeLibraryElement(librarySource); 1854 _context.computeLibraryElement(librarySource);
1694 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache( 1855 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache(
1695 librarySource, 1856 librarySource,
1696 librarySource, 1857 librarySource,
1697 null, 1858 null,
1698 null, 1859 null,
1699 null, 1860 null,
1700 0, 1861 0,
1701 0, 1862 0,
1702 0); 1863 0);
1703 _setIncrementalAnalysisCache(_context, incrementalCache); 1864 _setIncrementalAnalysisCache(_context, incrementalCache);
1704 expect(_getIncrementalAnalysisCache(_context), same(incrementalCache)); 1865 expect(_getIncrementalAnalysisCache(_context), same(incrementalCache));
1705 _context.setContents(librarySource, r''' 1866 String libraryContents2 = r'''
1706 library lib; 1867 library lib;
1707 part 'part.dart'; 1868 part 'part.dart';
1708 int aa = 0;'''); 1869 int aa = 0;''';
1870 _context.setContents(librarySource, libraryContents2);
1709 expect( 1871 expect(
1710 _context.getResolvedCompilationUnit2(partSource, librarySource), 1872 _context.getResolvedCompilationUnit2(partSource, librarySource),
1711 isNull); 1873 isNull);
1712 expect(_getIncrementalAnalysisCache(_context), isNull); 1874 expect(_getIncrementalAnalysisCache(_context), isNull);
1875 return pumpEventQueue().then((_) {
1876 listener.assertChanges(added: [librarySource]);
1877 listener.assertChanges(changedContents: {
1878 librarySource: libraryContents1
1879 });
1880 listener.assertChanges(added: [partSource]);
1881 listener.assertChanges(changedContents: {
1882 partSource: partContents1
1883 });
1884 listener.assertChanges(changedContents: {
1885 librarySource: libraryContents2
1886 });
1887 listener.assertNoMoreEvents();
1888 });
1713 } 1889 }
1714 1890
1715 void test_setContents_null() { 1891 void test_setContents_null() {
1716 _context = AnalysisContextFactory.contextWithCore(); 1892 _context = AnalysisContextFactory.contextWithCore();
1717 _sourceFactory = _context.sourceFactory; 1893 _sourceFactory = _context.sourceFactory;
1718 Source librarySource = _addSource("/lib.dart", r''' 1894 Source librarySource = _addSource("/lib.dart", r'''
1719 library lib; 1895 library lib;
1720 int a = 0;'''); 1896 int a = 0;''');
1721 _context.computeLibraryElement(librarySource); 1897 _context.computeLibraryElement(librarySource);
1722 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache( 1898 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache(
(...skipping 4280 matching lines...) Expand 10 before | Expand all | Expand 10 after
6003 Source source = factory.forUri("dart:core"); 6179 Source source = factory.forUri("dart:core");
6004 expect(partition.contains(source), isTrue); 6180 expect(partition.contains(source), isTrue);
6005 } 6181 }
6006 6182
6007 void test_creation() { 6183 void test_creation() {
6008 expect(new SdkCachePartition(null, 8), isNotNull); 6184 expect(new SdkCachePartition(null, 8), isNotNull);
6009 } 6185 }
6010 } 6186 }
6011 6187
6012 6188
6189 class SourcesChangedListener {
6190 static const Map<Source, String> EMPTY_CONTENTS_MAP = const {};
6191 static const Map<Source, ChangeSet_ContentChange> EMPTY_RANGE_MAP = const {};
6192 static const List<SourceContainer> EMPTY_CONTAINER_LIST = const [];
6193
6194 List<ChangeSet> actualChangeSets = [];
6195
6196 void assertChanges({List<Source> added: Source.EMPTY_ARRAY,
6197 List<Source> changedSources: Source.EMPTY_ARRAY, Map<Source,
6198 String> changedContents: EMPTY_CONTENTS_MAP, Map<Source,
6199 ChangeSet_ContentChange> changedRanges: EMPTY_RANGE_MAP,
6200 List<Source> removedSources: Source.EMPTY_ARRAY,
6201 List<SourceContainer> removedContainers: EMPTY_CONTAINER_LIST}) {
6202 if (actualChangeSets.isEmpty) {
6203 fail('Expected event but found none');
6204 }
6205 ChangeSet actual = actualChangeSets.removeAt(0);
6206 expect(actual.addedSources, added, reason: 'addedSources do not match');
6207 expect(
6208 actual.changedSources,
6209 changedSources,
6210 reason: 'changedSources do not match');
6211 expect(
6212 actual.changedContents,
6213 changedContents,
6214 reason: 'changedContents do no match');
6215
6216 HashMap<Source, ChangeSet_ContentChange> actualChangedRanges =
6217 actual.changedRanges;
6218 Map<Source, ChangeSet_ContentChange> expectedChangedRanges = changedRanges;
6219 _expectEqualChangedRanges(actualChangedRanges, expectedChangedRanges);
6220
6221 expect(actual.deletedSources, []);
6222 expect(actual.removedContainers, removedContainers);
6223 expect(
6224 actual.removedSources,
6225 removedSources,
6226 reason: 'removedSources do not match');
6227 }
6228
6229 void assertChangeSet(ChangeSet expected) {
6230 if (actualChangeSets.isEmpty) {
6231 fail('Expected event but found none');
6232 }
6233 ChangeSet actual = actualChangeSets.removeAt(0);
6234 expect(actual, expected);
6235 }
6236
6237 void assertNoMoreEvents() {
6238 expect(actualChangeSets, []);
6239 }
6240
6241 void onData(ChangeSet event) {
6242 actualChangeSets.add(event);
6243 }
6244
6245 void _expectEqualChangedRanges(Map<Source, ChangeSet_ContentChange> actual,
6246 Map<Source, ChangeSet_ContentChange> expected) {
6247 expect(actual, hasLength(expected.length));
6248 expected.forEach((Source source, ChangeSet_ContentChange expectedChange) {
6249 ChangeSet_ContentChange actualChange = actual[source];
6250 expect(actualChange.contents, expectedChange.contents);
6251 expect(actualChange.offset, expectedChange.offset);
6252 expect(actualChange.oldLength, expectedChange.oldLength);
6253 expect(actualChange.newLength, expectedChange.newLength);
6254 });
6255 }
6256 }
6257
6258
6013 /** 6259 /**
6014 * Instances of the class `TestAnalysisContext` implement an analysis context in which every 6260 * Instances of the class `TestAnalysisContext` implement an analysis context in which every
6015 * method will cause a test to fail when invoked. 6261 * method will cause a test to fail when invoked.
6016 */ 6262 */
6017 class TestAnalysisContext implements InternalAnalysisContext { 6263 class TestAnalysisContext implements InternalAnalysisContext {
6018 @override 6264 @override
6019 AnalysisOptions get analysisOptions { 6265 AnalysisOptions get analysisOptions {
6020 fail("Unexpected invocation of getAnalysisOptions"); 6266 fail("Unexpected invocation of getAnalysisOptions");
6021 return null; 6267 return null;
6022 } 6268 }
(...skipping 29 matching lines...) Expand all
6052 List<Source> get launchableServerLibrarySources { 6298 List<Source> get launchableServerLibrarySources {
6053 fail("Unexpected invocation of getLaunchableServerLibrarySources"); 6299 fail("Unexpected invocation of getLaunchableServerLibrarySources");
6054 return null; 6300 return null;
6055 } 6301 }
6056 @override 6302 @override
6057 List<Source> get librarySources { 6303 List<Source> get librarySources {
6058 fail("Unexpected invocation of getLibrarySources"); 6304 fail("Unexpected invocation of getLibrarySources");
6059 return null; 6305 return null;
6060 } 6306 }
6061 @override 6307 @override
6308 Stream<ChangeSet> get onSourcesChanged {
6309 fail("Unexpected invocation of onSourcesChanged");
6310 return null;
6311 }
6312 @override
6062 List<Source> get prioritySources { 6313 List<Source> get prioritySources {
6063 fail("Unexpected invocation of getPrioritySources"); 6314 fail("Unexpected invocation of getPrioritySources");
6064 return null; 6315 return null;
6065 } 6316 }
6066 @override 6317 @override
6067 List<Source> get refactoringUnsafeSources { 6318 List<Source> get refactoringUnsafeSources {
6068 fail("Unexpected invocation of getRefactoringUnsafeSources"); 6319 fail("Unexpected invocation of getRefactoringUnsafeSources");
6069 return null; 6320 return null;
6070 } 6321 }
6071 @override 6322 @override
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
7215 bool contains(Source source) => source == libB; 7466 bool contains(Source source) => source == libB;
7216 } 7467 }
7217 7468
7218 7469
7219 class _UniversalCachePartitionTest_test_setMaxCacheSize implements 7470 class _UniversalCachePartitionTest_test_setMaxCacheSize implements
7220 CacheRetentionPolicy { 7471 CacheRetentionPolicy {
7221 @override 7472 @override
7222 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => 7473 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) =>
7223 RetentionPriority.LOW; 7474 RetentionPriority.LOW;
7224 } 7475 }
OLDNEW
« pkg/analyzer/lib/src/generated/engine.dart ('K') | « 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