OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library engine.engine_test; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:collection'; |
| 9 |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 11 import 'package:analyzer/src/cancelable_future.dart'; |
| 12 import 'package:analyzer/src/context/cache.dart' show CacheEntry; |
| 13 import 'package:analyzer/src/generated/ast.dart'; |
| 14 import 'package:analyzer/src/generated/constant.dart'; |
| 15 import 'package:analyzer/src/generated/element.dart'; |
| 16 import 'package:analyzer/src/generated/engine.dart'; |
| 17 import 'package:analyzer/src/generated/error.dart'; |
| 18 import 'package:analyzer/src/generated/html.dart' as ht; |
| 19 import 'package:analyzer/src/generated/java_core.dart'; |
| 20 import 'package:analyzer/src/generated/java_engine.dart'; |
| 21 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 22 import 'package:analyzer/src/generated/java_io.dart'; |
| 23 import 'package:analyzer/src/generated/parser.dart'; |
| 24 import 'package:analyzer/src/generated/resolver.dart'; |
| 25 import 'package:analyzer/src/generated/scanner.dart'; |
| 26 import 'package:analyzer/src/generated/sdk.dart'; |
| 27 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 28 import 'package:analyzer/src/generated/source_io.dart'; |
| 29 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 30 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 31 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 32 import 'package:analyzer/src/services/lint.dart'; |
| 33 import 'package:analyzer/src/string_source.dart'; |
| 34 import 'package:analyzer/task/model.dart' hide AnalysisTask, WorkManager; |
| 35 import 'package:html/dom.dart' show Document; |
| 36 import 'package:path/path.dart' as pathos; |
| 37 import 'package:typed_mock/typed_mock.dart'; |
| 38 import 'package:unittest/unittest.dart'; |
| 39 import 'package:watcher/src/utils.dart'; |
| 40 |
| 41 import '../reflective_tests.dart'; |
| 42 import '../utils.dart'; |
| 43 import 'all_the_rest_test.dart'; |
| 44 import 'resolver_test.dart'; |
| 45 import 'test_support.dart'; |
| 46 |
| 47 main() { |
| 48 initializeTestEnvironment(); |
| 49 // Tests for the classes used in both old and new analysis implementations. |
| 50 runReflectiveTests(SourcesChangedEventTest); |
| 51 // Tests for the classes used in the old analysis implementation. |
| 52 if (!AnalysisEngine.instance.useTaskModel) { |
| 53 runReflectiveTests(AnalysisCacheTest); |
| 54 runReflectiveTests(AnalysisContextImplTest); |
| 55 runReflectiveTests(AnalysisTaskTest); |
| 56 runReflectiveTests(AnalysisOptionsImplTest); |
| 57 runReflectiveTests(DartEntryTest); |
| 58 runReflectiveTests(GenerateDartErrorsTaskTest); |
| 59 runReflectiveTests(GenerateDartHintsTaskTest); |
| 60 runReflectiveTests(GenerateDartLintsTaskTest); |
| 61 runReflectiveTests(GetContentTaskTest); |
| 62 runReflectiveTests(HtmlEntryTest); |
| 63 runReflectiveTests(IncrementalAnalysisCacheTest); |
| 64 runReflectiveTests(IncrementalAnalysisTaskTest); |
| 65 runReflectiveTests(LintGeneratorTest); |
| 66 runReflectiveTests(ParseDartTaskTest); |
| 67 runReflectiveTests(ParseHtmlTaskTest); |
| 68 runReflectiveTests(PartitionManagerTest); |
| 69 runReflectiveTests(ResolveDartLibraryTaskTest); |
| 70 runReflectiveTests(ResolveDartUnitTaskTest); |
| 71 runReflectiveTests(ResolveHtmlTaskTest); |
| 72 runReflectiveTests(ScanDartTaskTest); |
| 73 runReflectiveTests(SdkCachePartitionTest); |
| 74 runReflectiveTests(UniversalCachePartitionTest); |
| 75 runReflectiveTests(WorkManagerTest); |
| 76 } |
| 77 } |
| 78 |
| 79 @reflectiveTest |
| 80 class AnalysisCacheTest extends EngineTestCase { |
| 81 void test_creation() { |
| 82 expect(new AnalysisCache(new List<CachePartition>(0)), isNotNull); |
| 83 } |
| 84 |
| 85 void test_get() { |
| 86 AnalysisCache cache = new AnalysisCache(new List<CachePartition>(0)); |
| 87 TestSource source = new TestSource(); |
| 88 expect(cache.get(source), isNull); |
| 89 } |
| 90 |
| 91 void test_iterator() { |
| 92 CachePartition partition = |
| 93 new UniversalCachePartition(null, 8, new DefaultRetentionPolicy()); |
| 94 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); |
| 95 TestSource source = new TestSource(); |
| 96 DartEntry entry = new DartEntry(); |
| 97 cache.put(source, entry); |
| 98 MapIterator<Source, SourceEntry> iterator = cache.iterator(); |
| 99 expect(iterator.moveNext(), isTrue); |
| 100 expect(iterator.key, same(source)); |
| 101 expect(iterator.value, same(entry)); |
| 102 expect(iterator.moveNext(), isFalse); |
| 103 } |
| 104 |
| 105 /** |
| 106 * Verify that if multiple Source objects refer to the same file via |
| 107 * different URIs, they are treated as separate entries in the cache. |
| 108 */ |
| 109 void test_lookup_distinguishes_uris() { |
| 110 CachePartition partition = |
| 111 new UniversalCachePartition(null, 8, new DefaultRetentionPolicy()); |
| 112 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); |
| 113 JavaFile file = new JavaFile('baz.dart'); |
| 114 Source source1 = new FileBasedSource(file); |
| 115 Source source2 = |
| 116 new FileBasedSource(file, Uri.parse('package:foo/baz.dart')); |
| 117 Source source3 = |
| 118 new FileBasedSource(file, Uri.parse('package:bar/baz.dart')); |
| 119 DartEntry entry1 = new DartEntry(); |
| 120 DartEntry entry2 = new DartEntry(); |
| 121 DartEntry entry3 = new DartEntry(); |
| 122 cache.put(source1, entry1); |
| 123 cache.put(source2, entry2); |
| 124 cache.put(source3, entry3); |
| 125 expect(cache.get(source1), same(entry1)); |
| 126 expect(cache.get(source2), same(entry2)); |
| 127 expect(cache.get(source3), same(entry3)); |
| 128 } |
| 129 |
| 130 void test_put_noFlush() { |
| 131 CachePartition partition = |
| 132 new UniversalCachePartition(null, 8, new DefaultRetentionPolicy()); |
| 133 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); |
| 134 TestSource source = new TestSource(); |
| 135 DartEntry entry = new DartEntry(); |
| 136 cache.put(source, entry); |
| 137 expect(cache.get(source), same(entry)); |
| 138 } |
| 139 |
| 140 void test_setMaxCacheSize() { |
| 141 CachePartition partition = new UniversalCachePartition( |
| 142 null, 8, new _AnalysisCacheTest_test_setMaxCacheSize()); |
| 143 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); |
| 144 int size = 6; |
| 145 for (int i = 0; i < size; i++) { |
| 146 Source source = new TestSource("/test$i.dart"); |
| 147 DartEntry entry = new DartEntry(); |
| 148 entry.setValue(DartEntry.PARSED_UNIT, null); |
| 149 cache.put(source, entry); |
| 150 cache.accessedAst(source); |
| 151 } |
| 152 _assertNonFlushedCount(size, cache); |
| 153 int newSize = size - 2; |
| 154 partition.maxCacheSize = newSize; |
| 155 _assertNonFlushedCount(newSize, cache); |
| 156 } |
| 157 |
| 158 void test_size() { |
| 159 CachePartition partition = |
| 160 new UniversalCachePartition(null, 8, new DefaultRetentionPolicy()); |
| 161 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); |
| 162 int size = 4; |
| 163 for (int i = 0; i < size; i++) { |
| 164 Source source = new TestSource("/test$i.dart"); |
| 165 cache.put(source, new DartEntry()); |
| 166 cache.accessedAst(source); |
| 167 } |
| 168 expect(cache.size(), size); |
| 169 } |
| 170 |
| 171 void _assertNonFlushedCount(int expectedCount, AnalysisCache cache) { |
| 172 int nonFlushedCount = 0; |
| 173 MapIterator<Source, SourceEntry> iterator = cache.iterator(); |
| 174 while (iterator.moveNext()) { |
| 175 if (iterator.value.getState(DartEntry.PARSED_UNIT) != |
| 176 CacheState.FLUSHED) { |
| 177 nonFlushedCount++; |
| 178 } |
| 179 } |
| 180 expect(nonFlushedCount, expectedCount); |
| 181 } |
| 182 } |
| 183 |
| 184 @reflectiveTest |
| 185 class AnalysisContextImplTest extends EngineTestCase { |
| 186 /** |
| 187 * An analysis context whose source factory is [sourceFactory]. |
| 188 */ |
| 189 AnalysisContextImpl _context; |
| 190 |
| 191 /** |
| 192 * The source factory associated with the analysis [context]. |
| 193 */ |
| 194 SourceFactory _sourceFactory; |
| 195 |
| 196 void fail_performAnalysisTask_importedLibraryDelete_html() { |
| 197 Source htmlSource = _addSource( |
| 198 "/page.html", |
| 199 r''' |
| 200 <html><body><script type="application/dart"> |
| 201 import 'libB.dart'; |
| 202 main() {print('hello dart');} |
| 203 </script></body></html>'''); |
| 204 Source libBSource = _addSource("/libB.dart", "library libB;"); |
| 205 _analyzeAll_assertFinished(); |
| 206 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, |
| 207 reason: "htmlUnit resolved 1"); |
| 208 expect( |
| 209 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, |
| 210 reason: "libB resolved 1"); |
| 211 expect(!_hasAnalysisErrorWithErrorSeverity(_context.getErrors(htmlSource)), |
| 212 isTrue, |
| 213 reason: "htmlSource doesn't have errors"); |
| 214 // remove libB.dart content and analyze |
| 215 _context.setContents(libBSource, null); |
| 216 _analyzeAll_assertFinished(); |
| 217 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, |
| 218 reason: "htmlUnit resolved 1"); |
| 219 AnalysisErrorInfo errors = _context.getErrors(htmlSource); |
| 220 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, |
| 221 reason: "htmlSource has an error"); |
| 222 } |
| 223 |
| 224 void fail_recordLibraryElements() { |
| 225 fail("Implement this"); |
| 226 } |
| 227 |
| 228 @override |
| 229 void setUp() { |
| 230 _context = new AnalysisContextImpl(); |
| 231 _sourceFactory = new SourceFactory([ |
| 232 new DartUriResolver(DirectoryBasedDartSdk.defaultSdk), |
| 233 new FileUriResolver() |
| 234 ]); |
| 235 _context.sourceFactory = _sourceFactory; |
| 236 AnalysisOptionsImpl options = |
| 237 new AnalysisOptionsImpl.from(_context.analysisOptions); |
| 238 options.cacheSize = 256; |
| 239 _context.analysisOptions = options; |
| 240 } |
| 241 |
| 242 @override |
| 243 void tearDown() { |
| 244 _context = null; |
| 245 _sourceFactory = null; |
| 246 super.tearDown(); |
| 247 } |
| 248 |
| 249 Future test_applyChanges_add() { |
| 250 SourcesChangedListener listener = new SourcesChangedListener(); |
| 251 _context.onSourcesChanged.listen(listener.onData); |
| 252 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); |
| 253 Source source = |
| 254 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 255 ChangeSet changeSet = new ChangeSet(); |
| 256 changeSet.addedSource(source); |
| 257 _context.applyChanges(changeSet); |
| 258 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); |
| 259 return pumpEventQueue().then((_) { |
| 260 listener.assertEvent(wereSourcesAdded: true); |
| 261 listener.assertNoMoreEvents(); |
| 262 }); |
| 263 } |
| 264 |
| 265 Future test_applyChanges_change() { |
| 266 SourcesChangedListener listener = new SourcesChangedListener(); |
| 267 _context.onSourcesChanged.listen(listener.onData); |
| 268 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); |
| 269 Source source = |
| 270 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 271 ChangeSet changeSet1 = new ChangeSet(); |
| 272 changeSet1.addedSource(source); |
| 273 _context.applyChanges(changeSet1); |
| 274 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); |
| 275 Source source2 = |
| 276 new FileBasedSource(FileUtilities2.createFile("/test2.dart")); |
| 277 ChangeSet changeSet2 = new ChangeSet(); |
| 278 changeSet2.addedSource(source2); |
| 279 changeSet2.changedSource(source); |
| 280 _context.applyChanges(changeSet2); |
| 281 return pumpEventQueue().then((_) { |
| 282 listener.assertEvent(wereSourcesAdded: true); |
| 283 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); |
| 284 listener.assertNoMoreEvents(); |
| 285 }); |
| 286 } |
| 287 |
| 288 Future test_applyChanges_change_content() { |
| 289 SourcesChangedListener listener = new SourcesChangedListener(); |
| 290 _context.onSourcesChanged.listen(listener.onData); |
| 291 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); |
| 292 Source source = |
| 293 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 294 ChangeSet changeSet1 = new ChangeSet(); |
| 295 changeSet1.addedSource(source); |
| 296 _context.applyChanges(changeSet1); |
| 297 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); |
| 298 Source source2 = |
| 299 new FileBasedSource(FileUtilities2.createFile("/test2.dart")); |
| 300 ChangeSet changeSet2 = new ChangeSet(); |
| 301 changeSet2.addedSource(source2); |
| 302 changeSet2.changedContent(source, 'library test;'); |
| 303 _context.applyChanges(changeSet2); |
| 304 return pumpEventQueue().then((_) { |
| 305 listener.assertEvent(wereSourcesAdded: true); |
| 306 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); |
| 307 listener.assertNoMoreEvents(); |
| 308 }); |
| 309 } |
| 310 |
| 311 void test_applyChanges_change_flush_element() { |
| 312 _context = AnalysisContextFactory.oldContextWithCore(); |
| 313 _sourceFactory = _context.sourceFactory; |
| 314 Source librarySource = _addSource( |
| 315 "/lib.dart", |
| 316 r''' |
| 317 library lib; |
| 318 int a = 0;'''); |
| 319 expect(_context.computeLibraryElement(librarySource), isNotNull); |
| 320 _context.setContents( |
| 321 librarySource, |
| 322 r''' |
| 323 library lib; |
| 324 int aa = 0;'''); |
| 325 expect(_context.getLibraryElement(librarySource), isNull); |
| 326 } |
| 327 |
| 328 Future test_applyChanges_change_multiple() { |
| 329 _context = AnalysisContextFactory.oldContextWithCore(); |
| 330 SourcesChangedListener listener = new SourcesChangedListener(); |
| 331 _context.onSourcesChanged.listen(listener.onData); |
| 332 _sourceFactory = _context.sourceFactory; |
| 333 String libraryContents1 = r''' |
| 334 library lib; |
| 335 part 'part.dart'; |
| 336 int a = 0;'''; |
| 337 Source librarySource = _addSource("/lib.dart", libraryContents1); |
| 338 String partContents1 = r''' |
| 339 part of lib; |
| 340 int b = a;'''; |
| 341 Source partSource = _addSource("/part.dart", partContents1); |
| 342 _context.computeLibraryElement(librarySource); |
| 343 String libraryContents2 = r''' |
| 344 library lib; |
| 345 part 'part.dart'; |
| 346 int aa = 0;'''; |
| 347 _context.setContents(librarySource, libraryContents2); |
| 348 String partContents2 = r''' |
| 349 part of lib; |
| 350 int b = aa;'''; |
| 351 _context.setContents(partSource, partContents2); |
| 352 _context.computeLibraryElement(librarySource); |
| 353 CompilationUnit libraryUnit = |
| 354 _context.resolveCompilationUnit2(librarySource, librarySource); |
| 355 CompilationUnit partUnit = |
| 356 _context.resolveCompilationUnit2(partSource, librarySource); |
| 357 TopLevelVariableDeclaration declaration = |
| 358 libraryUnit.declarations[0] as TopLevelVariableDeclaration; |
| 359 Element declarationElement = declaration.variables.variables[0].element; |
| 360 TopLevelVariableDeclaration use = |
| 361 partUnit.declarations[0] as TopLevelVariableDeclaration; |
| 362 Element useElement = (use.variables.variables[0].initializer |
| 363 as SimpleIdentifier).staticElement; |
| 364 expect((useElement as PropertyAccessorElement).variable, |
| 365 same(declarationElement)); |
| 366 return pumpEventQueue().then((_) { |
| 367 listener.assertEvent(wereSourcesAdded: true); |
| 368 listener.assertEvent(changedSources: [librarySource]); |
| 369 listener.assertEvent(wereSourcesAdded: true); |
| 370 listener.assertEvent(changedSources: [partSource]); |
| 371 listener.assertEvent(changedSources: [librarySource]); |
| 372 listener.assertEvent(changedSources: [partSource]); |
| 373 listener.assertNoMoreEvents(); |
| 374 }); |
| 375 } |
| 376 |
| 377 Future test_applyChanges_change_range() { |
| 378 SourcesChangedListener listener = new SourcesChangedListener(); |
| 379 _context.onSourcesChanged.listen(listener.onData); |
| 380 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); |
| 381 Source source = |
| 382 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 383 ChangeSet changeSet1 = new ChangeSet(); |
| 384 changeSet1.addedSource(source); |
| 385 _context.applyChanges(changeSet1); |
| 386 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); |
| 387 Source source2 = |
| 388 new FileBasedSource(FileUtilities2.createFile("/test2.dart")); |
| 389 ChangeSet changeSet2 = new ChangeSet(); |
| 390 changeSet2.addedSource(source2); |
| 391 changeSet2.changedRange(source, 'library test;', 0, 0, 13); |
| 392 _context.applyChanges(changeSet2); |
| 393 return pumpEventQueue().then((_) { |
| 394 listener.assertEvent(wereSourcesAdded: true); |
| 395 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); |
| 396 listener.assertNoMoreEvents(); |
| 397 }); |
| 398 } |
| 399 |
| 400 void test_applyChanges_empty() { |
| 401 _context.applyChanges(new ChangeSet()); |
| 402 expect(_context.performAnalysisTask().changeNotices, isNull); |
| 403 } |
| 404 |
| 405 void test_applyChanges_overriddenSource() { |
| 406 // Note: addSource adds the source to the contentCache. |
| 407 Source source = _addSource("/test.dart", "library test;"); |
| 408 _context.computeErrors(source); |
| 409 while (!_context.sourcesNeedingProcessing.isEmpty) { |
| 410 _context.performAnalysisTask(); |
| 411 } |
| 412 // Adding the source as a changedSource should have no effect since |
| 413 // it is already overridden in the content cache. |
| 414 ChangeSet changeSet = new ChangeSet(); |
| 415 changeSet.changedSource(source); |
| 416 _context.applyChanges(changeSet); |
| 417 expect(_context.sourcesNeedingProcessing, hasLength(0)); |
| 418 } |
| 419 |
| 420 Future test_applyChanges_remove() { |
| 421 _context = AnalysisContextFactory.oldContextWithCore(); |
| 422 SourcesChangedListener listener = new SourcesChangedListener(); |
| 423 _context.onSourcesChanged.listen(listener.onData); |
| 424 _sourceFactory = _context.sourceFactory; |
| 425 String libAContents = r''' |
| 426 library libA; |
| 427 import 'libB.dart';'''; |
| 428 Source libA = _addSource("/libA.dart", libAContents); |
| 429 String libBContents = "library libB;"; |
| 430 Source libB = _addSource("/libB.dart", libBContents); |
| 431 LibraryElement libAElement = _context.computeLibraryElement(libA); |
| 432 List<LibraryElement> importedLibraries = libAElement.importedLibraries; |
| 433 expect(importedLibraries, hasLength(2)); |
| 434 _context.computeErrors(libA); |
| 435 _context.computeErrors(libB); |
| 436 expect(_context.sourcesNeedingProcessing, hasLength(0)); |
| 437 _context.setContents(libB, null); |
| 438 _removeSource(libB); |
| 439 List<Source> sources = _context.sourcesNeedingProcessing; |
| 440 expect(sources, hasLength(1)); |
| 441 expect(sources[0], same(libA)); |
| 442 libAElement = _context.computeLibraryElement(libA); |
| 443 importedLibraries = libAElement.importedLibraries; |
| 444 expect(importedLibraries, hasLength(1)); |
| 445 return pumpEventQueue().then((_) { |
| 446 listener.assertEvent(wereSourcesAdded: true); |
| 447 listener.assertEvent(changedSources: [libA]); |
| 448 listener.assertEvent(wereSourcesAdded: true); |
| 449 listener.assertEvent(changedSources: [libB]); |
| 450 listener.assertEvent(changedSources: [libB]); |
| 451 listener.assertEvent(wereSourcesRemovedOrDeleted: true); |
| 452 listener.assertNoMoreEvents(); |
| 453 }); |
| 454 } |
| 455 |
| 456 /** |
| 457 * IDEA uses the following scenario: |
| 458 * 1. Add overlay. |
| 459 * 2. Change overlay. |
| 460 * 3. If the contents of the document buffer is the same as the contents |
| 461 * of the file, remove overlay. |
| 462 * So, we need to try to use incremental resolution for removing overlays too. |
| 463 */ |
| 464 void test_applyChanges_remove_incremental() { |
| 465 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 466 Source source = resourceProvider |
| 467 .newFile( |
| 468 '/test.dart', |
| 469 r''' |
| 470 main() { |
| 471 print(1); |
| 472 } |
| 473 ''') |
| 474 .createSource(); |
| 475 _context = AnalysisContextFactory.oldContextWithCore(); |
| 476 _context.analysisOptions = new AnalysisOptionsImpl()..incremental = true; |
| 477 _context.applyChanges(new ChangeSet()..addedSource(source)); |
| 478 // remember compilation unit |
| 479 _analyzeAll_assertFinished(); |
| 480 CompilationUnit unit = _context.getResolvedCompilationUnit2(source, source); |
| 481 // add overlay |
| 482 _context.setContents( |
| 483 source, |
| 484 r''' |
| 485 main() { |
| 486 print(12); |
| 487 } |
| 488 '''); |
| 489 _analyzeAll_assertFinished(); |
| 490 expect(_context.getResolvedCompilationUnit2(source, source), unit); |
| 491 // remove overlay |
| 492 _context.setContents(source, null); |
| 493 _context.validateCacheConsistency(); |
| 494 _analyzeAll_assertFinished(); |
| 495 expect(_context.getResolvedCompilationUnit2(source, source), unit); |
| 496 } |
| 497 |
| 498 Future test_applyChanges_removeContainer() { |
| 499 _context = AnalysisContextFactory.oldContextWithCore(); |
| 500 SourcesChangedListener listener = new SourcesChangedListener(); |
| 501 _context.onSourcesChanged.listen(listener.onData); |
| 502 _sourceFactory = _context.sourceFactory; |
| 503 String libAContents = r''' |
| 504 library libA; |
| 505 import 'libB.dart';'''; |
| 506 Source libA = _addSource("/libA.dart", libAContents); |
| 507 String libBContents = "library libB;"; |
| 508 Source libB = _addSource("/libB.dart", libBContents); |
| 509 _context.computeLibraryElement(libA); |
| 510 _context.computeErrors(libA); |
| 511 _context.computeErrors(libB); |
| 512 expect(_context.sourcesNeedingProcessing, hasLength(0)); |
| 513 ChangeSet changeSet = new ChangeSet(); |
| 514 SourceContainer removedContainer = |
| 515 new _AnalysisContextImplTest_test_applyChanges_removeContainer(libB); |
| 516 changeSet.removedContainer(removedContainer); |
| 517 _context.applyChanges(changeSet); |
| 518 List<Source> sources = _context.sourcesNeedingProcessing; |
| 519 expect(sources, hasLength(1)); |
| 520 expect(sources[0], same(libA)); |
| 521 return pumpEventQueue().then((_) { |
| 522 listener.assertEvent(wereSourcesAdded: true); |
| 523 listener.assertEvent(changedSources: [libA]); |
| 524 listener.assertEvent(wereSourcesAdded: true); |
| 525 listener.assertEvent(changedSources: [libB]); |
| 526 listener.assertEvent(wereSourcesRemovedOrDeleted: true); |
| 527 listener.assertNoMoreEvents(); |
| 528 }); |
| 529 } |
| 530 |
| 531 void test_computeDocumentationComment_block() { |
| 532 _context = AnalysisContextFactory.oldContextWithCore(); |
| 533 _sourceFactory = _context.sourceFactory; |
| 534 String comment = "/** Comment */"; |
| 535 Source source = _addSource( |
| 536 "/test.dart", |
| 537 """ |
| 538 $comment |
| 539 class A {}"""); |
| 540 LibraryElement libraryElement = _context.computeLibraryElement(source); |
| 541 expect(libraryElement, isNotNull); |
| 542 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
| 543 expect(libraryElement, isNotNull); |
| 544 expect(_context.computeDocumentationComment(classElement), comment); |
| 545 } |
| 546 |
| 547 void test_computeDocumentationComment_none() { |
| 548 _context = AnalysisContextFactory.oldContextWithCore(); |
| 549 _sourceFactory = _context.sourceFactory; |
| 550 Source source = _addSource("/test.dart", "class A {}"); |
| 551 LibraryElement libraryElement = _context.computeLibraryElement(source); |
| 552 expect(libraryElement, isNotNull); |
| 553 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
| 554 expect(libraryElement, isNotNull); |
| 555 expect(_context.computeDocumentationComment(classElement), isNull); |
| 556 } |
| 557 |
| 558 void test_computeDocumentationComment_null() { |
| 559 expect(_context.computeDocumentationComment(null), isNull); |
| 560 } |
| 561 |
| 562 void test_computeDocumentationComment_singleLine_multiple_EOL_n() { |
| 563 _context = AnalysisContextFactory.oldContextWithCore(); |
| 564 _sourceFactory = _context.sourceFactory; |
| 565 String comment = "/// line 1\n/// line 2\n/// line 3\n"; |
| 566 Source source = _addSource("/test.dart", "${comment}class A {}"); |
| 567 LibraryElement libraryElement = _context.computeLibraryElement(source); |
| 568 expect(libraryElement, isNotNull); |
| 569 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
| 570 expect(libraryElement, isNotNull); |
| 571 String actual = _context.computeDocumentationComment(classElement); |
| 572 expect(actual, "/// line 1\n/// line 2\n/// line 3"); |
| 573 } |
| 574 |
| 575 void test_computeDocumentationComment_singleLine_multiple_EOL_rn() { |
| 576 _context = AnalysisContextFactory.oldContextWithCore(); |
| 577 _sourceFactory = _context.sourceFactory; |
| 578 String comment = "/// line 1\r\n/// line 2\r\n/// line 3\r\n"; |
| 579 Source source = _addSource("/test.dart", "${comment}class A {}"); |
| 580 LibraryElement libraryElement = _context.computeLibraryElement(source); |
| 581 expect(libraryElement, isNotNull); |
| 582 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
| 583 expect(libraryElement, isNotNull); |
| 584 String actual = _context.computeDocumentationComment(classElement); |
| 585 expect(actual, "/// line 1\n/// line 2\n/// line 3"); |
| 586 } |
| 587 |
| 588 void test_computeErrors_dart_none() { |
| 589 Source source = _addSource("/lib.dart", "library lib;"); |
| 590 List<AnalysisError> errors = _context.computeErrors(source); |
| 591 expect(errors, hasLength(0)); |
| 592 } |
| 593 |
| 594 void test_computeErrors_dart_part() { |
| 595 Source librarySource = |
| 596 _addSource("/lib.dart", "library lib; part 'part.dart';"); |
| 597 Source partSource = _addSource("/part.dart", "part of 'lib';"); |
| 598 _context.parseCompilationUnit(librarySource); |
| 599 List<AnalysisError> errors = _context.computeErrors(partSource); |
| 600 expect(errors, isNotNull); |
| 601 expect(errors.length > 0, isTrue); |
| 602 } |
| 603 |
| 604 void test_computeErrors_dart_some() { |
| 605 Source source = _addSource("/lib.dart", "library 'lib';"); |
| 606 List<AnalysisError> errors = _context.computeErrors(source); |
| 607 expect(errors, isNotNull); |
| 608 expect(errors.length > 0, isTrue); |
| 609 } |
| 610 |
| 611 void test_computeErrors_html_none() { |
| 612 Source source = _addSource("/test.html", "<html></html>"); |
| 613 List<AnalysisError> errors = _context.computeErrors(source); |
| 614 expect(errors, hasLength(0)); |
| 615 } |
| 616 |
| 617 void test_computeExportedLibraries_none() { |
| 618 Source source = _addSource("/test.dart", "library test;"); |
| 619 expect(_context.computeExportedLibraries(source), hasLength(0)); |
| 620 } |
| 621 |
| 622 void test_computeExportedLibraries_some() { |
| 623 // addSource("/lib1.dart", "library lib1;"); |
| 624 // addSource("/lib2.dart", "library lib2;"); |
| 625 Source source = _addSource( |
| 626 "/test.dart", "library test; export 'lib1.dart'; export 'lib2.dart';"); |
| 627 expect(_context.computeExportedLibraries(source), hasLength(2)); |
| 628 } |
| 629 |
| 630 void test_computeHtmlElement_nonHtml() { |
| 631 Source source = _addSource("/test.dart", "library test;"); |
| 632 expect(_context.computeHtmlElement(source), isNull); |
| 633 } |
| 634 |
| 635 void test_computeHtmlElement_valid() { |
| 636 Source source = _addSource("/test.html", "<html></html>"); |
| 637 HtmlElement element = _context.computeHtmlElement(source); |
| 638 expect(element, isNotNull); |
| 639 expect(_context.computeHtmlElement(source), same(element)); |
| 640 } |
| 641 |
| 642 void test_computeImportedLibraries_none() { |
| 643 Source source = _addSource("/test.dart", "library test;"); |
| 644 expect(_context.computeImportedLibraries(source), hasLength(0)); |
| 645 } |
| 646 |
| 647 void test_computeImportedLibraries_some() { |
| 648 // addSource("/lib1.dart", "library lib1;"); |
| 649 // addSource("/lib2.dart", "library lib2;"); |
| 650 Source source = _addSource( |
| 651 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); |
| 652 expect(_context.computeImportedLibraries(source), hasLength(2)); |
| 653 } |
| 654 |
| 655 void test_computeKindOf_html() { |
| 656 Source source = _addSource("/test.html", ""); |
| 657 expect(_context.computeKindOf(source), same(SourceKind.HTML)); |
| 658 } |
| 659 |
| 660 void test_computeKindOf_library() { |
| 661 Source source = _addSource("/test.dart", "library lib;"); |
| 662 expect(_context.computeKindOf(source), same(SourceKind.LIBRARY)); |
| 663 } |
| 664 |
| 665 void test_computeKindOf_libraryAndPart() { |
| 666 Source source = _addSource("/test.dart", "library lib; part of lib;"); |
| 667 expect(_context.computeKindOf(source), same(SourceKind.LIBRARY)); |
| 668 } |
| 669 |
| 670 void test_computeKindOf_part() { |
| 671 Source source = _addSource("/test.dart", "part of lib;"); |
| 672 expect(_context.computeKindOf(source), same(SourceKind.PART)); |
| 673 } |
| 674 |
| 675 void test_computeLibraryElement() { |
| 676 _context = AnalysisContextFactory.oldContextWithCore(); |
| 677 _sourceFactory = _context.sourceFactory; |
| 678 Source source = _addSource("/test.dart", "library lib;"); |
| 679 LibraryElement element = _context.computeLibraryElement(source); |
| 680 expect(element, isNotNull); |
| 681 } |
| 682 |
| 683 void test_computeLineInfo_dart() { |
| 684 Source source = _addSource( |
| 685 "/test.dart", |
| 686 r''' |
| 687 library lib; |
| 688 |
| 689 main() {}'''); |
| 690 LineInfo info = _context.computeLineInfo(source); |
| 691 expect(info, isNotNull); |
| 692 } |
| 693 |
| 694 void test_computeLineInfo_html() { |
| 695 Source source = _addSource( |
| 696 "/test.html", |
| 697 r''' |
| 698 <html> |
| 699 <body> |
| 700 <h1>A</h1> |
| 701 </body> |
| 702 </html>'''); |
| 703 LineInfo info = _context.computeLineInfo(source); |
| 704 expect(info, isNotNull); |
| 705 } |
| 706 |
| 707 void test_computeResolvableCompilationUnit_dart_exception() { |
| 708 TestSource source = _addSourceWithException("/test.dart"); |
| 709 try { |
| 710 _context.computeResolvableCompilationUnit(source); |
| 711 fail("Expected AnalysisException"); |
| 712 } on AnalysisException { |
| 713 // Expected |
| 714 } |
| 715 } |
| 716 |
| 717 void test_computeResolvableCompilationUnit_html_exception() { |
| 718 Source source = _addSource("/lib.html", "<html></html>"); |
| 719 try { |
| 720 _context.computeResolvableCompilationUnit(source); |
| 721 fail("Expected AnalysisException"); |
| 722 } on AnalysisException { |
| 723 // Expected |
| 724 } |
| 725 } |
| 726 |
| 727 void test_computeResolvableCompilationUnit_valid() { |
| 728 Source source = _addSource("/lib.dart", "library lib;"); |
| 729 CompilationUnit parsedUnit = _context.parseCompilationUnit(source); |
| 730 expect(parsedUnit, isNotNull); |
| 731 CompilationUnit resolvedUnit = |
| 732 _context.computeResolvableCompilationUnit(source); |
| 733 expect(resolvedUnit, isNotNull); |
| 734 expect(resolvedUnit, same(parsedUnit)); |
| 735 } |
| 736 |
| 737 Future test_computeResolvedCompilationUnitAsync() { |
| 738 _context = AnalysisContextFactory.oldContextWithCore(); |
| 739 _sourceFactory = _context.sourceFactory; |
| 740 Source source = _addSource("/lib.dart", "library lib;"); |
| 741 // Complete all pending analysis tasks and flush the AST so that it won't |
| 742 // be available immediately. |
| 743 _performPendingAnalysisTasks(); |
| 744 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); |
| 745 dartEntry.flushAstStructures(); |
| 746 bool completed = false; |
| 747 _context |
| 748 .computeResolvedCompilationUnitAsync(source, source) |
| 749 .then((CompilationUnit unit) { |
| 750 expect(unit, isNotNull); |
| 751 completed = true; |
| 752 }); |
| 753 return pumpEventQueue().then((_) { |
| 754 expect(completed, isFalse); |
| 755 _performPendingAnalysisTasks(); |
| 756 }).then((_) => pumpEventQueue()).then((_) { |
| 757 expect(completed, isTrue); |
| 758 }); |
| 759 } |
| 760 |
| 761 Future test_computeResolvedCompilationUnitAsync_afterDispose() { |
| 762 _context = AnalysisContextFactory.oldContextWithCore(); |
| 763 _sourceFactory = _context.sourceFactory; |
| 764 Source source = _addSource("/lib.dart", "library lib;"); |
| 765 // Complete all pending analysis tasks and flush the AST so that it won't |
| 766 // be available immediately. |
| 767 _performPendingAnalysisTasks(); |
| 768 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); |
| 769 dartEntry.flushAstStructures(); |
| 770 // Dispose of the context. |
| 771 _context.dispose(); |
| 772 // Any attempt to start an asynchronous computation should return a future |
| 773 // which completes with error. |
| 774 CancelableFuture<CompilationUnit> future = |
| 775 _context.computeResolvedCompilationUnitAsync(source, source); |
| 776 bool completed = false; |
| 777 future.then((CompilationUnit unit) { |
| 778 fail('Future should have completed with error'); |
| 779 }, onError: (error) { |
| 780 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); |
| 781 completed = true; |
| 782 }); |
| 783 return pumpEventQueue().then((_) { |
| 784 expect(completed, isTrue); |
| 785 }); |
| 786 } |
| 787 |
| 788 Future test_computeResolvedCompilationUnitAsync_cancel() { |
| 789 _context = AnalysisContextFactory.oldContextWithCore(); |
| 790 _sourceFactory = _context.sourceFactory; |
| 791 Source source = _addSource("/lib.dart", "library lib;"); |
| 792 // Complete all pending analysis tasks and flush the AST so that it won't |
| 793 // be available immediately. |
| 794 _performPendingAnalysisTasks(); |
| 795 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); |
| 796 dartEntry.flushAstStructures(); |
| 797 CancelableFuture<CompilationUnit> future = |
| 798 _context.computeResolvedCompilationUnitAsync(source, source); |
| 799 bool completed = false; |
| 800 future.then((CompilationUnit unit) { |
| 801 fail('Future should have been canceled'); |
| 802 }, onError: (error) { |
| 803 expect(error, new isInstanceOf<FutureCanceledError>()); |
| 804 completed = true; |
| 805 }); |
| 806 expect(completed, isFalse); |
| 807 expect(_context.pendingFutureSources_forTesting, isNotEmpty); |
| 808 future.cancel(); |
| 809 expect(_context.pendingFutureSources_forTesting, isEmpty); |
| 810 return pumpEventQueue().then((_) { |
| 811 expect(completed, isTrue); |
| 812 expect(_context.pendingFutureSources_forTesting, isEmpty); |
| 813 }); |
| 814 } |
| 815 |
| 816 Future test_computeResolvedCompilationUnitAsync_dispose() { |
| 817 _context = AnalysisContextFactory.oldContextWithCore(); |
| 818 _sourceFactory = _context.sourceFactory; |
| 819 Source source = _addSource("/lib.dart", "library lib;"); |
| 820 // Complete all pending analysis tasks and flush the AST so that it won't |
| 821 // be available immediately. |
| 822 _performPendingAnalysisTasks(); |
| 823 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); |
| 824 dartEntry.flushAstStructures(); |
| 825 CancelableFuture<CompilationUnit> future = |
| 826 _context.computeResolvedCompilationUnitAsync(source, source); |
| 827 bool completed = false; |
| 828 future.then((CompilationUnit unit) { |
| 829 fail('Future should have completed with error'); |
| 830 }, onError: (error) { |
| 831 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); |
| 832 completed = true; |
| 833 }); |
| 834 expect(completed, isFalse); |
| 835 expect(_context.pendingFutureSources_forTesting, isNotEmpty); |
| 836 // Disposing of the context should cause all pending futures to complete |
| 837 // with AnalysisNotScheduled, so that no clients are left hanging. |
| 838 _context.dispose(); |
| 839 expect(_context.pendingFutureSources_forTesting, isEmpty); |
| 840 return pumpEventQueue().then((_) { |
| 841 expect(completed, isTrue); |
| 842 expect(_context.pendingFutureSources_forTesting, isEmpty); |
| 843 }); |
| 844 } |
| 845 |
| 846 Future test_computeResolvedCompilationUnitAsync_unrelatedLibrary() { |
| 847 _context = AnalysisContextFactory.oldContextWithCore(); |
| 848 _sourceFactory = _context.sourceFactory; |
| 849 Source librarySource = _addSource("/lib.dart", "library lib;"); |
| 850 Source partSource = _addSource("/part.dart", "part of foo;"); |
| 851 bool completed = false; |
| 852 _context |
| 853 .computeResolvedCompilationUnitAsync(partSource, librarySource) |
| 854 .then((_) { |
| 855 fail('Expected resolution to fail'); |
| 856 }, onError: (e) { |
| 857 expect(e, new isInstanceOf<AnalysisNotScheduledError>()); |
| 858 completed = true; |
| 859 }); |
| 860 return pumpEventQueue().then((_) { |
| 861 expect(completed, isFalse); |
| 862 _performPendingAnalysisTasks(); |
| 863 }).then((_) => pumpEventQueue()).then((_) { |
| 864 expect(completed, isTrue); |
| 865 }); |
| 866 } |
| 867 |
| 868 void test_dispose() { |
| 869 expect(_context.isDisposed, isFalse); |
| 870 _context.dispose(); |
| 871 expect(_context.isDisposed, isTrue); |
| 872 } |
| 873 |
| 874 void test_exists_false() { |
| 875 TestSource source = new TestSource(); |
| 876 source.exists2 = false; |
| 877 expect(_context.exists(source), isFalse); |
| 878 } |
| 879 |
| 880 void test_exists_null() { |
| 881 expect(_context.exists(null), isFalse); |
| 882 } |
| 883 |
| 884 void test_exists_overridden() { |
| 885 Source source = new TestSource(); |
| 886 _context.setContents(source, ""); |
| 887 expect(_context.exists(source), isTrue); |
| 888 } |
| 889 |
| 890 void test_exists_true() { |
| 891 expect(_context.exists(new AnalysisContextImplTest_Source_exists_true()), |
| 892 isTrue); |
| 893 } |
| 894 |
| 895 void test_getAnalysisOptions() { |
| 896 expect(_context.analysisOptions, isNotNull); |
| 897 } |
| 898 |
| 899 void test_getContents_fromSource() { |
| 900 String content = "library lib;"; |
| 901 TimestampedData<String> contents = |
| 902 _context.getContents(new TestSource('/test.dart', content)); |
| 903 expect(contents.data.toString(), content); |
| 904 } |
| 905 |
| 906 void test_getContents_overridden() { |
| 907 String content = "library lib;"; |
| 908 Source source = new TestSource(); |
| 909 _context.setContents(source, content); |
| 910 TimestampedData<String> contents = _context.getContents(source); |
| 911 expect(contents.data.toString(), content); |
| 912 } |
| 913 |
| 914 void test_getContents_unoverridden() { |
| 915 String content = "library lib;"; |
| 916 Source source = new TestSource('/test.dart', content); |
| 917 _context.setContents(source, "part of lib;"); |
| 918 _context.setContents(source, null); |
| 919 TimestampedData<String> contents = _context.getContents(source); |
| 920 expect(contents.data.toString(), content); |
| 921 } |
| 922 |
| 923 void test_getDeclaredVariables() { |
| 924 _context = AnalysisContextFactory.oldContextWithCore(); |
| 925 expect(_context.declaredVariables, isNotNull); |
| 926 } |
| 927 |
| 928 void test_getElement() { |
| 929 _context = AnalysisContextFactory.oldContextWithCore(); |
| 930 _sourceFactory = _context.sourceFactory; |
| 931 LibraryElement core = |
| 932 _context.computeLibraryElement(_sourceFactory.forUri("dart:core")); |
| 933 expect(core, isNotNull); |
| 934 ClassElement classObject = |
| 935 _findClass(core.definingCompilationUnit, "Object"); |
| 936 expect(classObject, isNotNull); |
| 937 ElementLocation location = classObject.location; |
| 938 Element element = _context.getElement(location); |
| 939 expect(element, same(classObject)); |
| 940 } |
| 941 |
| 942 void test_getElement_constructor_named() { |
| 943 Source source = _addSource( |
| 944 "/lib.dart", |
| 945 r''' |
| 946 class A { |
| 947 A.named() {} |
| 948 }'''); |
| 949 _analyzeAll_assertFinished(); |
| 950 LibraryElement library = _context.computeLibraryElement(source); |
| 951 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); |
| 952 ConstructorElement constructor = classA.constructors[0]; |
| 953 ElementLocation location = constructor.location; |
| 954 Element element = _context.getElement(location); |
| 955 expect(element, same(constructor)); |
| 956 } |
| 957 |
| 958 void test_getElement_constructor_unnamed() { |
| 959 Source source = _addSource( |
| 960 "/lib.dart", |
| 961 r''' |
| 962 class A { |
| 963 A() {} |
| 964 }'''); |
| 965 _analyzeAll_assertFinished(); |
| 966 LibraryElement library = _context.computeLibraryElement(source); |
| 967 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); |
| 968 ConstructorElement constructor = classA.constructors[0]; |
| 969 ElementLocation location = constructor.location; |
| 970 Element element = _context.getElement(location); |
| 971 expect(element, same(constructor)); |
| 972 } |
| 973 |
| 974 void test_getElement_enum() { |
| 975 Source source = _addSource('/test.dart', 'enum MyEnum {A, B, C}'); |
| 976 _analyzeAll_assertFinished(); |
| 977 LibraryElement library = _context.computeLibraryElement(source); |
| 978 ClassElement myEnum = library.definingCompilationUnit.getEnum('MyEnum'); |
| 979 ElementLocation location = myEnum.location; |
| 980 Element element = _context.getElement(location); |
| 981 expect(element, same(myEnum)); |
| 982 } |
| 983 |
| 984 void test_getErrors_dart_none() { |
| 985 Source source = _addSource("/lib.dart", "library lib;"); |
| 986 List<AnalysisError> errors = _context.getErrors(source).errors; |
| 987 expect(errors, hasLength(0)); |
| 988 _context.computeErrors(source); |
| 989 errors = _context.getErrors(source).errors; |
| 990 expect(errors, hasLength(0)); |
| 991 } |
| 992 |
| 993 void test_getErrors_dart_some() { |
| 994 Source source = _addSource("/lib.dart", "library 'lib';"); |
| 995 List<AnalysisError> errors = _context.getErrors(source).errors; |
| 996 expect(errors, hasLength(0)); |
| 997 _context.computeErrors(source); |
| 998 errors = _context.getErrors(source).errors; |
| 999 expect(errors, hasLength(1)); |
| 1000 } |
| 1001 |
| 1002 void test_getErrors_html_none() { |
| 1003 Source source = _addSource("/test.html", "<html></html>"); |
| 1004 List<AnalysisError> errors = _context.getErrors(source).errors; |
| 1005 expect(errors, hasLength(0)); |
| 1006 _context.computeErrors(source); |
| 1007 errors = _context.getErrors(source).errors; |
| 1008 expect(errors, hasLength(0)); |
| 1009 } |
| 1010 |
| 1011 void test_getErrors_html_some() { |
| 1012 Source source = _addSource( |
| 1013 "/test.html", |
| 1014 r''' |
| 1015 <html><head> |
| 1016 <script type='application/dart' src='test.dart'/> |
| 1017 </head></html>'''); |
| 1018 List<AnalysisError> errors = _context.getErrors(source).errors; |
| 1019 expect(errors, hasLength(0)); |
| 1020 _context.computeErrors(source); |
| 1021 errors = _context.getErrors(source).errors; |
| 1022 expect(errors, hasLength(1)); |
| 1023 } |
| 1024 |
| 1025 void test_getHtmlElement_dart() { |
| 1026 Source source = _addSource("/test.dart", ""); |
| 1027 expect(_context.getHtmlElement(source), isNull); |
| 1028 expect(_context.computeHtmlElement(source), isNull); |
| 1029 expect(_context.getHtmlElement(source), isNull); |
| 1030 } |
| 1031 |
| 1032 void test_getHtmlElement_html() { |
| 1033 Source source = _addSource("/test.html", "<html></html>"); |
| 1034 HtmlElement element = _context.getHtmlElement(source); |
| 1035 expect(element, isNull); |
| 1036 _context.computeHtmlElement(source); |
| 1037 element = _context.getHtmlElement(source); |
| 1038 expect(element, isNotNull); |
| 1039 } |
| 1040 |
| 1041 void test_getHtmlFilesReferencing_html() { |
| 1042 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1043 _sourceFactory = _context.sourceFactory; |
| 1044 Source htmlSource = _addSource( |
| 1045 "/test.html", |
| 1046 r''' |
| 1047 <html><head> |
| 1048 <script type='application/dart' src='test.dart'/> |
| 1049 <script type='application/dart' src='test.js'/> |
| 1050 </head></html>'''); |
| 1051 Source librarySource = _addSource("/test.dart", "library lib;"); |
| 1052 Source secondHtmlSource = _addSource("/test.html", "<html></html>"); |
| 1053 _context.computeLibraryElement(librarySource); |
| 1054 List<Source> result = _context.getHtmlFilesReferencing(secondHtmlSource); |
| 1055 expect(result, hasLength(0)); |
| 1056 _context.parseHtmlUnit(htmlSource); |
| 1057 result = _context.getHtmlFilesReferencing(secondHtmlSource); |
| 1058 expect(result, hasLength(0)); |
| 1059 } |
| 1060 |
| 1061 void test_getHtmlFilesReferencing_library() { |
| 1062 Source htmlSource = _addSource( |
| 1063 "/test.html", |
| 1064 r''' |
| 1065 <html><head> |
| 1066 <script type='application/dart' src='test.dart'/> |
| 1067 <script type='application/dart' src='test.js'/> |
| 1068 </head></html>'''); |
| 1069 Source librarySource = _addSource("/test.dart", "library lib;"); |
| 1070 List<Source> result = _context.getHtmlFilesReferencing(librarySource); |
| 1071 expect(result, hasLength(0)); |
| 1072 _context.parseHtmlUnit(htmlSource); |
| 1073 result = _context.getHtmlFilesReferencing(librarySource); |
| 1074 expect(result, hasLength(1)); |
| 1075 expect(result[0], htmlSource); |
| 1076 } |
| 1077 |
| 1078 void test_getHtmlFilesReferencing_part() { |
| 1079 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1080 _sourceFactory = _context.sourceFactory; |
| 1081 Source htmlSource = _addSource( |
| 1082 "/test.html", |
| 1083 r''' |
| 1084 <html><head> |
| 1085 <script type='application/dart' src='test.dart'/> |
| 1086 <script type='application/dart' src='test.js'/> |
| 1087 </head></html>'''); |
| 1088 Source librarySource = |
| 1089 _addSource("/test.dart", "library lib; part 'part.dart';"); |
| 1090 Source partSource = _addSource("/part.dart", "part of lib;"); |
| 1091 _context.computeLibraryElement(librarySource); |
| 1092 List<Source> result = _context.getHtmlFilesReferencing(partSource); |
| 1093 expect(result, hasLength(0)); |
| 1094 _context.parseHtmlUnit(htmlSource); |
| 1095 result = _context.getHtmlFilesReferencing(partSource); |
| 1096 expect(result, hasLength(1)); |
| 1097 expect(result[0], htmlSource); |
| 1098 } |
| 1099 |
| 1100 void test_getHtmlSources() { |
| 1101 List<Source> sources = _context.htmlSources; |
| 1102 expect(sources, hasLength(0)); |
| 1103 Source source = _addSource("/test.html", ""); |
| 1104 _context.computeKindOf(source); |
| 1105 sources = _context.htmlSources; |
| 1106 expect(sources, hasLength(1)); |
| 1107 expect(sources[0], source); |
| 1108 } |
| 1109 |
| 1110 void test_getKindOf_html() { |
| 1111 Source source = _addSource("/test.html", ""); |
| 1112 expect(_context.getKindOf(source), same(SourceKind.HTML)); |
| 1113 } |
| 1114 |
| 1115 void test_getKindOf_library() { |
| 1116 Source source = _addSource("/test.dart", "library lib;"); |
| 1117 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); |
| 1118 _context.computeKindOf(source); |
| 1119 expect(_context.getKindOf(source), same(SourceKind.LIBRARY)); |
| 1120 } |
| 1121 |
| 1122 void test_getKindOf_part() { |
| 1123 Source source = _addSource("/test.dart", "part of lib;"); |
| 1124 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); |
| 1125 _context.computeKindOf(source); |
| 1126 expect(_context.getKindOf(source), same(SourceKind.PART)); |
| 1127 } |
| 1128 |
| 1129 void test_getKindOf_unknown() { |
| 1130 Source source = _addSource("/test.css", ""); |
| 1131 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); |
| 1132 } |
| 1133 |
| 1134 void test_getLaunchableClientLibrarySources() { |
| 1135 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1136 _sourceFactory = _context.sourceFactory; |
| 1137 List<Source> sources = _context.launchableClientLibrarySources; |
| 1138 expect(sources, hasLength(0)); |
| 1139 Source source = _addSource( |
| 1140 "/test.dart", |
| 1141 r''' |
| 1142 import 'dart:html'; |
| 1143 main() {}'''); |
| 1144 _context.computeLibraryElement(source); |
| 1145 sources = _context.launchableClientLibrarySources; |
| 1146 expect(sources, hasLength(1)); |
| 1147 } |
| 1148 |
| 1149 void test_getLaunchableServerLibrarySources() { |
| 1150 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1151 _sourceFactory = _context.sourceFactory; |
| 1152 List<Source> sources = _context.launchableServerLibrarySources; |
| 1153 expect(sources, hasLength(0)); |
| 1154 Source source = _addSource("/test.dart", "main() {}"); |
| 1155 _context.computeLibraryElement(source); |
| 1156 sources = _context.launchableServerLibrarySources; |
| 1157 expect(sources, hasLength(1)); |
| 1158 } |
| 1159 |
| 1160 void test_getLibrariesContaining() { |
| 1161 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1162 _sourceFactory = _context.sourceFactory; |
| 1163 Source librarySource = _addSource( |
| 1164 "/lib.dart", |
| 1165 r''' |
| 1166 library lib; |
| 1167 part 'part.dart';'''); |
| 1168 Source partSource = _addSource("/part.dart", "part of lib;"); |
| 1169 _context.computeLibraryElement(librarySource); |
| 1170 List<Source> result = _context.getLibrariesContaining(librarySource); |
| 1171 expect(result, hasLength(1)); |
| 1172 expect(result[0], librarySource); |
| 1173 result = _context.getLibrariesContaining(partSource); |
| 1174 expect(result, hasLength(1)); |
| 1175 expect(result[0], librarySource); |
| 1176 } |
| 1177 |
| 1178 void test_getLibrariesDependingOn() { |
| 1179 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1180 _sourceFactory = _context.sourceFactory; |
| 1181 Source libASource = _addSource("/libA.dart", "library libA;"); |
| 1182 _addSource("/libB.dart", "library libB;"); |
| 1183 Source lib1Source = _addSource( |
| 1184 "/lib1.dart", |
| 1185 r''' |
| 1186 library lib1; |
| 1187 import 'libA.dart'; |
| 1188 export 'libB.dart';'''); |
| 1189 Source lib2Source = _addSource( |
| 1190 "/lib2.dart", |
| 1191 r''' |
| 1192 library lib2; |
| 1193 import 'libB.dart'; |
| 1194 export 'libA.dart';'''); |
| 1195 _context.computeLibraryElement(lib1Source); |
| 1196 _context.computeLibraryElement(lib2Source); |
| 1197 List<Source> result = _context.getLibrariesDependingOn(libASource); |
| 1198 expect(result, unorderedEquals([lib1Source, lib2Source])); |
| 1199 } |
| 1200 |
| 1201 void test_getLibrariesReferencedFromHtml() { |
| 1202 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1203 _sourceFactory = _context.sourceFactory; |
| 1204 Source htmlSource = _addSource( |
| 1205 "/test.html", |
| 1206 r''' |
| 1207 <html><head> |
| 1208 <script type='application/dart' src='test.dart'/> |
| 1209 <script type='application/dart' src='test.js'/> |
| 1210 </head></html>'''); |
| 1211 Source librarySource = _addSource("/test.dart", "library lib;"); |
| 1212 _context.computeLibraryElement(librarySource); |
| 1213 _context.parseHtmlUnit(htmlSource); |
| 1214 List<Source> result = _context.getLibrariesReferencedFromHtml(htmlSource); |
| 1215 expect(result, hasLength(1)); |
| 1216 expect(result[0], librarySource); |
| 1217 } |
| 1218 |
| 1219 void test_getLibrariesReferencedFromHtml_no() { |
| 1220 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1221 _sourceFactory = _context.sourceFactory; |
| 1222 Source htmlSource = _addSource( |
| 1223 "/test.html", |
| 1224 r''' |
| 1225 <html><head> |
| 1226 <script type='application/dart' src='test.js'/> |
| 1227 </head></html>'''); |
| 1228 _addSource("/test.dart", "library lib;"); |
| 1229 _context.parseHtmlUnit(htmlSource); |
| 1230 List<Source> result = _context.getLibrariesReferencedFromHtml(htmlSource); |
| 1231 expect(result, hasLength(0)); |
| 1232 } |
| 1233 |
| 1234 void test_getLibraryElement() { |
| 1235 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1236 _sourceFactory = _context.sourceFactory; |
| 1237 Source source = _addSource("/test.dart", "library lib;"); |
| 1238 LibraryElement element = _context.getLibraryElement(source); |
| 1239 expect(element, isNull); |
| 1240 _context.computeLibraryElement(source); |
| 1241 element = _context.getLibraryElement(source); |
| 1242 expect(element, isNotNull); |
| 1243 } |
| 1244 |
| 1245 void test_getLibrarySources() { |
| 1246 List<Source> sources = _context.librarySources; |
| 1247 int originalLength = sources.length; |
| 1248 Source source = _addSource("/test.dart", "library lib;"); |
| 1249 _context.computeKindOf(source); |
| 1250 sources = _context.librarySources; |
| 1251 expect(sources, hasLength(originalLength + 1)); |
| 1252 for (Source returnedSource in sources) { |
| 1253 if (returnedSource == source) { |
| 1254 return; |
| 1255 } |
| 1256 } |
| 1257 fail("The added source was not in the list of library sources"); |
| 1258 } |
| 1259 |
| 1260 void test_getLineInfo() { |
| 1261 Source source = _addSource( |
| 1262 "/test.dart", |
| 1263 r''' |
| 1264 library lib; |
| 1265 |
| 1266 main() {}'''); |
| 1267 LineInfo info = _context.getLineInfo(source); |
| 1268 expect(info, isNull); |
| 1269 _context.parseCompilationUnit(source); |
| 1270 info = _context.getLineInfo(source); |
| 1271 expect(info, isNotNull); |
| 1272 } |
| 1273 |
| 1274 void test_getModificationStamp_fromSource() { |
| 1275 int stamp = 42; |
| 1276 expect( |
| 1277 _context.getModificationStamp( |
| 1278 new AnalysisContextImplTest_Source_getModificationStamp_fromSource( |
| 1279 stamp)), |
| 1280 stamp); |
| 1281 } |
| 1282 |
| 1283 void test_getModificationStamp_overridden() { |
| 1284 int stamp = 42; |
| 1285 Source source = |
| 1286 new AnalysisContextImplTest_Source_getModificationStamp_overridden( |
| 1287 stamp); |
| 1288 _context.setContents(source, ""); |
| 1289 expect(stamp != _context.getModificationStamp(source), isTrue); |
| 1290 } |
| 1291 |
| 1292 void test_getPublicNamespace_element() { |
| 1293 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1294 _sourceFactory = _context.sourceFactory; |
| 1295 Source source = _addSource("/test.dart", "class A {}"); |
| 1296 LibraryElement library = _context.computeLibraryElement(source); |
| 1297 Namespace namespace = _context.getPublicNamespace(library); |
| 1298 expect(namespace, isNotNull); |
| 1299 EngineTestCase.assertInstanceOf( |
| 1300 (obj) => obj is ClassElement, ClassElement, namespace.get("A")); |
| 1301 } |
| 1302 |
| 1303 void test_getResolvedCompilationUnit_library() { |
| 1304 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1305 _sourceFactory = _context.sourceFactory; |
| 1306 Source source = _addSource("/lib.dart", "library libb;"); |
| 1307 LibraryElement library = _context.computeLibraryElement(source); |
| 1308 expect(_context.getResolvedCompilationUnit(source, library), isNotNull); |
| 1309 _context.setContents(source, "library lib;"); |
| 1310 expect(_context.getResolvedCompilationUnit(source, library), isNull); |
| 1311 } |
| 1312 |
| 1313 void test_getResolvedCompilationUnit_library_null() { |
| 1314 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1315 _sourceFactory = _context.sourceFactory; |
| 1316 Source source = _addSource("/lib.dart", "library lib;"); |
| 1317 expect(_context.getResolvedCompilationUnit(source, null), isNull); |
| 1318 } |
| 1319 |
| 1320 void test_getResolvedCompilationUnit_source_dart() { |
| 1321 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1322 _sourceFactory = _context.sourceFactory; |
| 1323 Source source = _addSource("/lib.dart", "library lib;"); |
| 1324 expect(_context.getResolvedCompilationUnit2(source, source), isNull); |
| 1325 _context.resolveCompilationUnit2(source, source); |
| 1326 expect(_context.getResolvedCompilationUnit2(source, source), isNotNull); |
| 1327 } |
| 1328 |
| 1329 void test_getResolvedCompilationUnit_source_html() { |
| 1330 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1331 _sourceFactory = _context.sourceFactory; |
| 1332 Source source = _addSource("/test.html", "<html></html>"); |
| 1333 expect(_context.getResolvedCompilationUnit2(source, source), isNull); |
| 1334 expect(_context.resolveCompilationUnit2(source, source), isNull); |
| 1335 expect(_context.getResolvedCompilationUnit2(source, source), isNull); |
| 1336 } |
| 1337 |
| 1338 void test_getResolvedHtmlUnit() { |
| 1339 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1340 _sourceFactory = _context.sourceFactory; |
| 1341 Source source = _addSource("/test.html", "<html></html>"); |
| 1342 expect(_context.getResolvedHtmlUnit(source), isNull); |
| 1343 _context.resolveHtmlUnit(source); |
| 1344 expect(_context.getResolvedHtmlUnit(source), isNotNull); |
| 1345 } |
| 1346 |
| 1347 void test_getSourceFactory() { |
| 1348 expect(_context.sourceFactory, same(_sourceFactory)); |
| 1349 } |
| 1350 |
| 1351 void test_getSourcesWithFullName() { |
| 1352 String filePath = '/foo/lib/file.dart'; |
| 1353 List<Source> expected = <Source>[]; |
| 1354 ChangeSet changeSet = new ChangeSet(); |
| 1355 |
| 1356 TestSourceWithUri source1 = |
| 1357 new TestSourceWithUri(filePath, Uri.parse('file://$filePath')); |
| 1358 expected.add(source1); |
| 1359 changeSet.addedSource(source1); |
| 1360 |
| 1361 TestSourceWithUri source2 = |
| 1362 new TestSourceWithUri(filePath, Uri.parse('package:foo/file.dart')); |
| 1363 expected.add(source2); |
| 1364 changeSet.addedSource(source2); |
| 1365 |
| 1366 _context.applyChanges(changeSet); |
| 1367 expect( |
| 1368 _context.getSourcesWithFullName(filePath), unorderedEquals(expected)); |
| 1369 } |
| 1370 |
| 1371 void test_getStatistics() { |
| 1372 AnalysisContextStatistics statistics = _context.statistics; |
| 1373 expect(statistics, isNotNull); |
| 1374 // The following lines are fragile. |
| 1375 // The values depend on the number of libraries in the SDK. |
| 1376 // assertLength(0, statistics.getCacheRows()); |
| 1377 // assertLength(0, statistics.getExceptions()); |
| 1378 // assertLength(0, statistics.getSources()); |
| 1379 } |
| 1380 |
| 1381 Future test_implicitAnalysisEvents_added() async { |
| 1382 AnalyzedSourcesListener listener = new AnalyzedSourcesListener(); |
| 1383 _context.implicitAnalysisEvents.listen(listener.onData); |
| 1384 // |
| 1385 // Create a file that references an file that is not explicitly being |
| 1386 // analyzed and fully analyze it. Ensure that the listener is told about |
| 1387 // the implicitly analyzed file. |
| 1388 // |
| 1389 Source sourceA = _addSource('/a.dart', "library a; import 'b.dart';"); |
| 1390 Source sourceB = _createSource('/b.dart', "library b;"); |
| 1391 _context.computeErrors(sourceA); |
| 1392 await pumpEventQueue(); |
| 1393 listener.expectAnalyzed(sourceB); |
| 1394 } |
| 1395 |
| 1396 void test_isClientLibrary_dart() { |
| 1397 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1398 _sourceFactory = _context.sourceFactory; |
| 1399 Source source = _addSource( |
| 1400 "/test.dart", |
| 1401 r''' |
| 1402 import 'dart:html'; |
| 1403 |
| 1404 main() {}'''); |
| 1405 expect(_context.isClientLibrary(source), isFalse); |
| 1406 expect(_context.isServerLibrary(source), isFalse); |
| 1407 _context.computeLibraryElement(source); |
| 1408 expect(_context.isClientLibrary(source), isTrue); |
| 1409 expect(_context.isServerLibrary(source), isFalse); |
| 1410 } |
| 1411 |
| 1412 void test_isClientLibrary_html() { |
| 1413 Source source = _addSource("/test.html", "<html></html>"); |
| 1414 expect(_context.isClientLibrary(source), isFalse); |
| 1415 } |
| 1416 |
| 1417 void test_isServerLibrary_dart() { |
| 1418 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1419 _sourceFactory = _context.sourceFactory; |
| 1420 Source source = _addSource( |
| 1421 "/test.dart", |
| 1422 r''' |
| 1423 library lib; |
| 1424 |
| 1425 main() {}'''); |
| 1426 expect(_context.isClientLibrary(source), isFalse); |
| 1427 expect(_context.isServerLibrary(source), isFalse); |
| 1428 _context.computeLibraryElement(source); |
| 1429 expect(_context.isClientLibrary(source), isFalse); |
| 1430 expect(_context.isServerLibrary(source), isTrue); |
| 1431 } |
| 1432 |
| 1433 void test_isServerLibrary_html() { |
| 1434 Source source = _addSource("/test.html", "<html></html>"); |
| 1435 expect(_context.isServerLibrary(source), isFalse); |
| 1436 } |
| 1437 |
| 1438 void test_parseCompilationUnit_errors() { |
| 1439 Source source = _addSource("/lib.dart", "library {"); |
| 1440 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); |
| 1441 expect(compilationUnit, isNotNull); |
| 1442 List<AnalysisError> errors = _context.getErrors(source).errors; |
| 1443 expect(errors, isNotNull); |
| 1444 expect(errors.length > 0, isTrue); |
| 1445 } |
| 1446 |
| 1447 void test_parseCompilationUnit_exception() { |
| 1448 Source source = _addSourceWithException("/test.dart"); |
| 1449 try { |
| 1450 _context.parseCompilationUnit(source); |
| 1451 fail("Expected AnalysisException"); |
| 1452 } on AnalysisException { |
| 1453 // Expected |
| 1454 } |
| 1455 } |
| 1456 |
| 1457 void test_parseCompilationUnit_html() { |
| 1458 Source source = _addSource("/test.html", "<html></html>"); |
| 1459 expect(_context.parseCompilationUnit(source), isNull); |
| 1460 } |
| 1461 |
| 1462 void test_parseCompilationUnit_noErrors() { |
| 1463 Source source = _addSource("/lib.dart", "library lib;"); |
| 1464 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); |
| 1465 expect(compilationUnit, isNotNull); |
| 1466 expect(_context.getErrors(source).errors, hasLength(0)); |
| 1467 } |
| 1468 |
| 1469 void test_parseCompilationUnit_nonExistentSource() { |
| 1470 Source source = |
| 1471 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 1472 try { |
| 1473 _context.parseCompilationUnit(source); |
| 1474 fail("Expected AnalysisException because file does not exist"); |
| 1475 } on AnalysisException { |
| 1476 // Expected result |
| 1477 } |
| 1478 } |
| 1479 |
| 1480 void test_parseHtmlUnit_noErrors() { |
| 1481 Source source = _addSource("/lib.html", "<html></html>"); |
| 1482 ht.HtmlUnit unit = _context.parseHtmlUnit(source); |
| 1483 expect(unit, isNotNull); |
| 1484 } |
| 1485 |
| 1486 void test_parseHtmlUnit_resolveDirectives() { |
| 1487 Source libSource = _addSource( |
| 1488 "/lib.dart", |
| 1489 r''' |
| 1490 library lib; |
| 1491 class ClassA {}'''); |
| 1492 Source source = _addSource( |
| 1493 "/lib.html", |
| 1494 r''' |
| 1495 <html> |
| 1496 <head> |
| 1497 <script type='application/dart'> |
| 1498 import 'lib.dart'; |
| 1499 ClassA v = null; |
| 1500 </script> |
| 1501 </head> |
| 1502 <body> |
| 1503 </body> |
| 1504 </html>'''); |
| 1505 ht.HtmlUnit unit = _context.parseHtmlUnit(source); |
| 1506 // import directive should be resolved |
| 1507 ht.XmlTagNode htmlNode = unit.tagNodes[0]; |
| 1508 ht.XmlTagNode headNode = htmlNode.tagNodes[0]; |
| 1509 ht.HtmlScriptTagNode scriptNode = headNode.tagNodes[0]; |
| 1510 CompilationUnit script = scriptNode.script; |
| 1511 ImportDirective importNode = script.directives[0] as ImportDirective; |
| 1512 expect(importNode.uriContent, isNotNull); |
| 1513 expect(importNode.source, libSource); |
| 1514 } |
| 1515 |
| 1516 void test_performAnalysisTask_addPart() { |
| 1517 Source libSource = _addSource( |
| 1518 "/lib.dart", |
| 1519 r''' |
| 1520 library lib; |
| 1521 part 'part.dart';'''); |
| 1522 // run all tasks without part |
| 1523 _analyzeAll_assertFinished(); |
| 1524 // add part and run all tasks |
| 1525 Source partSource = _addSource( |
| 1526 "/part.dart", |
| 1527 r''' |
| 1528 part of lib; |
| 1529 '''); |
| 1530 _analyzeAll_assertFinished(); |
| 1531 // "libSource" should be here |
| 1532 List<Source> librariesWithPart = |
| 1533 _context.getLibrariesContaining(partSource); |
| 1534 expect(librariesWithPart, unorderedEquals([libSource])); |
| 1535 } |
| 1536 |
| 1537 void test_performAnalysisTask_changeLibraryContents() { |
| 1538 Source libSource = |
| 1539 _addSource("/test.dart", "library lib; part 'test-part.dart';"); |
| 1540 Source partSource = _addSource("/test-part.dart", "part of lib;"); |
| 1541 _analyzeAll_assertFinished(); |
| 1542 expect( |
| 1543 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1544 reason: "library resolved 1"); |
| 1545 expect( |
| 1546 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1547 reason: "part resolved 1"); |
| 1548 // update and analyze #1 |
| 1549 _context.setContents(libSource, "library lib;"); |
| 1550 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
| 1551 reason: "library changed 2"); |
| 1552 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1553 reason: "part changed 2"); |
| 1554 _analyzeAll_assertFinished(); |
| 1555 expect( |
| 1556 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1557 reason: "library resolved 2"); |
| 1558 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1559 reason: "part resolved 2"); |
| 1560 // update and analyze #2 |
| 1561 _context.setContents(libSource, "library lib; part 'test-part.dart';"); |
| 1562 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
| 1563 reason: "library changed 3"); |
| 1564 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1565 reason: "part changed 3"); |
| 1566 _analyzeAll_assertFinished(); |
| 1567 expect( |
| 1568 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1569 reason: "library resolved 2"); |
| 1570 expect( |
| 1571 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1572 reason: "part resolved 3"); |
| 1573 } |
| 1574 |
| 1575 void test_performAnalysisTask_changeLibraryThenPartContents() { |
| 1576 Source libSource = |
| 1577 _addSource("/test.dart", "library lib; part 'test-part.dart';"); |
| 1578 Source partSource = _addSource("/test-part.dart", "part of lib;"); |
| 1579 _analyzeAll_assertFinished(); |
| 1580 expect( |
| 1581 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1582 reason: "library resolved 1"); |
| 1583 expect( |
| 1584 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1585 reason: "part resolved 1"); |
| 1586 // update and analyze #1 |
| 1587 _context.setContents(libSource, "library lib;"); |
| 1588 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
| 1589 reason: "library changed 2"); |
| 1590 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1591 reason: "part changed 2"); |
| 1592 _analyzeAll_assertFinished(); |
| 1593 expect( |
| 1594 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1595 reason: "library resolved 2"); |
| 1596 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1597 reason: "part resolved 2"); |
| 1598 // update and analyze #2 |
| 1599 _context.setContents(partSource, "part of lib; // 1"); |
| 1600 // Assert that changing the part's content does not effect the library |
| 1601 // now that it is no longer part of that library |
| 1602 expect( |
| 1603 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1604 reason: "library changed 3"); |
| 1605 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1606 reason: "part changed 3"); |
| 1607 _analyzeAll_assertFinished(); |
| 1608 expect( |
| 1609 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1610 reason: "library resolved 3"); |
| 1611 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1612 reason: "part resolved 3"); |
| 1613 } |
| 1614 |
| 1615 void test_performAnalysisTask_changePartContents_makeItAPart() { |
| 1616 Source libSource = _addSource( |
| 1617 "/lib.dart", |
| 1618 r''' |
| 1619 library lib; |
| 1620 part 'part.dart'; |
| 1621 void f(x) {}'''); |
| 1622 Source partSource = _addSource("/part.dart", "void g() { f(null); }"); |
| 1623 _analyzeAll_assertFinished(); |
| 1624 expect( |
| 1625 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1626 reason: "library resolved 1"); |
| 1627 expect( |
| 1628 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1629 reason: "part resolved 1"); |
| 1630 // update and analyze |
| 1631 _context.setContents( |
| 1632 partSource, |
| 1633 r''' |
| 1634 part of lib; |
| 1635 void g() { f(null); }'''); |
| 1636 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
| 1637 reason: "library changed 2"); |
| 1638 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1639 reason: "part changed 2"); |
| 1640 _analyzeAll_assertFinished(); |
| 1641 expect( |
| 1642 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1643 reason: "library resolved 2"); |
| 1644 expect( |
| 1645 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1646 reason: "part resolved 2"); |
| 1647 expect(_context.getErrors(libSource).errors, hasLength(0)); |
| 1648 expect(_context.getErrors(partSource).errors, hasLength(0)); |
| 1649 } |
| 1650 |
| 1651 /** |
| 1652 * https://code.google.com/p/dart/issues/detail?id=12424 |
| 1653 */ |
| 1654 void test_performAnalysisTask_changePartContents_makeItNotPart() { |
| 1655 Source libSource = _addSource( |
| 1656 "/lib.dart", |
| 1657 r''' |
| 1658 library lib; |
| 1659 part 'part.dart'; |
| 1660 void f(x) {}'''); |
| 1661 Source partSource = _addSource( |
| 1662 "/part.dart", |
| 1663 r''' |
| 1664 part of lib; |
| 1665 void g() { f(null); }'''); |
| 1666 _analyzeAll_assertFinished(); |
| 1667 expect(_context.getErrors(libSource).errors, hasLength(0)); |
| 1668 expect(_context.getErrors(partSource).errors, hasLength(0)); |
| 1669 // Remove 'part' directive, which should make "f(null)" an error. |
| 1670 _context.setContents( |
| 1671 partSource, |
| 1672 r''' |
| 1673 //part of lib; |
| 1674 void g() { f(null); }'''); |
| 1675 _analyzeAll_assertFinished(); |
| 1676 expect(_context.getErrors(libSource).errors.length != 0, isTrue); |
| 1677 } |
| 1678 |
| 1679 void test_performAnalysisTask_changePartContents_noSemanticChanges() { |
| 1680 Source libSource = |
| 1681 _addSource("/test.dart", "library lib; part 'test-part.dart';"); |
| 1682 Source partSource = _addSource("/test-part.dart", "part of lib;"); |
| 1683 _analyzeAll_assertFinished(); |
| 1684 expect( |
| 1685 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1686 reason: "library resolved 1"); |
| 1687 expect( |
| 1688 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1689 reason: "part resolved 1"); |
| 1690 // update and analyze #1 |
| 1691 _context.setContents(partSource, "part of lib; // 1"); |
| 1692 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
| 1693 reason: "library changed 2"); |
| 1694 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1695 reason: "part changed 2"); |
| 1696 _analyzeAll_assertFinished(); |
| 1697 expect( |
| 1698 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1699 reason: "library resolved 2"); |
| 1700 expect( |
| 1701 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1702 reason: "part resolved 2"); |
| 1703 // update and analyze #2 |
| 1704 _context.setContents(partSource, "part of lib; // 12"); |
| 1705 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
| 1706 reason: "library changed 3"); |
| 1707 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
| 1708 reason: "part changed 3"); |
| 1709 _analyzeAll_assertFinished(); |
| 1710 expect( |
| 1711 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
| 1712 reason: "library resolved 3"); |
| 1713 expect( |
| 1714 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
| 1715 reason: "part resolved 3"); |
| 1716 } |
| 1717 |
| 1718 void test_performAnalysisTask_getContentException_dart() { |
| 1719 // add source that throw an exception on "get content" |
| 1720 Source source = new _Source_getContent_throwException('test.dart'); |
| 1721 { |
| 1722 ChangeSet changeSet = new ChangeSet(); |
| 1723 changeSet.addedSource(source); |
| 1724 _context.applyChanges(changeSet); |
| 1725 } |
| 1726 // prepare errors |
| 1727 _analyzeAll_assertFinished(); |
| 1728 List<AnalysisError> errors = _context.getErrors(source).errors; |
| 1729 // validate errors |
| 1730 expect(errors, hasLength(1)); |
| 1731 AnalysisError error = errors[0]; |
| 1732 expect(error.source, same(source)); |
| 1733 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); |
| 1734 } |
| 1735 |
| 1736 void test_performAnalysisTask_getContentException_html() { |
| 1737 // add source that throw an exception on "get content" |
| 1738 Source source = new _Source_getContent_throwException('test.html'); |
| 1739 { |
| 1740 ChangeSet changeSet = new ChangeSet(); |
| 1741 changeSet.addedSource(source); |
| 1742 _context.applyChanges(changeSet); |
| 1743 } |
| 1744 // prepare errors |
| 1745 _analyzeAll_assertFinished(); |
| 1746 List<AnalysisError> errors = _context.getErrors(source).errors; |
| 1747 // validate errors |
| 1748 expect(errors, hasLength(1)); |
| 1749 AnalysisError error = errors[0]; |
| 1750 expect(error.source, same(source)); |
| 1751 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); |
| 1752 } |
| 1753 |
| 1754 void test_performAnalysisTask_importedLibraryAdd() { |
| 1755 Source libASource = |
| 1756 _addSource("/libA.dart", "library libA; import 'libB.dart';"); |
| 1757 _analyzeAll_assertFinished(); |
| 1758 expect( |
| 1759 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, |
| 1760 reason: "libA resolved 1"); |
| 1761 expect(_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), |
| 1762 isTrue, |
| 1763 reason: "libA has an error"); |
| 1764 // add libB.dart and analyze |
| 1765 Source libBSource = _addSource("/libB.dart", "library libB;"); |
| 1766 _analyzeAll_assertFinished(); |
| 1767 expect( |
| 1768 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, |
| 1769 reason: "libA resolved 2"); |
| 1770 expect( |
| 1771 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, |
| 1772 reason: "libB resolved 2"); |
| 1773 expect(!_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), |
| 1774 isTrue, |
| 1775 reason: "libA doesn't have errors"); |
| 1776 } |
| 1777 |
| 1778 void test_performAnalysisTask_importedLibraryAdd_html() { |
| 1779 Source htmlSource = _addSource( |
| 1780 "/page.html", |
| 1781 r''' |
| 1782 <html><body><script type="application/dart"> |
| 1783 import '/libB.dart'; |
| 1784 main() {print('hello dart');} |
| 1785 </script></body></html>'''); |
| 1786 _analyzeAll_assertFinished(); |
| 1787 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, |
| 1788 reason: "htmlUnit resolved 1"); |
| 1789 expect(_hasAnalysisErrorWithErrorSeverity(_context.getErrors(htmlSource)), |
| 1790 isTrue, |
| 1791 reason: "htmlSource has an error"); |
| 1792 // add libB.dart and analyze |
| 1793 Source libBSource = _addSource("/libB.dart", "library libB;"); |
| 1794 _analyzeAll_assertFinished(); |
| 1795 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, |
| 1796 reason: "htmlUnit resolved 1"); |
| 1797 expect( |
| 1798 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, |
| 1799 reason: "libB resolved 2"); |
| 1800 // TODO (danrubel) commented out to fix red bots |
| 1801 // AnalysisErrorInfo errors = _context.getErrors(htmlSource); |
| 1802 // expect( |
| 1803 // !_hasAnalysisErrorWithErrorSeverity(errors), |
| 1804 // isTrue, |
| 1805 // reason: "htmlSource doesn't have errors"); |
| 1806 } |
| 1807 |
| 1808 void test_performAnalysisTask_importedLibraryDelete() { |
| 1809 Source libASource = |
| 1810 _addSource("/libA.dart", "library libA; import 'libB.dart';"); |
| 1811 Source libBSource = _addSource("/libB.dart", "library libB;"); |
| 1812 _analyzeAll_assertFinished(); |
| 1813 expect( |
| 1814 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, |
| 1815 reason: "libA resolved 1"); |
| 1816 expect( |
| 1817 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, |
| 1818 reason: "libB resolved 1"); |
| 1819 expect(!_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), |
| 1820 isTrue, |
| 1821 reason: "libA doesn't have errors"); |
| 1822 // remove libB.dart content and analyze |
| 1823 _context.setContents(libBSource, null); |
| 1824 _analyzeAll_assertFinished(); |
| 1825 expect( |
| 1826 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, |
| 1827 reason: "libA resolved 2"); |
| 1828 expect(_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), |
| 1829 isTrue, |
| 1830 reason: "libA has an error"); |
| 1831 } |
| 1832 |
| 1833 void test_performAnalysisTask_IOException() { |
| 1834 TestSource source = _addSourceWithException2("/test.dart", "library test;"); |
| 1835 int oldTimestamp = _context.getModificationStamp(source); |
| 1836 source.generateExceptionOnRead = false; |
| 1837 _analyzeAll_assertFinished(); |
| 1838 expect(source.readCount, 1); |
| 1839 source.generateExceptionOnRead = true; |
| 1840 do { |
| 1841 _changeSource(source, ""); |
| 1842 // Ensure that the timestamp differs, |
| 1843 // so that analysis engine notices the change |
| 1844 } while (oldTimestamp == _context.getModificationStamp(source)); |
| 1845 _analyzeAll_assertFinished(); |
| 1846 expect(source.readCount, 2); |
| 1847 } |
| 1848 |
| 1849 void test_performAnalysisTask_missingPart() { |
| 1850 Source source = |
| 1851 _addSource("/test.dart", "library lib; part 'no-such-file.dart';"); |
| 1852 _analyzeAll_assertFinished(); |
| 1853 expect(_context.getLibraryElement(source), isNotNull, |
| 1854 reason: "performAnalysisTask failed to compute an element model"); |
| 1855 } |
| 1856 |
| 1857 void test_performAnalysisTask_modifiedAfterParse() { |
| 1858 // TODO(scheglov) no threads in Dart |
| 1859 // Source source = _addSource("/test.dart", "library lib;"); |
| 1860 // int initialTime = _context.getModificationStamp(source); |
| 1861 // List<Source> sources = new List<Source>(); |
| 1862 // sources.add(source); |
| 1863 // _context.analysisPriorityOrder = sources; |
| 1864 // _context.parseCompilationUnit(source); |
| 1865 // while (initialTime == JavaSystem.currentTimeMillis()) { |
| 1866 // Thread.sleep(1); |
| 1867 // // Force the modification time to be different. |
| 1868 // } |
| 1869 // _context.setContents(source, "library test;"); |
| 1870 // JUnitTestCase.assertTrue(initialTime != _context.getModificationStamp(sour
ce)); |
| 1871 // _analyzeAll_assertFinished(); |
| 1872 // JUnitTestCase.assertNotNullMsg("performAnalysisTask failed to compute an e
lement model", _context.getLibraryElement(source)); |
| 1873 } |
| 1874 |
| 1875 void test_resolveCompilationUnit_import_relative() { |
| 1876 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1877 Source sourceA = |
| 1878 _addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}"); |
| 1879 _addSource("/libB.dart", "library libB; class B{}"); |
| 1880 CompilationUnit compilationUnit = |
| 1881 _context.resolveCompilationUnit2(sourceA, sourceA); |
| 1882 LibraryElement library = compilationUnit.element.library; |
| 1883 List<LibraryElement> importedLibraries = library.importedLibraries; |
| 1884 assertNamedElements(importedLibraries, ["dart.core", "libB"]); |
| 1885 List<LibraryElement> visibleLibraries = library.visibleLibraries; |
| 1886 assertNamedElements(visibleLibraries, ["dart.core", "libA", "libB"]); |
| 1887 } |
| 1888 |
| 1889 void test_resolveCompilationUnit_import_relative_cyclic() { |
| 1890 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1891 Source sourceA = |
| 1892 _addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}"); |
| 1893 _addSource("/libB.dart", "library libB; import 'libA.dart'; class B{}"); |
| 1894 CompilationUnit compilationUnit = |
| 1895 _context.resolveCompilationUnit2(sourceA, sourceA); |
| 1896 LibraryElement library = compilationUnit.element.library; |
| 1897 List<LibraryElement> importedLibraries = library.importedLibraries; |
| 1898 assertNamedElements(importedLibraries, ["dart.core", "libB"]); |
| 1899 List<LibraryElement> visibleLibraries = library.visibleLibraries; |
| 1900 assertNamedElements(visibleLibraries, ["dart.core", "libA", "libB"]); |
| 1901 } |
| 1902 |
| 1903 void test_resolveCompilationUnit_library() { |
| 1904 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1905 _sourceFactory = _context.sourceFactory; |
| 1906 Source source = _addSource("/lib.dart", "library lib;"); |
| 1907 LibraryElement library = _context.computeLibraryElement(source); |
| 1908 CompilationUnit compilationUnit = |
| 1909 _context.resolveCompilationUnit(source, library); |
| 1910 expect(compilationUnit, isNotNull); |
| 1911 expect(compilationUnit.element, isNotNull); |
| 1912 } |
| 1913 |
| 1914 void test_resolveCompilationUnit_source() { |
| 1915 _context = AnalysisContextFactory.oldContextWithCore(); |
| 1916 _sourceFactory = _context.sourceFactory; |
| 1917 Source source = _addSource("/lib.dart", "library lib;"); |
| 1918 CompilationUnit compilationUnit = |
| 1919 _context.resolveCompilationUnit2(source, source); |
| 1920 expect(compilationUnit, isNotNull); |
| 1921 } |
| 1922 |
| 1923 void test_resolveCompilationUnit_sourceChangeDuringResolution() { |
| 1924 _context = new _AnalysisContext_sourceChangeDuringResolution(); |
| 1925 AnalysisContextFactory.initContextWithCore(_context); |
| 1926 _sourceFactory = _context.sourceFactory; |
| 1927 Source source = _addSource("/lib.dart", "library lib;"); |
| 1928 CompilationUnit compilationUnit = |
| 1929 _context.resolveCompilationUnit2(source, source); |
| 1930 expect(compilationUnit, isNotNull); |
| 1931 expect(_context.getLineInfo(source), isNotNull); |
| 1932 } |
| 1933 |
| 1934 void test_resolveHtmlUnit() { |
| 1935 Source source = _addSource("/lib.html", "<html></html>"); |
| 1936 ht.HtmlUnit unit = _context.resolveHtmlUnit(source); |
| 1937 expect(unit, isNotNull); |
| 1938 } |
| 1939 |
| 1940 void test_setAnalysisOptions() { |
| 1941 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 1942 options.cacheSize = 42; |
| 1943 options.dart2jsHint = false; |
| 1944 options.hint = false; |
| 1945 _context.analysisOptions = options; |
| 1946 AnalysisOptions result = _context.analysisOptions; |
| 1947 expect(result.cacheSize, options.cacheSize); |
| 1948 expect(result.dart2jsHint, options.dart2jsHint); |
| 1949 expect(result.hint, options.hint); |
| 1950 } |
| 1951 |
| 1952 void test_setAnalysisOptions_reduceAnalysisPriorityOrder() { |
| 1953 AnalysisOptionsImpl options = |
| 1954 new AnalysisOptionsImpl.from(_context.analysisOptions); |
| 1955 List<Source> sources = new List<Source>(); |
| 1956 for (int index = 0; index < options.cacheSize; index++) { |
| 1957 sources.add(_addSource("/lib.dart$index", "")); |
| 1958 } |
| 1959 _context.analysisPriorityOrder = sources; |
| 1960 int oldPriorityOrderSize = _getPriorityOrder(_context).length; |
| 1961 options.cacheSize = options.cacheSize - 10; |
| 1962 _context.analysisOptions = options; |
| 1963 expect(oldPriorityOrderSize > _getPriorityOrder(_context).length, isTrue); |
| 1964 } |
| 1965 |
| 1966 void test_setAnalysisPriorityOrder_empty() { |
| 1967 _context.analysisPriorityOrder = new List<Source>(); |
| 1968 } |
| 1969 |
| 1970 void test_setAnalysisPriorityOrder_lessThanCacheSize() { |
| 1971 AnalysisOptions options = _context.analysisOptions; |
| 1972 List<Source> sources = new List<Source>(); |
| 1973 for (int index = 0; index < options.cacheSize; index++) { |
| 1974 sources.add(_addSource("/lib.dart$index", "")); |
| 1975 } |
| 1976 _context.analysisPriorityOrder = sources; |
| 1977 expect(options.cacheSize > _getPriorityOrder(_context).length, isTrue); |
| 1978 } |
| 1979 |
| 1980 void test_setAnalysisPriorityOrder_nonEmpty() { |
| 1981 List<Source> sources = new List<Source>(); |
| 1982 sources.add(_addSource("/lib.dart", "library lib;")); |
| 1983 _context.analysisPriorityOrder = sources; |
| 1984 } |
| 1985 |
| 1986 Future test_setChangedContents_libraryWithPart() { |
| 1987 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 1988 options.incremental = true; |
| 1989 _context = AnalysisContextFactory.oldContextWithCoreAndOptions(options); |
| 1990 SourcesChangedListener listener = new SourcesChangedListener(); |
| 1991 _context.onSourcesChanged.listen(listener.onData); |
| 1992 _sourceFactory = _context.sourceFactory; |
| 1993 String oldCode = r''' |
| 1994 library lib; |
| 1995 part 'part.dart'; |
| 1996 int a = 0;'''; |
| 1997 Source librarySource = _addSource("/lib.dart", oldCode); |
| 1998 String partContents = r''' |
| 1999 part of lib; |
| 2000 int b = a;'''; |
| 2001 Source partSource = _addSource("/part.dart", partContents); |
| 2002 LibraryElement element = _context.computeLibraryElement(librarySource); |
| 2003 CompilationUnit unit = |
| 2004 _context.getResolvedCompilationUnit(librarySource, element); |
| 2005 expect(unit, isNotNull); |
| 2006 int offset = oldCode.indexOf("int a") + 4; |
| 2007 String newCode = r''' |
| 2008 library lib; |
| 2009 part 'part.dart'; |
| 2010 int ya = 0;'''; |
| 2011 expect(_getIncrementalAnalysisCache(_context), isNull); |
| 2012 _context.setChangedContents(librarySource, newCode, offset, 0, 1); |
| 2013 expect(_context.getContents(librarySource).data, newCode); |
| 2014 IncrementalAnalysisCache incrementalCache = |
| 2015 _getIncrementalAnalysisCache(_context); |
| 2016 expect(incrementalCache.librarySource, librarySource); |
| 2017 expect(incrementalCache.resolvedUnit, same(unit)); |
| 2018 expect(_context.getResolvedCompilationUnit2(partSource, librarySource), |
| 2019 isNull); |
| 2020 expect(incrementalCache.newContents, newCode); |
| 2021 return pumpEventQueue().then((_) { |
| 2022 listener.assertEvent(wereSourcesAdded: true); |
| 2023 listener.assertEvent(changedSources: [librarySource]); |
| 2024 listener.assertEvent(wereSourcesAdded: true); |
| 2025 listener.assertEvent(changedSources: [partSource]); |
| 2026 listener.assertEvent(changedSources: [librarySource]); |
| 2027 listener.assertNoMoreEvents(); |
| 2028 }); |
| 2029 } |
| 2030 |
| 2031 void test_setChangedContents_notResolved() { |
| 2032 _context = AnalysisContextFactory.oldContextWithCore(); |
| 2033 AnalysisOptionsImpl options = |
| 2034 new AnalysisOptionsImpl.from(_context.analysisOptions); |
| 2035 options.incremental = true; |
| 2036 _context.analysisOptions = options; |
| 2037 _sourceFactory = _context.sourceFactory; |
| 2038 String oldCode = r''' |
| 2039 library lib; |
| 2040 int a = 0;'''; |
| 2041 Source librarySource = _addSource("/lib.dart", oldCode); |
| 2042 int offset = oldCode.indexOf("int a") + 4; |
| 2043 String newCode = r''' |
| 2044 library lib; |
| 2045 int ya = 0;'''; |
| 2046 _context.setChangedContents(librarySource, newCode, offset, 0, 1); |
| 2047 expect(_context.getContents(librarySource).data, newCode); |
| 2048 expect(_getIncrementalAnalysisCache(_context), isNull); |
| 2049 } |
| 2050 |
| 2051 Future test_setContents_libraryWithPart() { |
| 2052 _context = AnalysisContextFactory.oldContextWithCore(); |
| 2053 SourcesChangedListener listener = new SourcesChangedListener(); |
| 2054 _context.onSourcesChanged.listen(listener.onData); |
| 2055 _sourceFactory = _context.sourceFactory; |
| 2056 String libraryContents1 = r''' |
| 2057 library lib; |
| 2058 part 'part.dart'; |
| 2059 int a = 0;'''; |
| 2060 Source librarySource = _addSource("/lib.dart", libraryContents1); |
| 2061 String partContents1 = r''' |
| 2062 part of lib; |
| 2063 int b = a;'''; |
| 2064 Source partSource = _addSource("/part.dart", partContents1); |
| 2065 _context.computeLibraryElement(librarySource); |
| 2066 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache( |
| 2067 librarySource, librarySource, null, null, null, 0, 0, 0); |
| 2068 _setIncrementalAnalysisCache(_context, incrementalCache); |
| 2069 expect(_getIncrementalAnalysisCache(_context), same(incrementalCache)); |
| 2070 String libraryContents2 = r''' |
| 2071 library lib; |
| 2072 part 'part.dart'; |
| 2073 int aa = 0;'''; |
| 2074 _context.setContents(librarySource, libraryContents2); |
| 2075 expect(_context.getResolvedCompilationUnit2(partSource, librarySource), |
| 2076 isNull); |
| 2077 expect(_getIncrementalAnalysisCache(_context), isNull); |
| 2078 return pumpEventQueue().then((_) { |
| 2079 listener.assertEvent(wereSourcesAdded: true); |
| 2080 listener.assertEvent(changedSources: [librarySource]); |
| 2081 listener.assertEvent(wereSourcesAdded: true); |
| 2082 listener.assertEvent(changedSources: [partSource]); |
| 2083 listener.assertEvent(changedSources: [librarySource]); |
| 2084 listener.assertNoMoreEvents(); |
| 2085 }); |
| 2086 } |
| 2087 |
| 2088 void test_setContents_null() { |
| 2089 _context = AnalysisContextFactory.oldContextWithCore(); |
| 2090 _sourceFactory = _context.sourceFactory; |
| 2091 Source librarySource = _addSource( |
| 2092 "/lib.dart", |
| 2093 r''' |
| 2094 library lib; |
| 2095 int a = 0;'''); |
| 2096 _context.computeLibraryElement(librarySource); |
| 2097 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache( |
| 2098 librarySource, librarySource, null, null, null, 0, 0, 0); |
| 2099 _setIncrementalAnalysisCache(_context, incrementalCache); |
| 2100 expect(_getIncrementalAnalysisCache(_context), same(incrementalCache)); |
| 2101 _context.setContents(librarySource, null); |
| 2102 expect(_context.getResolvedCompilationUnit2(librarySource, librarySource), |
| 2103 isNull); |
| 2104 expect(_getIncrementalAnalysisCache(_context), isNull); |
| 2105 } |
| 2106 |
| 2107 void test_setContents_unchanged_consistentModificationTime() { |
| 2108 String contents = "// foo"; |
| 2109 Source source = _addSource("/test.dart", contents); |
| 2110 // do all, no tasks |
| 2111 _analyzeAll_assertFinished(); |
| 2112 { |
| 2113 AnalysisResult result = _context.performAnalysisTask(); |
| 2114 expect(result.changeNotices, isNull); |
| 2115 } |
| 2116 // set the same contents, still no tasks |
| 2117 _context.setContents(source, contents); |
| 2118 { |
| 2119 AnalysisResult result = _context.performAnalysisTask(); |
| 2120 expect(result.changeNotices, isNull); |
| 2121 } |
| 2122 } |
| 2123 |
| 2124 void test_setSourceFactory() { |
| 2125 expect(_context.sourceFactory, _sourceFactory); |
| 2126 SourceFactory factory = new SourceFactory([]); |
| 2127 _context.sourceFactory = factory; |
| 2128 expect(_context.sourceFactory, factory); |
| 2129 } |
| 2130 |
| 2131 void test_unreadableSource() { |
| 2132 _context = AnalysisContextFactory.oldContextWithCore(); |
| 2133 _sourceFactory = _context.sourceFactory; |
| 2134 Source test1 = _addSource( |
| 2135 "/test1.dart", |
| 2136 r''' |
| 2137 import 'test2.dart'; |
| 2138 library test1;'''); |
| 2139 Source test2 = _addSource( |
| 2140 "/test2.dart", |
| 2141 r''' |
| 2142 import 'test1.dart'; |
| 2143 import 'test3.dart'; |
| 2144 library test2;'''); |
| 2145 Source test3 = _addSourceWithException("/test3.dart"); |
| 2146 _analyzeAll_assertFinished(); |
| 2147 // test1 and test2 should have been successfully analyzed |
| 2148 // despite the fact that test3 couldn't be read. |
| 2149 expect(_context.computeLibraryElement(test1), isNotNull); |
| 2150 expect(_context.computeLibraryElement(test2), isNotNull); |
| 2151 expect(_context.computeLibraryElement(test3), isNull); |
| 2152 } |
| 2153 |
| 2154 void test_updateAnalysis() { |
| 2155 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); |
| 2156 Source source = |
| 2157 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 2158 AnalysisDelta delta = new AnalysisDelta(); |
| 2159 delta.setAnalysisLevel(source, AnalysisLevel.ALL); |
| 2160 _context.applyAnalysisDelta(delta); |
| 2161 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); |
| 2162 delta = new AnalysisDelta(); |
| 2163 delta.setAnalysisLevel(source, AnalysisLevel.NONE); |
| 2164 _context.applyAnalysisDelta(delta); |
| 2165 expect(_context.sourcesNeedingProcessing.contains(source), isFalse); |
| 2166 } |
| 2167 |
| 2168 void xtest_performAnalysisTask_stress() { |
| 2169 int maxCacheSize = 4; |
| 2170 AnalysisOptionsImpl options = |
| 2171 new AnalysisOptionsImpl.from(_context.analysisOptions); |
| 2172 options.cacheSize = maxCacheSize; |
| 2173 _context.analysisOptions = options; |
| 2174 int sourceCount = maxCacheSize + 2; |
| 2175 List<Source> sources = new List<Source>(); |
| 2176 ChangeSet changeSet = new ChangeSet(); |
| 2177 for (int i = 0; i < sourceCount; i++) { |
| 2178 Source source = _addSource("/lib$i.dart", "library lib$i;"); |
| 2179 sources.add(source); |
| 2180 changeSet.addedSource(source); |
| 2181 } |
| 2182 _context.applyChanges(changeSet); |
| 2183 _context.analysisPriorityOrder = sources; |
| 2184 for (int i = 0; i < 1000; i++) { |
| 2185 List<ChangeNotice> notice = _context.performAnalysisTask().changeNotices; |
| 2186 if (notice == null) { |
| 2187 //System.out.println("test_performAnalysisTask_stress: " + i); |
| 2188 break; |
| 2189 } |
| 2190 } |
| 2191 List<ChangeNotice> notice = _context.performAnalysisTask().changeNotices; |
| 2192 if (notice != null) { |
| 2193 fail( |
| 2194 "performAnalysisTask failed to terminate after analyzing all sources")
; |
| 2195 } |
| 2196 } |
| 2197 |
| 2198 Source _addSource(String fileName, String contents) { |
| 2199 Source source = new FileBasedSource(FileUtilities2.createFile(fileName)); |
| 2200 ChangeSet changeSet = new ChangeSet(); |
| 2201 changeSet.addedSource(source); |
| 2202 _context.applyChanges(changeSet); |
| 2203 _context.setContents(source, contents); |
| 2204 return source; |
| 2205 } |
| 2206 |
| 2207 TestSource _addSourceWithException(String fileName) { |
| 2208 return _addSourceWithException2(fileName, ""); |
| 2209 } |
| 2210 |
| 2211 TestSource _addSourceWithException2(String fileName, String contents) { |
| 2212 TestSource source = new TestSource(fileName, contents); |
| 2213 source.generateExceptionOnRead = true; |
| 2214 ChangeSet changeSet = new ChangeSet(); |
| 2215 changeSet.addedSource(source); |
| 2216 _context.applyChanges(changeSet); |
| 2217 return source; |
| 2218 } |
| 2219 |
| 2220 /** |
| 2221 * Perform analysis tasks up to 512 times and asserts that that was enough. |
| 2222 */ |
| 2223 void _analyzeAll_assertFinished() { |
| 2224 _analyzeAll_assertFinished2(512); |
| 2225 } |
| 2226 |
| 2227 /** |
| 2228 * Perform analysis tasks up to the given number of times and asserts that tha
t was enough. |
| 2229 * |
| 2230 * @param maxIterations the maximum number of tasks to perform |
| 2231 */ |
| 2232 void _analyzeAll_assertFinished2(int maxIterations) { |
| 2233 for (int i = 0; i < maxIterations; i++) { |
| 2234 List<ChangeNotice> notice = _context.performAnalysisTask().changeNotices; |
| 2235 if (notice == null) { |
| 2236 return; |
| 2237 } |
| 2238 } |
| 2239 fail("performAnalysisTask failed to terminate after analyzing all sources"); |
| 2240 } |
| 2241 |
| 2242 void _changeSource(TestSource source, String contents) { |
| 2243 source.setContents(contents); |
| 2244 ChangeSet changeSet = new ChangeSet(); |
| 2245 changeSet.changedSource(source); |
| 2246 _context.applyChanges(changeSet); |
| 2247 } |
| 2248 |
| 2249 Source _createSource(String fileName, String contents) { |
| 2250 Source source = new FileBasedSource(FileUtilities2.createFile(fileName)); |
| 2251 _context.setContents(source, contents); |
| 2252 return source; |
| 2253 } |
| 2254 |
| 2255 /** |
| 2256 * Search the given compilation unit for a class with the given name. Return t
he class with the |
| 2257 * given name, or `null` if the class cannot be found. |
| 2258 * |
| 2259 * @param unit the compilation unit being searched |
| 2260 * @param className the name of the class being searched for |
| 2261 * @return the class with the given name |
| 2262 */ |
| 2263 ClassElement _findClass(CompilationUnitElement unit, String className) { |
| 2264 for (ClassElement classElement in unit.types) { |
| 2265 if (classElement.displayName == className) { |
| 2266 return classElement; |
| 2267 } |
| 2268 } |
| 2269 return null; |
| 2270 } |
| 2271 |
| 2272 IncrementalAnalysisCache _getIncrementalAnalysisCache( |
| 2273 AnalysisContextImpl context2) { |
| 2274 return context2.test_incrementalAnalysisCache; |
| 2275 } |
| 2276 |
| 2277 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { |
| 2278 return context2.test_priorityOrder; |
| 2279 } |
| 2280 |
| 2281 void _performPendingAnalysisTasks([int maxTasks = 20]) { |
| 2282 for (int i = 0; _context.performAnalysisTask().hasMoreWork; i++) { |
| 2283 if (i > maxTasks) { |
| 2284 fail('Analysis did not terminate.'); |
| 2285 } |
| 2286 } |
| 2287 } |
| 2288 |
| 2289 void _removeSource(Source source) { |
| 2290 ChangeSet changeSet = new ChangeSet(); |
| 2291 changeSet.removedSource(source); |
| 2292 _context.applyChanges(changeSet); |
| 2293 } |
| 2294 |
| 2295 void _setIncrementalAnalysisCache( |
| 2296 AnalysisContextImpl context, IncrementalAnalysisCache incrementalCache) { |
| 2297 context.test_incrementalAnalysisCache = incrementalCache; |
| 2298 } |
| 2299 |
| 2300 /** |
| 2301 * Returns `true` if there is an [AnalysisError] with [ErrorSeverity.ERROR] in |
| 2302 * the given [AnalysisErrorInfo]. |
| 2303 */ |
| 2304 static bool _hasAnalysisErrorWithErrorSeverity(AnalysisErrorInfo errorInfo) { |
| 2305 List<AnalysisError> errors = errorInfo.errors; |
| 2306 for (AnalysisError analysisError in errors) { |
| 2307 if (analysisError.errorCode.errorSeverity == ErrorSeverity.ERROR) { |
| 2308 return true; |
| 2309 } |
| 2310 } |
| 2311 return false; |
| 2312 } |
| 2313 } |
| 2314 |
| 2315 class AnalysisContextImplTest_Source_exists_true extends TestSource { |
| 2316 @override |
| 2317 bool exists() => true; |
| 2318 } |
| 2319 |
| 2320 class AnalysisContextImplTest_Source_getModificationStamp_fromSource |
| 2321 extends TestSource { |
| 2322 int stamp; |
| 2323 AnalysisContextImplTest_Source_getModificationStamp_fromSource(this.stamp); |
| 2324 @override |
| 2325 int get modificationStamp => stamp; |
| 2326 } |
| 2327 |
| 2328 class AnalysisContextImplTest_Source_getModificationStamp_overridden |
| 2329 extends TestSource { |
| 2330 int stamp; |
| 2331 AnalysisContextImplTest_Source_getModificationStamp_overridden(this.stamp); |
| 2332 @override |
| 2333 int get modificationStamp => stamp; |
| 2334 } |
| 2335 |
| 2336 @reflectiveTest |
| 2337 class AnalysisOptionsImplTest extends EngineTestCase { |
| 2338 void test_AnalysisOptionsImpl_copy() { |
| 2339 bool booleanValue = true; |
| 2340 for (int i = 0; i < 2; i++, booleanValue = !booleanValue) { |
| 2341 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2342 options.analyzeFunctionBodies = booleanValue; |
| 2343 options.cacheSize = i; |
| 2344 options.dart2jsHint = booleanValue; |
| 2345 options.enableStrictCallChecks = booleanValue; |
| 2346 options.enableSuperMixins = booleanValue; |
| 2347 options.generateImplicitErrors = booleanValue; |
| 2348 options.generateSdkErrors = booleanValue; |
| 2349 options.hint = booleanValue; |
| 2350 options.incremental = booleanValue; |
| 2351 options.preserveComments = booleanValue; |
| 2352 options.strongMode = booleanValue; |
| 2353 AnalysisOptionsImpl copy = new AnalysisOptionsImpl.from(options); |
| 2354 expect(copy.analyzeFunctionBodies, options.analyzeFunctionBodies); |
| 2355 expect(copy.cacheSize, options.cacheSize); |
| 2356 expect(copy.dart2jsHint, options.dart2jsHint); |
| 2357 expect(copy.enableStrictCallChecks, options.enableStrictCallChecks); |
| 2358 expect(copy.enableSuperMixins, options.enableSuperMixins); |
| 2359 expect(copy.generateImplicitErrors, options.generateImplicitErrors); |
| 2360 expect(copy.generateSdkErrors, options.generateSdkErrors); |
| 2361 expect(copy.hint, options.hint); |
| 2362 expect(copy.incremental, options.incremental); |
| 2363 expect(copy.preserveComments, options.preserveComments); |
| 2364 expect(copy.strongMode, options.strongMode); |
| 2365 } |
| 2366 } |
| 2367 |
| 2368 void test_analyzeFunctionBodies() { |
| 2369 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2370 bool value = !options.analyzeFunctionBodies; |
| 2371 options.analyzeFunctionBodies = value; |
| 2372 expect(options.analyzeFunctionBodies, value); |
| 2373 } |
| 2374 |
| 2375 void test_cacheSize() { |
| 2376 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2377 expect(options.cacheSize, AnalysisOptionsImpl.DEFAULT_CACHE_SIZE); |
| 2378 int value = options.cacheSize + 1; |
| 2379 options.cacheSize = value; |
| 2380 expect(options.cacheSize, value); |
| 2381 } |
| 2382 |
| 2383 void test_dart2jsHint() { |
| 2384 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2385 bool value = !options.dart2jsHint; |
| 2386 options.dart2jsHint = value; |
| 2387 expect(options.dart2jsHint, value); |
| 2388 } |
| 2389 |
| 2390 void test_enableSuperMixins() { |
| 2391 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2392 bool value = !options.enableSuperMixins; |
| 2393 options.enableSuperMixins = value; |
| 2394 expect(options.enableSuperMixins, value); |
| 2395 } |
| 2396 |
| 2397 void test_generateImplicitErrors() { |
| 2398 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2399 bool value = !options.generateImplicitErrors; |
| 2400 options.generateImplicitErrors = value; |
| 2401 expect(options.generateImplicitErrors, value); |
| 2402 } |
| 2403 |
| 2404 void test_generateSdkErrors() { |
| 2405 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2406 bool value = !options.generateSdkErrors; |
| 2407 options.generateSdkErrors = value; |
| 2408 expect(options.generateSdkErrors, value); |
| 2409 } |
| 2410 |
| 2411 void test_hint() { |
| 2412 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2413 bool value = !options.hint; |
| 2414 options.hint = value; |
| 2415 expect(options.hint, value); |
| 2416 } |
| 2417 |
| 2418 void test_incremental() { |
| 2419 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2420 bool value = !options.incremental; |
| 2421 options.incremental = value; |
| 2422 expect(options.incremental, value); |
| 2423 } |
| 2424 |
| 2425 void test_preserveComments() { |
| 2426 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2427 bool value = !options.preserveComments; |
| 2428 options.preserveComments = value; |
| 2429 expect(options.preserveComments, value); |
| 2430 } |
| 2431 |
| 2432 void test_strongMode() { |
| 2433 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2434 bool value = !options.strongMode; |
| 2435 options.strongMode = value; |
| 2436 expect(options.strongMode, value); |
| 2437 } |
| 2438 } |
| 2439 |
| 2440 class AnalysisTask_test_perform_exception extends AnalysisTask { |
| 2441 AnalysisTask_test_perform_exception(InternalAnalysisContext arg0) |
| 2442 : super(arg0); |
| 2443 @override |
| 2444 String get taskDescription => null; |
| 2445 @override |
| 2446 accept(AnalysisTaskVisitor visitor) { |
| 2447 expect(exception, isNotNull); |
| 2448 return null; |
| 2449 } |
| 2450 |
| 2451 @override |
| 2452 void internalPerform() { |
| 2453 throw new AnalysisException("Forced exception"); |
| 2454 } |
| 2455 } |
| 2456 |
| 2457 @reflectiveTest |
| 2458 class AnalysisTaskTest extends EngineTestCase { |
| 2459 void test_perform_exception() { |
| 2460 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 2461 AnalysisTask task = new AnalysisTask_test_perform_exception(context); |
| 2462 task.perform(new TestTaskVisitor<Object>()); |
| 2463 } |
| 2464 } |
| 2465 |
| 2466 /** |
| 2467 * A listener used to gather the [ImplicitAnalysisEvent]s that are produced |
| 2468 * during analysis. |
| 2469 */ |
| 2470 class AnalyzedSourcesListener { |
| 2471 /** |
| 2472 * The events that have been gathered. |
| 2473 */ |
| 2474 List<ImplicitAnalysisEvent> actualEvents = <ImplicitAnalysisEvent>[]; |
| 2475 |
| 2476 /** |
| 2477 * The sources that are being implicitly analyzed. |
| 2478 */ |
| 2479 List<Source> analyzedSources = <Source>[]; |
| 2480 |
| 2481 /** |
| 2482 * Assert that the given source is currently being implicitly analyzed. |
| 2483 */ |
| 2484 void expectAnalyzed(Source source) { |
| 2485 expect(analyzedSources, contains(source)); |
| 2486 } |
| 2487 |
| 2488 /** |
| 2489 * Assert that the given source is not currently being implicitly analyzed. |
| 2490 */ |
| 2491 void expectNotAnalyzed(Source source) { |
| 2492 expect(analyzedSources, isNot(contains(source))); |
| 2493 } |
| 2494 |
| 2495 /** |
| 2496 * Record that the given event was produced. |
| 2497 */ |
| 2498 void onData(ImplicitAnalysisEvent event) { |
| 2499 actualEvents.add(event); |
| 2500 if (event.isAnalyzed) { |
| 2501 analyzedSources.add(event.source); |
| 2502 } else { |
| 2503 analyzedSources.remove(event.source); |
| 2504 } |
| 2505 } |
| 2506 } |
| 2507 |
| 2508 class CompilationUnitMock extends TypedMock implements CompilationUnit { |
| 2509 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 2510 } |
| 2511 |
| 2512 @reflectiveTest |
| 2513 class DartEntryTest extends EngineTestCase { |
| 2514 void test_allErrors() { |
| 2515 Source source = new TestSource(); |
| 2516 DartEntry entry = new DartEntry(); |
| 2517 expect(entry.allErrors, hasLength(0)); |
| 2518 entry.setValue(SourceEntry.CONTENT_ERRORS, <AnalysisError>[ |
| 2519 new AnalysisError(source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, |
| 2520 ['exception details']) |
| 2521 ]); |
| 2522 entry.setValue(DartEntry.SCAN_ERRORS, <AnalysisError>[ |
| 2523 new AnalysisError( |
| 2524 source, 0, 0, ScannerErrorCode.UNTERMINATED_STRING_LITERAL) |
| 2525 ]); |
| 2526 entry.setValue(DartEntry.PARSE_ERRORS, <AnalysisError>[ |
| 2527 new AnalysisError(source, 0, 0, ParserErrorCode.ABSTRACT_CLASS_MEMBER) |
| 2528 ]); |
| 2529 entry.setValueInLibrary( |
| 2530 DartEntry.RESOLUTION_ERRORS, source, <AnalysisError>[ |
| 2531 new AnalysisError( |
| 2532 source, 0, 0, CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION) |
| 2533 ]); |
| 2534 entry.setValueInLibrary( |
| 2535 DartEntry.VERIFICATION_ERRORS, source, <AnalysisError>[ |
| 2536 new AnalysisError( |
| 2537 source, 0, 0, StaticWarningCode.CASE_BLOCK_NOT_TERMINATED) |
| 2538 ]); |
| 2539 entry.setValueInLibrary(DartEntry.HINTS, source, |
| 2540 <AnalysisError>[new AnalysisError(source, 0, 0, HintCode.DEAD_CODE)]); |
| 2541 expect(entry.allErrors, hasLength(6)); |
| 2542 } |
| 2543 |
| 2544 void test_creation() { |
| 2545 Source librarySource = new TestSource(); |
| 2546 DartEntry entry = new DartEntry(); |
| 2547 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.INVALID)); |
| 2548 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.INVALID)); |
| 2549 expect(entry.getState(DartEntry.CONTAINING_LIBRARIES), |
| 2550 same(CacheState.INVALID)); |
| 2551 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.INVALID)); |
| 2552 expect( |
| 2553 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.INVALID)); |
| 2554 expect( |
| 2555 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.INVALID)); |
| 2556 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.INVALID)); |
| 2557 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.INVALID)); |
| 2558 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.INVALID)); |
| 2559 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.INVALID)); |
| 2560 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.INVALID)); |
| 2561 expect( |
| 2562 entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.INVALID)); |
| 2563 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.INVALID)); |
| 2564 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.INVALID)); |
| 2565 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.INVALID)); |
| 2566 |
| 2567 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, librarySource), |
| 2568 same(CacheState.INVALID)); |
| 2569 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, librarySource), |
| 2570 same(CacheState.INVALID)); |
| 2571 expect(entry.getStateInLibrary(DartEntry.HINTS, librarySource), |
| 2572 same(CacheState.INVALID)); |
| 2573 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, librarySource), |
| 2574 same(CacheState.INVALID)); |
| 2575 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource), |
| 2576 same(CacheState.INVALID)); |
| 2577 expect( |
| 2578 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource), |
| 2579 same(CacheState.INVALID)); |
| 2580 } |
| 2581 |
| 2582 void test_getResolvableCompilationUnit_none() { |
| 2583 DartEntry entry = new DartEntry(); |
| 2584 expect(entry.resolvableCompilationUnit, isNull); |
| 2585 } |
| 2586 |
| 2587 void test_getResolvableCompilationUnit_parsed_accessed() { |
| 2588 Source librarySource = new TestSource("/lib.dart"); |
| 2589 String importUri = "/f1.dart"; |
| 2590 Source importSource = new TestSource(importUri); |
| 2591 ImportDirective importDirective = |
| 2592 AstFactory.importDirective3(importUri, null); |
| 2593 importDirective.source = importSource; |
| 2594 importDirective.uriContent = importUri; |
| 2595 String exportUri = "/f2.dart"; |
| 2596 Source exportSource = new TestSource(exportUri); |
| 2597 ExportDirective exportDirective = AstFactory.exportDirective2(exportUri); |
| 2598 exportDirective.source = exportSource; |
| 2599 exportDirective.uriContent = exportUri; |
| 2600 String partUri = "/f3.dart"; |
| 2601 Source partSource = new TestSource(partUri); |
| 2602 PartDirective partDirective = AstFactory.partDirective2(partUri); |
| 2603 partDirective.source = partSource; |
| 2604 partDirective.uriContent = partUri; |
| 2605 CompilationUnit unit = AstFactory |
| 2606 .compilationUnit3([importDirective, exportDirective, partDirective]); |
| 2607 DartEntry entry = new DartEntry(); |
| 2608 entry.setValue(DartEntry.PARSED_UNIT, unit); |
| 2609 entry.getValue(DartEntry.PARSED_UNIT); |
| 2610 CompilationUnit result = entry.resolvableCompilationUnit; |
| 2611 expect(result, same(unit)); |
| 2612 entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource, unit); |
| 2613 result = entry.resolvableCompilationUnit; |
| 2614 expect(result, isNot(same(unit))); |
| 2615 NodeList<Directive> directives = result.directives; |
| 2616 ImportDirective resultImportDirective = directives[0] as ImportDirective; |
| 2617 expect(resultImportDirective.uriContent, importUri); |
| 2618 expect(resultImportDirective.source, same(importSource)); |
| 2619 ExportDirective resultExportDirective = directives[1] as ExportDirective; |
| 2620 expect(resultExportDirective.uriContent, exportUri); |
| 2621 expect(resultExportDirective.source, same(exportSource)); |
| 2622 PartDirective resultPartDirective = directives[2] as PartDirective; |
| 2623 expect(resultPartDirective.uriContent, partUri); |
| 2624 expect(resultPartDirective.source, same(partSource)); |
| 2625 } |
| 2626 |
| 2627 void test_getResolvableCompilationUnit_parsed_notAccessed() { |
| 2628 CompilationUnit unit = AstFactory.compilationUnit(); |
| 2629 DartEntry entry = new DartEntry(); |
| 2630 entry.setValue(DartEntry.PARSED_UNIT, unit); |
| 2631 expect(entry.resolvableCompilationUnit, same(unit)); |
| 2632 } |
| 2633 |
| 2634 void test_getResolvableCompilationUnit_resolved() { |
| 2635 String importUri = "f1.dart"; |
| 2636 Source importSource = new TestSource(importUri); |
| 2637 ImportDirective importDirective = |
| 2638 AstFactory.importDirective3(importUri, null); |
| 2639 importDirective.source = importSource; |
| 2640 importDirective.uriContent = importUri; |
| 2641 String exportUri = "f2.dart"; |
| 2642 Source exportSource = new TestSource(exportUri); |
| 2643 ExportDirective exportDirective = AstFactory.exportDirective2(exportUri); |
| 2644 exportDirective.source = exportSource; |
| 2645 exportDirective.uriContent = exportUri; |
| 2646 String partUri = "f3.dart"; |
| 2647 Source partSource = new TestSource(partUri); |
| 2648 PartDirective partDirective = AstFactory.partDirective2(partUri); |
| 2649 partDirective.source = partSource; |
| 2650 partDirective.uriContent = partUri; |
| 2651 CompilationUnit unit = AstFactory |
| 2652 .compilationUnit3([importDirective, exportDirective, partDirective]); |
| 2653 DartEntry entry = new DartEntry(); |
| 2654 entry.setValueInLibrary( |
| 2655 DartEntry.RESOLVED_UNIT, new TestSource("lib.dart"), unit); |
| 2656 CompilationUnit result = entry.resolvableCompilationUnit; |
| 2657 expect(result, isNot(same(unit))); |
| 2658 NodeList<Directive> directives = result.directives; |
| 2659 ImportDirective resultImportDirective = directives[0] as ImportDirective; |
| 2660 expect(resultImportDirective.uriContent, importUri); |
| 2661 expect(resultImportDirective.source, same(importSource)); |
| 2662 ExportDirective resultExportDirective = directives[1] as ExportDirective; |
| 2663 expect(resultExportDirective.uriContent, exportUri); |
| 2664 expect(resultExportDirective.source, same(exportSource)); |
| 2665 PartDirective resultPartDirective = directives[2] as PartDirective; |
| 2666 expect(resultPartDirective.uriContent, partUri); |
| 2667 expect(resultPartDirective.source, same(partSource)); |
| 2668 } |
| 2669 |
| 2670 void test_getState_invalid_resolutionErrors() { |
| 2671 DartEntry entry = new DartEntry(); |
| 2672 try { |
| 2673 entry.getState(DartEntry.RESOLUTION_ERRORS); |
| 2674 fail("Expected ArgumentError for RESOLUTION_ERRORS"); |
| 2675 } on ArgumentError { |
| 2676 // Expected |
| 2677 } |
| 2678 } |
| 2679 |
| 2680 void test_getState_invalid_verificationErrors() { |
| 2681 DartEntry entry = new DartEntry(); |
| 2682 try { |
| 2683 entry.getState(DartEntry.VERIFICATION_ERRORS); |
| 2684 fail("Expected ArgumentError for VERIFICATION_ERRORS"); |
| 2685 } on ArgumentError { |
| 2686 // Expected |
| 2687 } |
| 2688 } |
| 2689 |
| 2690 void test_getStateInLibrary_invalid_element() { |
| 2691 DartEntry entry = new DartEntry(); |
| 2692 try { |
| 2693 entry.getStateInLibrary(DartEntry.ELEMENT, new TestSource()); |
| 2694 fail("Expected ArgumentError for ELEMENT"); |
| 2695 } on ArgumentError { |
| 2696 // Expected |
| 2697 } |
| 2698 } |
| 2699 |
| 2700 void test_getValue_containingLibraries() { |
| 2701 Source testSource = new TestSource(); |
| 2702 DartEntry entry = new DartEntry(); |
| 2703 List<Source> value = entry.containingLibraries; |
| 2704 expect(value, hasLength(0)); |
| 2705 entry.addContainingLibrary(testSource); |
| 2706 value = entry.containingLibraries; |
| 2707 expect(value, hasLength(1)); |
| 2708 expect(value[0], testSource); |
| 2709 entry.removeContainingLibrary(testSource); |
| 2710 value = entry.containingLibraries; |
| 2711 expect(value, hasLength(0)); |
| 2712 } |
| 2713 |
| 2714 void test_getValue_invalid_resolutionErrors() { |
| 2715 DartEntry entry = new DartEntry(); |
| 2716 try { |
| 2717 entry.getValue(DartEntry.RESOLUTION_ERRORS); |
| 2718 fail("Expected ArgumentError for RESOLUTION_ERRORS"); |
| 2719 } on ArgumentError {} |
| 2720 } |
| 2721 |
| 2722 void test_getValue_invalid_verificationErrors() { |
| 2723 DartEntry entry = new DartEntry(); |
| 2724 try { |
| 2725 entry.getValue(DartEntry.VERIFICATION_ERRORS); |
| 2726 fail("Expected ArgumentError for VERIFICATION_ERRORS"); |
| 2727 } on ArgumentError { |
| 2728 // Expected |
| 2729 } |
| 2730 } |
| 2731 |
| 2732 void test_getValueInLibrary_invalid_element() { |
| 2733 DartEntry entry = new DartEntry(); |
| 2734 try { |
| 2735 entry.getValueInLibrary(DartEntry.ELEMENT, new TestSource()); |
| 2736 fail("Expected ArgumentError for ELEMENT"); |
| 2737 } on ArgumentError { |
| 2738 // Expected |
| 2739 } |
| 2740 } |
| 2741 |
| 2742 void test_getValueInLibrary_invalid_resolutionErrors_multiple() { |
| 2743 Source source1 = new TestSource(); |
| 2744 Source source2 = new TestSource(); |
| 2745 Source source3 = new TestSource(); |
| 2746 DartEntry entry = new DartEntry(); |
| 2747 entry.setValueInLibrary( |
| 2748 DartEntry.RESOLVED_UNIT, source1, AstFactory.compilationUnit()); |
| 2749 entry.setValueInLibrary( |
| 2750 DartEntry.RESOLVED_UNIT, source2, AstFactory.compilationUnit()); |
| 2751 entry.setValueInLibrary( |
| 2752 DartEntry.RESOLVED_UNIT, source3, AstFactory.compilationUnit()); |
| 2753 try { |
| 2754 entry.getValueInLibrary(DartEntry.ELEMENT, source3); |
| 2755 fail("Expected ArgumentError for ELEMENT"); |
| 2756 } on ArgumentError { |
| 2757 // Expected |
| 2758 } |
| 2759 } |
| 2760 |
| 2761 void test_hasInvalidData_false() { |
| 2762 DartEntry entry = new DartEntry(); |
| 2763 entry.recordScanError(new CaughtException(new AnalysisException(), null)); |
| 2764 expect(entry.hasInvalidData(DartEntry.ELEMENT), isFalse); |
| 2765 expect(entry.hasInvalidData(DartEntry.EXPORTED_LIBRARIES), isFalse); |
| 2766 expect(entry.hasInvalidData(DartEntry.HINTS), isFalse); |
| 2767 expect(entry.hasInvalidData(DartEntry.IMPORTED_LIBRARIES), isFalse); |
| 2768 expect(entry.hasInvalidData(DartEntry.INCLUDED_PARTS), isFalse); |
| 2769 expect(entry.hasInvalidData(DartEntry.IS_CLIENT), isFalse); |
| 2770 expect(entry.hasInvalidData(DartEntry.IS_LAUNCHABLE), isFalse); |
| 2771 expect(entry.hasInvalidData(SourceEntry.LINE_INFO), isFalse); |
| 2772 expect(entry.hasInvalidData(DartEntry.PARSE_ERRORS), isFalse); |
| 2773 expect(entry.hasInvalidData(DartEntry.PARSED_UNIT), isFalse); |
| 2774 expect(entry.hasInvalidData(DartEntry.PUBLIC_NAMESPACE), isFalse); |
| 2775 expect(entry.hasInvalidData(DartEntry.SOURCE_KIND), isFalse); |
| 2776 expect(entry.hasInvalidData(DartEntry.RESOLUTION_ERRORS), isFalse); |
| 2777 expect(entry.hasInvalidData(DartEntry.RESOLVED_UNIT), isFalse); |
| 2778 expect(entry.hasInvalidData(DartEntry.VERIFICATION_ERRORS), isFalse); |
| 2779 } |
| 2780 |
| 2781 void test_hasInvalidData_true() { |
| 2782 DartEntry entry = new DartEntry(); |
| 2783 expect(entry.hasInvalidData(DartEntry.ELEMENT), isTrue); |
| 2784 expect(entry.hasInvalidData(DartEntry.EXPORTED_LIBRARIES), isTrue); |
| 2785 expect(entry.hasInvalidData(DartEntry.HINTS), isTrue); |
| 2786 expect(entry.hasInvalidData(DartEntry.IMPORTED_LIBRARIES), isTrue); |
| 2787 expect(entry.hasInvalidData(DartEntry.INCLUDED_PARTS), isTrue); |
| 2788 expect(entry.hasInvalidData(DartEntry.IS_CLIENT), isTrue); |
| 2789 expect(entry.hasInvalidData(DartEntry.IS_LAUNCHABLE), isTrue); |
| 2790 expect(entry.hasInvalidData(SourceEntry.LINE_INFO), isTrue); |
| 2791 expect(entry.hasInvalidData(DartEntry.PARSE_ERRORS), isTrue); |
| 2792 expect(entry.hasInvalidData(DartEntry.PARSED_UNIT), isTrue); |
| 2793 expect(entry.hasInvalidData(DartEntry.PUBLIC_NAMESPACE), isTrue); |
| 2794 expect(entry.hasInvalidData(DartEntry.SOURCE_KIND), isTrue); |
| 2795 expect(entry.hasInvalidData(DartEntry.RESOLUTION_ERRORS), isTrue); |
| 2796 expect(entry.hasInvalidData(DartEntry.RESOLVED_UNIT), isTrue); |
| 2797 expect(entry.hasInvalidData(DartEntry.VERIFICATION_ERRORS), isTrue); |
| 2798 } |
| 2799 |
| 2800 void test_invalidateAllInformation() { |
| 2801 Source librarySource = new TestSource(); |
| 2802 DartEntry entry = _entryWithValidState(librarySource); |
| 2803 entry.invalidateAllInformation(); |
| 2804 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.INVALID)); |
| 2805 expect( |
| 2806 entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.INVALID)); |
| 2807 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.INVALID)); |
| 2808 expect( |
| 2809 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 2810 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.INVALID)); |
| 2811 expect( |
| 2812 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.INVALID)); |
| 2813 expect( |
| 2814 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.INVALID)); |
| 2815 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.INVALID)); |
| 2816 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.INVALID)); |
| 2817 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.INVALID)); |
| 2818 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.INVALID)); |
| 2819 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.INVALID)); |
| 2820 expect( |
| 2821 entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.INVALID)); |
| 2822 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.INVALID)); |
| 2823 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.INVALID)); |
| 2824 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.INVALID)); |
| 2825 |
| 2826 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, librarySource), |
| 2827 same(CacheState.INVALID)); |
| 2828 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, librarySource), |
| 2829 same(CacheState.INVALID)); |
| 2830 expect(entry.getStateInLibrary(DartEntry.HINTS, librarySource), |
| 2831 same(CacheState.INVALID)); |
| 2832 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, librarySource), |
| 2833 same(CacheState.INVALID)); |
| 2834 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource), |
| 2835 same(CacheState.INVALID)); |
| 2836 expect( |
| 2837 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource), |
| 2838 same(CacheState.INVALID)); |
| 2839 } |
| 2840 |
| 2841 void test_invalidateAllResolutionInformation() { |
| 2842 Source librarySource = new TestSource(); |
| 2843 DartEntry entry = _entryWithValidState(librarySource); |
| 2844 entry.invalidateAllResolutionInformation(false); |
| 2845 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); |
| 2846 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 2847 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 2848 expect( |
| 2849 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 2850 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.INVALID)); |
| 2851 expect( |
| 2852 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); |
| 2853 expect( |
| 2854 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); |
| 2855 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); |
| 2856 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.INVALID)); |
| 2857 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.INVALID)); |
| 2858 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 2859 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 2860 expect( |
| 2861 entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.INVALID)); |
| 2862 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); |
| 2863 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); |
| 2864 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); |
| 2865 |
| 2866 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, librarySource), |
| 2867 same(CacheState.INVALID)); |
| 2868 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, librarySource), |
| 2869 same(CacheState.INVALID)); |
| 2870 expect(entry.getStateInLibrary(DartEntry.HINTS, librarySource), |
| 2871 same(CacheState.INVALID)); |
| 2872 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, librarySource), |
| 2873 same(CacheState.INVALID)); |
| 2874 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource), |
| 2875 same(CacheState.INVALID)); |
| 2876 expect( |
| 2877 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource), |
| 2878 same(CacheState.INVALID)); |
| 2879 } |
| 2880 |
| 2881 void test_invalidateAllResolutionInformation_includingUris() { |
| 2882 Source librarySource = new TestSource(); |
| 2883 DartEntry entry = _entryWithValidState(librarySource); |
| 2884 entry.invalidateAllResolutionInformation(true); |
| 2885 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); |
| 2886 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 2887 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 2888 expect( |
| 2889 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 2890 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.INVALID)); |
| 2891 expect( |
| 2892 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.INVALID)); |
| 2893 expect( |
| 2894 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.INVALID)); |
| 2895 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.INVALID)); |
| 2896 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.INVALID)); |
| 2897 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.INVALID)); |
| 2898 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 2899 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 2900 expect( |
| 2901 entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.INVALID)); |
| 2902 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); |
| 2903 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); |
| 2904 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); |
| 2905 |
| 2906 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, librarySource), |
| 2907 same(CacheState.INVALID)); |
| 2908 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, librarySource), |
| 2909 same(CacheState.INVALID)); |
| 2910 expect(entry.getStateInLibrary(DartEntry.HINTS, librarySource), |
| 2911 same(CacheState.INVALID)); |
| 2912 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, librarySource), |
| 2913 same(CacheState.INVALID)); |
| 2914 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource), |
| 2915 same(CacheState.INVALID)); |
| 2916 expect( |
| 2917 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource), |
| 2918 same(CacheState.INVALID)); |
| 2919 } |
| 2920 |
| 2921 void test_isClient() { |
| 2922 DartEntry entry = new DartEntry(); |
| 2923 // true |
| 2924 entry.setValue(DartEntry.IS_CLIENT, true); |
| 2925 expect(entry.getValue(DartEntry.IS_CLIENT), isTrue); |
| 2926 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.VALID)); |
| 2927 // invalidate |
| 2928 entry.setState(DartEntry.IS_CLIENT, CacheState.INVALID); |
| 2929 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.INVALID)); |
| 2930 // false |
| 2931 entry.setValue(DartEntry.IS_CLIENT, false); |
| 2932 expect(entry.getValue(DartEntry.IS_CLIENT), isFalse); |
| 2933 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.VALID)); |
| 2934 } |
| 2935 |
| 2936 void test_isLaunchable() { |
| 2937 DartEntry entry = new DartEntry(); |
| 2938 // true |
| 2939 entry.setValue(DartEntry.IS_LAUNCHABLE, true); |
| 2940 expect(entry.getValue(DartEntry.IS_LAUNCHABLE), isTrue); |
| 2941 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.VALID)); |
| 2942 // invalidate |
| 2943 entry.setState(DartEntry.IS_LAUNCHABLE, CacheState.INVALID); |
| 2944 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.INVALID)); |
| 2945 // false |
| 2946 entry.setValue(DartEntry.IS_LAUNCHABLE, false); |
| 2947 expect(entry.getValue(DartEntry.IS_LAUNCHABLE), isFalse); |
| 2948 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.VALID)); |
| 2949 } |
| 2950 |
| 2951 void test_recordBuildElementError() { |
| 2952 Source firstLibrary = new TestSource('first.dart'); |
| 2953 Source secondLibrary = new TestSource('second.dart'); |
| 2954 DartEntry entry = _entryWithValidState(firstLibrary, secondLibrary); |
| 2955 entry.recordBuildElementErrorInLibrary( |
| 2956 firstLibrary, new CaughtException(new AnalysisException(), null)); |
| 2957 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); |
| 2958 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 2959 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 2960 expect( |
| 2961 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 2962 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); |
| 2963 expect( |
| 2964 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); |
| 2965 expect( |
| 2966 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); |
| 2967 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); |
| 2968 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); |
| 2969 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); |
| 2970 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 2971 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 2972 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); |
| 2973 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); |
| 2974 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); |
| 2975 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); |
| 2976 |
| 2977 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), |
| 2978 same(CacheState.ERROR)); |
| 2979 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), |
| 2980 same(CacheState.ERROR)); |
| 2981 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), |
| 2982 same(CacheState.ERROR)); |
| 2983 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), |
| 2984 same(CacheState.ERROR)); |
| 2985 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), |
| 2986 same(CacheState.ERROR)); |
| 2987 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), |
| 2988 same(CacheState.ERROR)); |
| 2989 |
| 2990 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), |
| 2991 same(CacheState.VALID)); |
| 2992 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), |
| 2993 same(CacheState.VALID)); |
| 2994 expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), |
| 2995 same(CacheState.VALID)); |
| 2996 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary), |
| 2997 same(CacheState.VALID)); |
| 2998 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), |
| 2999 same(CacheState.VALID)); |
| 3000 expect( |
| 3001 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrary), |
| 3002 same(CacheState.VALID)); |
| 3003 } |
| 3004 |
| 3005 void test_recordContentError() { |
| 3006 Source firstLibrary = new TestSource('first.dart'); |
| 3007 // Source secondLibrary = new TestSource('second.dart'); |
| 3008 DartEntry entry = _entryWithValidState(firstLibrary); |
| 3009 entry |
| 3010 .recordContentError(new CaughtException(new AnalysisException(), null)); |
| 3011 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.ERROR)); |
| 3012 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 3013 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.ERROR)); |
| 3014 expect( |
| 3015 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 3016 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); |
| 3017 expect( |
| 3018 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.ERROR)); |
| 3019 expect( |
| 3020 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.ERROR)); |
| 3021 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.ERROR)); |
| 3022 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); |
| 3023 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); |
| 3024 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.ERROR)); |
| 3025 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.ERROR)); |
| 3026 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); |
| 3027 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.ERROR)); |
| 3028 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.ERROR)); |
| 3029 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.ERROR)); |
| 3030 |
| 3031 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), |
| 3032 same(CacheState.ERROR)); |
| 3033 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), |
| 3034 same(CacheState.ERROR)); |
| 3035 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), |
| 3036 same(CacheState.ERROR)); |
| 3037 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), |
| 3038 same(CacheState.ERROR)); |
| 3039 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), |
| 3040 same(CacheState.ERROR)); |
| 3041 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), |
| 3042 same(CacheState.ERROR)); |
| 3043 |
| 3044 // The following lines are commented out because we don't currently have |
| 3045 // any way of setting the state for data associated with a library we |
| 3046 // don't know anything about. |
| 3047 // expect(entry.getStateInLibrary(DartEntry.ANGULAR_ERRORS, secondLibrary), s
ame(CacheState.ERROR)); |
| 3048 // expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), sa
me(CacheState.ERROR)); |
| 3049 // expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), same(
CacheState.ERROR)); |
| 3050 // expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), same(Cache
State.ERROR)); |
| 3051 // expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary)
, same(CacheState.ERROR)); |
| 3052 // expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), sa
me(CacheState.ERROR)); |
| 3053 // expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrar
y), same(CacheState.ERROR)); |
| 3054 } |
| 3055 |
| 3056 void test_recordHintErrorInLibrary() { |
| 3057 Source firstLibrary = new TestSource('first.dart'); |
| 3058 Source secondLibrary = new TestSource('second.dart'); |
| 3059 DartEntry entry = _entryWithValidState(firstLibrary, secondLibrary); |
| 3060 entry.recordHintErrorInLibrary( |
| 3061 firstLibrary, new CaughtException(new AnalysisException(), null)); |
| 3062 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); |
| 3063 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 3064 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 3065 expect( |
| 3066 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 3067 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.VALID)); |
| 3068 expect( |
| 3069 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); |
| 3070 expect( |
| 3071 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); |
| 3072 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); |
| 3073 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.VALID)); |
| 3074 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.VALID)); |
| 3075 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 3076 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 3077 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.VALID)); |
| 3078 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); |
| 3079 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); |
| 3080 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); |
| 3081 |
| 3082 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), |
| 3083 same(CacheState.VALID)); |
| 3084 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), |
| 3085 same(CacheState.VALID)); |
| 3086 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), |
| 3087 same(CacheState.ERROR)); |
| 3088 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), |
| 3089 same(CacheState.VALID)); |
| 3090 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), |
| 3091 same(CacheState.VALID)); |
| 3092 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), |
| 3093 same(CacheState.VALID)); |
| 3094 |
| 3095 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), |
| 3096 same(CacheState.VALID)); |
| 3097 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), |
| 3098 same(CacheState.VALID)); |
| 3099 expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), |
| 3100 same(CacheState.VALID)); |
| 3101 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary), |
| 3102 same(CacheState.VALID)); |
| 3103 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), |
| 3104 same(CacheState.VALID)); |
| 3105 expect( |
| 3106 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrary), |
| 3107 same(CacheState.VALID)); |
| 3108 } |
| 3109 |
| 3110 void test_recordParseError() { |
| 3111 Source firstLibrary = new TestSource('first.dart'); |
| 3112 // Source secondLibrary = new TestSource('second.dart'); |
| 3113 DartEntry entry = _entryWithValidState(firstLibrary); |
| 3114 entry.recordParseError(new CaughtException(new AnalysisException(), null)); |
| 3115 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); |
| 3116 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 3117 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 3118 expect( |
| 3119 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 3120 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); |
| 3121 expect( |
| 3122 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.ERROR)); |
| 3123 expect( |
| 3124 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.ERROR)); |
| 3125 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.ERROR)); |
| 3126 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); |
| 3127 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); |
| 3128 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.ERROR)); |
| 3129 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.ERROR)); |
| 3130 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); |
| 3131 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); |
| 3132 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.ERROR)); |
| 3133 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); |
| 3134 |
| 3135 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), |
| 3136 same(CacheState.ERROR)); |
| 3137 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), |
| 3138 same(CacheState.ERROR)); |
| 3139 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), |
| 3140 same(CacheState.ERROR)); |
| 3141 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), |
| 3142 same(CacheState.ERROR)); |
| 3143 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), |
| 3144 same(CacheState.ERROR)); |
| 3145 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), |
| 3146 same(CacheState.ERROR)); |
| 3147 |
| 3148 // The following lines are commented out because we don't currently have |
| 3149 // any way of setting the state for data associated with a library we |
| 3150 // don't know anything about. |
| 3151 // expect(entry.getStateInLibrary(DartEntry.ANGULAR_ERRORS, secondLibrary), s
ame(CacheState.ERROR)); |
| 3152 // expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), sa
me(CacheState.ERROR)); |
| 3153 // expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), same(
CacheState.ERROR)); |
| 3154 // expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), same(Cache
State.ERROR)); |
| 3155 // expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary)
, same(CacheState.ERROR)); |
| 3156 // expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), sa
me(CacheState.ERROR)); |
| 3157 // expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrar
y), same(CacheState.ERROR)); |
| 3158 } |
| 3159 |
| 3160 void test_recordResolutionError() { |
| 3161 Source firstLibrary = new TestSource('first.dart'); |
| 3162 // Source secondLibrary = new TestSource('second.dart'); |
| 3163 DartEntry entry = _entryWithValidState(firstLibrary); |
| 3164 entry.recordResolutionError( |
| 3165 new CaughtException(new AnalysisException(), null)); |
| 3166 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); |
| 3167 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 3168 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 3169 expect( |
| 3170 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 3171 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); |
| 3172 expect( |
| 3173 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); |
| 3174 expect( |
| 3175 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); |
| 3176 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); |
| 3177 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); |
| 3178 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); |
| 3179 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 3180 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 3181 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); |
| 3182 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); |
| 3183 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); |
| 3184 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); |
| 3185 |
| 3186 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), |
| 3187 same(CacheState.ERROR)); |
| 3188 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), |
| 3189 same(CacheState.ERROR)); |
| 3190 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), |
| 3191 same(CacheState.ERROR)); |
| 3192 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), |
| 3193 same(CacheState.ERROR)); |
| 3194 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), |
| 3195 same(CacheState.ERROR)); |
| 3196 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), |
| 3197 same(CacheState.ERROR)); |
| 3198 |
| 3199 // The following lines are commented out because we don't currently have |
| 3200 // any way of setting the state for data associated with a library we |
| 3201 // don't know anything about. |
| 3202 // expect(entry.getStateInLibrary(DartEntry.ANGULAR_ERRORS, secondLibrary), s
ame(CacheState.ERROR)); |
| 3203 // expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), sa
me(CacheState.ERROR)); |
| 3204 // expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), same(
CacheState.ERROR)); |
| 3205 // expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), same(Cache
State.ERROR)); |
| 3206 // expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary)
, same(CacheState.ERROR)); |
| 3207 // expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), sa
me(CacheState.ERROR)); |
| 3208 // expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrar
y), same(CacheState.ERROR)); |
| 3209 } |
| 3210 |
| 3211 void test_recordResolutionErrorInLibrary() { |
| 3212 Source firstLibrary = new TestSource('first.dart'); |
| 3213 Source secondLibrary = new TestSource('second.dart'); |
| 3214 DartEntry entry = _entryWithValidState(firstLibrary, secondLibrary); |
| 3215 entry.recordResolutionErrorInLibrary( |
| 3216 firstLibrary, new CaughtException(new AnalysisException(), null)); |
| 3217 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); |
| 3218 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 3219 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 3220 expect( |
| 3221 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 3222 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); |
| 3223 expect( |
| 3224 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); |
| 3225 expect( |
| 3226 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); |
| 3227 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); |
| 3228 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); |
| 3229 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); |
| 3230 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 3231 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 3232 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); |
| 3233 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); |
| 3234 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); |
| 3235 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); |
| 3236 |
| 3237 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), |
| 3238 same(CacheState.VALID)); |
| 3239 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), |
| 3240 same(CacheState.VALID)); |
| 3241 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), |
| 3242 same(CacheState.ERROR)); |
| 3243 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), |
| 3244 same(CacheState.ERROR)); |
| 3245 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), |
| 3246 same(CacheState.ERROR)); |
| 3247 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), |
| 3248 same(CacheState.ERROR)); |
| 3249 |
| 3250 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), |
| 3251 same(CacheState.VALID)); |
| 3252 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), |
| 3253 same(CacheState.VALID)); |
| 3254 expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), |
| 3255 same(CacheState.VALID)); |
| 3256 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary), |
| 3257 same(CacheState.VALID)); |
| 3258 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), |
| 3259 same(CacheState.VALID)); |
| 3260 expect( |
| 3261 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrary), |
| 3262 same(CacheState.VALID)); |
| 3263 } |
| 3264 |
| 3265 void test_recordScanError() { |
| 3266 Source firstLibrary = new TestSource('first.dart'); |
| 3267 // Source secondLibrary = new TestSource('second.dart'); |
| 3268 DartEntry entry = _entryWithValidState(firstLibrary); |
| 3269 entry.recordScanError(new CaughtException(new AnalysisException(), null)); |
| 3270 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); |
| 3271 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 3272 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.ERROR)); |
| 3273 expect( |
| 3274 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 3275 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); |
| 3276 expect( |
| 3277 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.ERROR)); |
| 3278 expect( |
| 3279 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.ERROR)); |
| 3280 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.ERROR)); |
| 3281 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); |
| 3282 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); |
| 3283 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.ERROR)); |
| 3284 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.ERROR)); |
| 3285 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); |
| 3286 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.ERROR)); |
| 3287 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.ERROR)); |
| 3288 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.ERROR)); |
| 3289 |
| 3290 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), |
| 3291 same(CacheState.ERROR)); |
| 3292 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), |
| 3293 same(CacheState.ERROR)); |
| 3294 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), |
| 3295 same(CacheState.ERROR)); |
| 3296 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), |
| 3297 same(CacheState.ERROR)); |
| 3298 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), |
| 3299 same(CacheState.ERROR)); |
| 3300 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), |
| 3301 same(CacheState.ERROR)); |
| 3302 |
| 3303 // The following lines are commented out because we don't currently have |
| 3304 // any way of setting the state for data associated with a library we |
| 3305 // don't know anything about. |
| 3306 // expect(entry.getStateInLibrary(DartEntry.ANGULAR_ERRORS, secondLibrary), s
ame(CacheState.ERROR)); |
| 3307 // expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), sa
me(CacheState.ERROR)); |
| 3308 // expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), same(
CacheState.ERROR)); |
| 3309 // expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), same(Cache
State.ERROR)); |
| 3310 // expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary)
, same(CacheState.ERROR)); |
| 3311 // expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), sa
me(CacheState.ERROR)); |
| 3312 // expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrar
y), same(CacheState.ERROR)); |
| 3313 } |
| 3314 |
| 3315 void test_recordVerificationErrorInLibrary() { |
| 3316 Source firstLibrary = new TestSource('first.dart'); |
| 3317 Source secondLibrary = new TestSource('second.dart'); |
| 3318 DartEntry entry = _entryWithValidState(firstLibrary, secondLibrary); |
| 3319 entry.recordVerificationErrorInLibrary( |
| 3320 firstLibrary, new CaughtException(new AnalysisException(), null)); |
| 3321 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); |
| 3322 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 3323 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 3324 expect( |
| 3325 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 3326 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.VALID)); |
| 3327 expect( |
| 3328 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); |
| 3329 expect( |
| 3330 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); |
| 3331 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); |
| 3332 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.VALID)); |
| 3333 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.VALID)); |
| 3334 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 3335 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 3336 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.VALID)); |
| 3337 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); |
| 3338 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); |
| 3339 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); |
| 3340 |
| 3341 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), |
| 3342 same(CacheState.VALID)); |
| 3343 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), |
| 3344 same(CacheState.VALID)); |
| 3345 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), |
| 3346 same(CacheState.ERROR)); |
| 3347 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), |
| 3348 same(CacheState.VALID)); |
| 3349 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), |
| 3350 same(CacheState.VALID)); |
| 3351 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), |
| 3352 same(CacheState.ERROR)); |
| 3353 |
| 3354 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), |
| 3355 same(CacheState.VALID)); |
| 3356 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), |
| 3357 same(CacheState.VALID)); |
| 3358 expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), |
| 3359 same(CacheState.VALID)); |
| 3360 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary), |
| 3361 same(CacheState.VALID)); |
| 3362 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), |
| 3363 same(CacheState.VALID)); |
| 3364 expect( |
| 3365 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrary), |
| 3366 same(CacheState.VALID)); |
| 3367 } |
| 3368 |
| 3369 void test_removeResolution_multiple_first() { |
| 3370 Source source1 = new TestSource('first.dart'); |
| 3371 Source source2 = new TestSource('second.dart'); |
| 3372 Source source3 = new TestSource('third.dart'); |
| 3373 DartEntry entry = new DartEntry(); |
| 3374 entry.setValueInLibrary( |
| 3375 DartEntry.RESOLVED_UNIT, source1, AstFactory.compilationUnit()); |
| 3376 entry.setValueInLibrary( |
| 3377 DartEntry.RESOLVED_UNIT, source2, AstFactory.compilationUnit()); |
| 3378 entry.setValueInLibrary( |
| 3379 DartEntry.RESOLVED_UNIT, source3, AstFactory.compilationUnit()); |
| 3380 entry.removeResolution(source1); |
| 3381 } |
| 3382 |
| 3383 void test_removeResolution_multiple_last() { |
| 3384 Source source1 = new TestSource('first.dart'); |
| 3385 Source source2 = new TestSource('second.dart'); |
| 3386 Source source3 = new TestSource('third.dart'); |
| 3387 DartEntry entry = new DartEntry(); |
| 3388 entry.setValueInLibrary( |
| 3389 DartEntry.RESOLVED_UNIT, source1, AstFactory.compilationUnit()); |
| 3390 entry.setValueInLibrary( |
| 3391 DartEntry.RESOLVED_UNIT, source2, AstFactory.compilationUnit()); |
| 3392 entry.setValueInLibrary( |
| 3393 DartEntry.RESOLVED_UNIT, source3, AstFactory.compilationUnit()); |
| 3394 entry.removeResolution(source3); |
| 3395 } |
| 3396 |
| 3397 void test_removeResolution_multiple_middle() { |
| 3398 Source source1 = new TestSource('first.dart'); |
| 3399 Source source2 = new TestSource('second.dart'); |
| 3400 Source source3 = new TestSource('third.dart'); |
| 3401 DartEntry entry = new DartEntry(); |
| 3402 entry.setValueInLibrary( |
| 3403 DartEntry.RESOLVED_UNIT, source1, AstFactory.compilationUnit()); |
| 3404 entry.setValueInLibrary( |
| 3405 DartEntry.RESOLVED_UNIT, source2, AstFactory.compilationUnit()); |
| 3406 entry.setValueInLibrary( |
| 3407 DartEntry.RESOLVED_UNIT, source3, AstFactory.compilationUnit()); |
| 3408 entry.removeResolution(source2); |
| 3409 } |
| 3410 |
| 3411 void test_removeResolution_single() { |
| 3412 Source source1 = new TestSource(); |
| 3413 DartEntry entry = new DartEntry(); |
| 3414 entry.setValueInLibrary( |
| 3415 DartEntry.RESOLVED_UNIT, source1, AstFactory.compilationUnit()); |
| 3416 entry.removeResolution(source1); |
| 3417 } |
| 3418 |
| 3419 void test_resolvableCompilationUnit_builtUnit() { |
| 3420 Source librarySource = new TestSource('/lib.dart'); |
| 3421 CompilationUnit unit = AstFactory.compilationUnit(); |
| 3422 CompilationUnitElement element = |
| 3423 ElementFactory.compilationUnit('test.dart'); |
| 3424 unit.element = element; |
| 3425 DartEntry entry = new DartEntry(); |
| 3426 entry.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
| 3427 entry.setValueInLibrary(DartEntry.BUILT_UNIT, librarySource, unit); |
| 3428 entry.invalidateAllResolutionInformation(false); |
| 3429 CompilationUnit resolvableUnit = entry.resolvableCompilationUnit; |
| 3430 expect(resolvableUnit, isNotNull); |
| 3431 expect(resolvableUnit.element, isNull); |
| 3432 expect(entry.resolvableCompilationUnit, isNull); |
| 3433 } |
| 3434 |
| 3435 void test_resolvableCompilationUnit_none() { |
| 3436 DartEntry entry = new DartEntry(); |
| 3437 expect(entry.resolvableCompilationUnit, isNull); |
| 3438 } |
| 3439 |
| 3440 void test_resolvableCompilationUnit_parsed() { |
| 3441 CompilationUnit unit = AstFactory.compilationUnit(); |
| 3442 DartEntry entry = new DartEntry(); |
| 3443 entry.setValue(DartEntry.PARSED_UNIT, unit); |
| 3444 expect(entry.resolvableCompilationUnit, unit); |
| 3445 expect(entry.resolvableCompilationUnit, isNull); |
| 3446 } |
| 3447 |
| 3448 void test_resolvableCompilationUnit_resolved() { |
| 3449 Source librarySource = new TestSource('/lib.dart'); |
| 3450 CompilationUnit unit = AstFactory.compilationUnit(); |
| 3451 CompilationUnitElement element = |
| 3452 ElementFactory.compilationUnit('test.dart'); |
| 3453 unit.element = element; |
| 3454 DartEntry entry = new DartEntry(); |
| 3455 entry.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); |
| 3456 entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource, unit); |
| 3457 entry.invalidateAllResolutionInformation(false); |
| 3458 CompilationUnit resolvableUnit = entry.resolvableCompilationUnit; |
| 3459 expect(resolvableUnit, isNotNull); |
| 3460 expect(resolvableUnit.element, isNull); |
| 3461 expect(entry.resolvableCompilationUnit, isNull); |
| 3462 } |
| 3463 |
| 3464 void test_setState_element() { |
| 3465 _setState(DartEntry.ELEMENT); |
| 3466 } |
| 3467 |
| 3468 void test_setState_exportedLibraries() { |
| 3469 _setState(DartEntry.EXPORTED_LIBRARIES); |
| 3470 } |
| 3471 |
| 3472 void test_setState_hints() { |
| 3473 _setStateInLibrary(DartEntry.HINTS); |
| 3474 } |
| 3475 |
| 3476 void test_setState_importedLibraries() { |
| 3477 _setState(DartEntry.IMPORTED_LIBRARIES); |
| 3478 } |
| 3479 |
| 3480 void test_setState_includedParts() { |
| 3481 _setState(DartEntry.INCLUDED_PARTS); |
| 3482 } |
| 3483 |
| 3484 void test_setState_invalid_element() { |
| 3485 DartEntry entry = new DartEntry(); |
| 3486 try { |
| 3487 entry.setStateInLibrary(DartEntry.ELEMENT, null, CacheState.FLUSHED); |
| 3488 fail("Expected ArgumentError for ELEMENT"); |
| 3489 } on ArgumentError { |
| 3490 // Expected |
| 3491 } |
| 3492 } |
| 3493 |
| 3494 void test_setState_invalid_resolutionErrors() { |
| 3495 DartEntry entry = new DartEntry(); |
| 3496 try { |
| 3497 entry.setState(DartEntry.RESOLUTION_ERRORS, CacheState.FLUSHED); |
| 3498 fail("Expected ArgumentError for RESOLUTION_ERRORS"); |
| 3499 } on ArgumentError { |
| 3500 // Expected |
| 3501 } |
| 3502 } |
| 3503 |
| 3504 void test_setState_invalid_validState() { |
| 3505 DartEntry entry = new DartEntry(); |
| 3506 try { |
| 3507 entry.setState(SourceEntry.LINE_INFO, CacheState.VALID); |
| 3508 fail("Expected ArgumentError for a state of VALID"); |
| 3509 } on ArgumentError {} |
| 3510 } |
| 3511 |
| 3512 void test_setState_invalid_verificationErrors() { |
| 3513 DartEntry entry = new DartEntry(); |
| 3514 try { |
| 3515 entry.setState(DartEntry.VERIFICATION_ERRORS, CacheState.FLUSHED); |
| 3516 fail("Expected ArgumentError for VERIFICATION_ERRORS"); |
| 3517 } on ArgumentError { |
| 3518 // Expected |
| 3519 } |
| 3520 } |
| 3521 |
| 3522 void test_setState_isClient() { |
| 3523 _setState(DartEntry.IS_CLIENT); |
| 3524 } |
| 3525 |
| 3526 void test_setState_isLaunchable() { |
| 3527 _setState(DartEntry.IS_LAUNCHABLE); |
| 3528 } |
| 3529 |
| 3530 void test_setState_lineInfo() { |
| 3531 _setState(SourceEntry.LINE_INFO); |
| 3532 } |
| 3533 |
| 3534 void test_setState_parsedUnit() { |
| 3535 _setState(DartEntry.PARSED_UNIT); |
| 3536 } |
| 3537 |
| 3538 void test_setState_parseErrors() { |
| 3539 _setState(DartEntry.PARSE_ERRORS); |
| 3540 } |
| 3541 |
| 3542 void test_setState_publicNamespace() { |
| 3543 _setState(DartEntry.PUBLIC_NAMESPACE); |
| 3544 } |
| 3545 |
| 3546 void test_setState_resolutionErrors() { |
| 3547 _setStateInLibrary(DartEntry.RESOLUTION_ERRORS); |
| 3548 } |
| 3549 |
| 3550 void test_setState_resolvedUnit() { |
| 3551 _setStateInLibrary(DartEntry.RESOLVED_UNIT); |
| 3552 } |
| 3553 |
| 3554 void test_setState_scanErrors() { |
| 3555 _setState(DartEntry.SCAN_ERRORS); |
| 3556 } |
| 3557 |
| 3558 void test_setState_sourceKind() { |
| 3559 _setState(DartEntry.SOURCE_KIND); |
| 3560 } |
| 3561 |
| 3562 void test_setState_tokenStream() { |
| 3563 _setState(DartEntry.TOKEN_STREAM); |
| 3564 } |
| 3565 |
| 3566 void test_setState_verificationErrors() { |
| 3567 _setStateInLibrary(DartEntry.VERIFICATION_ERRORS); |
| 3568 } |
| 3569 |
| 3570 void test_setValue_element() { |
| 3571 _setValue( |
| 3572 DartEntry.ELEMENT, |
| 3573 new LibraryElementImpl.forNode( |
| 3574 null, AstFactory.libraryIdentifier2(["lib"]))); |
| 3575 } |
| 3576 |
| 3577 void test_setValue_exportedLibraries() { |
| 3578 _setValue(DartEntry.EXPORTED_LIBRARIES, <Source>[new TestSource()]); |
| 3579 } |
| 3580 |
| 3581 void test_setValue_hints() { |
| 3582 _setValueInLibrary(DartEntry.HINTS, |
| 3583 <AnalysisError>[new AnalysisError(null, 0, 0, HintCode.DEAD_CODE)]); |
| 3584 } |
| 3585 |
| 3586 void test_setValue_importedLibraries() { |
| 3587 _setValue(DartEntry.IMPORTED_LIBRARIES, <Source>[new TestSource()]); |
| 3588 } |
| 3589 |
| 3590 void test_setValue_includedParts() { |
| 3591 _setValue(DartEntry.INCLUDED_PARTS, <Source>[new TestSource()]); |
| 3592 } |
| 3593 |
| 3594 void test_setValue_isClient() { |
| 3595 _setValue(DartEntry.IS_CLIENT, true); |
| 3596 } |
| 3597 |
| 3598 void test_setValue_isLaunchable() { |
| 3599 _setValue(DartEntry.IS_LAUNCHABLE, true); |
| 3600 } |
| 3601 |
| 3602 void test_setValue_lineInfo() { |
| 3603 _setValue(SourceEntry.LINE_INFO, new LineInfo(<int>[0])); |
| 3604 } |
| 3605 |
| 3606 void test_setValue_parsedUnit() { |
| 3607 _setValue(DartEntry.PARSED_UNIT, AstFactory.compilationUnit()); |
| 3608 } |
| 3609 |
| 3610 void test_setValue_parseErrors() { |
| 3611 _setValue(DartEntry.PARSE_ERRORS, <AnalysisError>[ |
| 3612 new AnalysisError(null, 0, 0, ParserErrorCode.ABSTRACT_CLASS_MEMBER) |
| 3613 ]); |
| 3614 } |
| 3615 |
| 3616 void test_setValue_publicNamespace() { |
| 3617 _setValue(DartEntry.PUBLIC_NAMESPACE, |
| 3618 new Namespace(new HashMap<String, Element>())); |
| 3619 } |
| 3620 |
| 3621 void test_setValue_resolutionErrors() { |
| 3622 _setValueInLibrary(DartEntry.RESOLUTION_ERRORS, <AnalysisError>[ |
| 3623 new AnalysisError( |
| 3624 null, 0, 0, CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION) |
| 3625 ]); |
| 3626 } |
| 3627 |
| 3628 void test_setValue_resolvedUnit() { |
| 3629 _setValueInLibrary(DartEntry.RESOLVED_UNIT, AstFactory.compilationUnit()); |
| 3630 } |
| 3631 |
| 3632 void test_setValue_scanErrors() { |
| 3633 _setValue(DartEntry.SCAN_ERRORS, <AnalysisError>[ |
| 3634 new AnalysisError( |
| 3635 null, 0, 0, ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT) |
| 3636 ]); |
| 3637 } |
| 3638 |
| 3639 void test_setValue_sourceKind() { |
| 3640 _setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); |
| 3641 } |
| 3642 |
| 3643 void test_setValue_tokenStream() { |
| 3644 _setValue(DartEntry.TOKEN_STREAM, new Token(TokenType.LT, 5)); |
| 3645 } |
| 3646 |
| 3647 void test_setValue_verificationErrors() { |
| 3648 _setValueInLibrary(DartEntry.VERIFICATION_ERRORS, <AnalysisError>[ |
| 3649 new AnalysisError(null, 0, 0, StaticWarningCode.CASE_BLOCK_NOT_TERMINATED) |
| 3650 ]); |
| 3651 } |
| 3652 |
| 3653 DartEntry _entryWithValidState([Source firstLibrary, Source secondLibrary]) { |
| 3654 DartEntry entry = new DartEntry(); |
| 3655 entry.setValue(SourceEntry.CONTENT, null); |
| 3656 entry.setValue(SourceEntry.CONTENT_ERRORS, null); |
| 3657 entry.setValue(SourceEntry.LINE_INFO, null); |
| 3658 entry.setValue(DartEntry.CONTAINING_LIBRARIES, null); |
| 3659 entry.setValue(DartEntry.ELEMENT, null); |
| 3660 entry.setValue(DartEntry.EXPORTED_LIBRARIES, null); |
| 3661 entry.setValue(DartEntry.IMPORTED_LIBRARIES, null); |
| 3662 entry.setValue(DartEntry.INCLUDED_PARTS, null); |
| 3663 entry.setValue(DartEntry.IS_CLIENT, null); |
| 3664 entry.setValue(DartEntry.IS_LAUNCHABLE, null); |
| 3665 entry.setValue(DartEntry.PARSE_ERRORS, null); |
| 3666 entry.setValue(DartEntry.PARSED_UNIT, null); |
| 3667 entry.setValue(DartEntry.PUBLIC_NAMESPACE, null); |
| 3668 entry.setValue(DartEntry.SCAN_ERRORS, null); |
| 3669 entry.setValue(DartEntry.SOURCE_KIND, null); |
| 3670 entry.setValue(DartEntry.TOKEN_STREAM, null); |
| 3671 if (firstLibrary != null) { |
| 3672 entry.setValueInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary, null); |
| 3673 entry.setValueInLibrary(DartEntry.BUILT_UNIT, firstLibrary, null); |
| 3674 entry.setValueInLibrary(DartEntry.HINTS, firstLibrary, null); |
| 3675 entry.setValueInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary, null); |
| 3676 entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary, null); |
| 3677 entry.setValueInLibrary( |
| 3678 DartEntry.VERIFICATION_ERRORS, firstLibrary, null); |
| 3679 } |
| 3680 if (secondLibrary != null) { |
| 3681 entry.setValueInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary, null); |
| 3682 entry.setValueInLibrary(DartEntry.BUILT_UNIT, secondLibrary, null); |
| 3683 entry.setValueInLibrary(DartEntry.HINTS, secondLibrary, null); |
| 3684 entry.setValueInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary, null); |
| 3685 entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary, null); |
| 3686 entry.setValueInLibrary( |
| 3687 DartEntry.VERIFICATION_ERRORS, secondLibrary, null); |
| 3688 } |
| 3689 // |
| 3690 // Validate that the state was set correctly. |
| 3691 // |
| 3692 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); |
| 3693 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); |
| 3694 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 3695 expect( |
| 3696 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); |
| 3697 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.VALID)); |
| 3698 expect( |
| 3699 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); |
| 3700 expect( |
| 3701 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); |
| 3702 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); |
| 3703 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.VALID)); |
| 3704 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.VALID)); |
| 3705 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 3706 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 3707 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.VALID)); |
| 3708 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); |
| 3709 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); |
| 3710 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); |
| 3711 if (firstLibrary != null) { |
| 3712 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), |
| 3713 same(CacheState.VALID)); |
| 3714 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), |
| 3715 same(CacheState.VALID)); |
| 3716 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), |
| 3717 same(CacheState.VALID)); |
| 3718 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), |
| 3719 same(CacheState.VALID)); |
| 3720 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), |
| 3721 same(CacheState.VALID)); |
| 3722 expect( |
| 3723 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), |
| 3724 same(CacheState.VALID)); |
| 3725 } |
| 3726 if (secondLibrary != null) { |
| 3727 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), |
| 3728 same(CacheState.VALID)); |
| 3729 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), |
| 3730 same(CacheState.VALID)); |
| 3731 expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), |
| 3732 same(CacheState.VALID)); |
| 3733 expect( |
| 3734 entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary), |
| 3735 same(CacheState.VALID)); |
| 3736 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), |
| 3737 same(CacheState.VALID)); |
| 3738 expect( |
| 3739 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrary), |
| 3740 same(CacheState.VALID)); |
| 3741 } |
| 3742 return entry; |
| 3743 } |
| 3744 |
| 3745 void _setState(DataDescriptor descriptor) { |
| 3746 DartEntry entry = new DartEntry(); |
| 3747 expect(entry.getState(descriptor), isNot(same(CacheState.FLUSHED))); |
| 3748 entry.setState(descriptor, CacheState.FLUSHED); |
| 3749 expect(entry.getState(descriptor), same(CacheState.FLUSHED)); |
| 3750 } |
| 3751 |
| 3752 void _setStateInLibrary(DataDescriptor descriptor) { |
| 3753 Source source = new TestSource(); |
| 3754 DartEntry entry = new DartEntry(); |
| 3755 expect(entry.getStateInLibrary(descriptor, source), |
| 3756 isNot(same(CacheState.FLUSHED))); |
| 3757 entry.setStateInLibrary(descriptor, source, CacheState.FLUSHED); |
| 3758 expect( |
| 3759 entry.getStateInLibrary(descriptor, source), same(CacheState.FLUSHED)); |
| 3760 } |
| 3761 |
| 3762 void _setValue(DataDescriptor descriptor, Object newValue) { |
| 3763 DartEntry entry = new DartEntry(); |
| 3764 Object value = entry.getValue(descriptor); |
| 3765 expect(newValue, isNot(same(value))); |
| 3766 entry.setValue(descriptor, newValue); |
| 3767 expect(entry.getState(descriptor), same(CacheState.VALID)); |
| 3768 expect(entry.getValue(descriptor), same(newValue)); |
| 3769 } |
| 3770 |
| 3771 void _setValueInLibrary(DataDescriptor descriptor, Object newValue) { |
| 3772 Source source = new TestSource(); |
| 3773 DartEntry entry = new DartEntry(); |
| 3774 Object value = entry.getValueInLibrary(descriptor, source); |
| 3775 expect(newValue, isNot(same(value))); |
| 3776 entry.setValueInLibrary(descriptor, source, newValue); |
| 3777 expect(entry.getStateInLibrary(descriptor, source), same(CacheState.VALID)); |
| 3778 expect(entry.getValueInLibrary(descriptor, source), same(newValue)); |
| 3779 } |
| 3780 } |
| 3781 |
| 3782 @reflectiveTest |
| 3783 class GenerateDartErrorsTaskTest extends EngineTestCase { |
| 3784 void test_accept() { |
| 3785 GenerateDartErrorsTask task = |
| 3786 new GenerateDartErrorsTask(null, null, null, null); |
| 3787 expect(task.accept(new GenerateDartErrorsTaskTestTV_accept()), isTrue); |
| 3788 } |
| 3789 |
| 3790 void test_getException() { |
| 3791 GenerateDartErrorsTask task = |
| 3792 new GenerateDartErrorsTask(null, null, null, null); |
| 3793 expect(task.exception, isNull); |
| 3794 } |
| 3795 |
| 3796 void test_getLibraryElement() { |
| 3797 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 3798 LibraryElement element = ElementFactory.library(context, "lib"); |
| 3799 GenerateDartErrorsTask task = |
| 3800 new GenerateDartErrorsTask(context, null, null, element); |
| 3801 expect(task.libraryElement, same(element)); |
| 3802 } |
| 3803 |
| 3804 void test_getSource() { |
| 3805 Source source = |
| 3806 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 3807 GenerateDartErrorsTask task = |
| 3808 new GenerateDartErrorsTask(null, source, null, null); |
| 3809 expect(task.source, same(source)); |
| 3810 } |
| 3811 |
| 3812 void test_perform() { |
| 3813 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 3814 Source source = |
| 3815 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 3816 ChangeSet changeSet = new ChangeSet(); |
| 3817 changeSet.addedSource(source); |
| 3818 context.applyChanges(changeSet); |
| 3819 context.setContents( |
| 3820 source, |
| 3821 r''' |
| 3822 library lib; |
| 3823 class A { |
| 3824 int f = new A(); |
| 3825 }'''); |
| 3826 LibraryElement libraryElement = context.computeLibraryElement(source); |
| 3827 CompilationUnit unit = |
| 3828 context.getResolvedCompilationUnit(source, libraryElement); |
| 3829 GenerateDartErrorsTask task = |
| 3830 new GenerateDartErrorsTask(context, source, unit, libraryElement); |
| 3831 task.perform( |
| 3832 new GenerateDartErrorsTaskTestTV_perform(libraryElement, source)); |
| 3833 } |
| 3834 |
| 3835 void test_perform_validateDirectives() { |
| 3836 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 3837 Source source = |
| 3838 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 3839 ChangeSet changeSet = new ChangeSet(); |
| 3840 changeSet.addedSource(source); |
| 3841 context.applyChanges(changeSet); |
| 3842 // TODO(scheglov) "import" causes second error reported |
| 3843 // context.setContents(source, EngineTestCase.createSource([ |
| 3844 // "library lib;", |
| 3845 // "import 'invaliduri^.dart';", |
| 3846 // "export '\${a}lib3.dart';", |
| 3847 // "part '/does/not/exist.dart';", |
| 3848 // "class A {}"])); |
| 3849 context.setContents( |
| 3850 source, |
| 3851 r''' |
| 3852 library lib; |
| 3853 part '/does/not/exist.dart'; |
| 3854 class A {}'''); |
| 3855 LibraryElement libraryElement = context.computeLibraryElement(source); |
| 3856 CompilationUnit unit = |
| 3857 context.getResolvedCompilationUnit(source, libraryElement); |
| 3858 GenerateDartErrorsTask task = |
| 3859 new GenerateDartErrorsTask(context, source, unit, libraryElement); |
| 3860 task.perform(new GenerateDartErrorsTaskTestTV_perform_validateDirectives( |
| 3861 libraryElement, source)); |
| 3862 } |
| 3863 } |
| 3864 |
| 3865 class GenerateDartErrorsTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 3866 @override |
| 3867 bool visitGenerateDartErrorsTask(GenerateDartErrorsTask task) => true; |
| 3868 } |
| 3869 |
| 3870 class GenerateDartErrorsTaskTestTV_perform extends TestTaskVisitor<bool> { |
| 3871 LibraryElement libraryElement; |
| 3872 Source source; |
| 3873 GenerateDartErrorsTaskTestTV_perform(this.libraryElement, this.source); |
| 3874 @override |
| 3875 bool visitGenerateDartErrorsTask(GenerateDartErrorsTask task) { |
| 3876 CaughtException exception = task.exception; |
| 3877 if (exception != null) { |
| 3878 throw exception; |
| 3879 } |
| 3880 expect(task.libraryElement, same(libraryElement)); |
| 3881 expect(task.source, same(source)); |
| 3882 List<AnalysisError> errors = task.errors; |
| 3883 expect(errors, hasLength(1)); |
| 3884 return true; |
| 3885 } |
| 3886 } |
| 3887 |
| 3888 class GenerateDartErrorsTaskTestTV_perform_validateDirectives |
| 3889 extends TestTaskVisitor<bool> { |
| 3890 LibraryElement libraryElement; |
| 3891 Source source; |
| 3892 GenerateDartErrorsTaskTestTV_perform_validateDirectives( |
| 3893 this.libraryElement, this.source); |
| 3894 @override |
| 3895 bool visitGenerateDartErrorsTask(GenerateDartErrorsTask task) { |
| 3896 CaughtException exception = task.exception; |
| 3897 if (exception != null) { |
| 3898 throw exception; |
| 3899 } |
| 3900 expect(task.libraryElement, same(libraryElement)); |
| 3901 expect(task.source, same(source)); |
| 3902 List<AnalysisError> errors = task.errors; |
| 3903 expect(errors, hasLength(1)); |
| 3904 expect(errors[0].errorCode, same(CompileTimeErrorCode.URI_DOES_NOT_EXIST)); |
| 3905 return true; |
| 3906 } |
| 3907 } |
| 3908 |
| 3909 @reflectiveTest |
| 3910 class GenerateDartHintsTaskTest extends EngineTestCase { |
| 3911 void test_accept() { |
| 3912 GenerateDartHintsTask task = new GenerateDartHintsTask(null, null, null); |
| 3913 expect(task.accept(new GenerateDartHintsTaskTestTV_accept()), isTrue); |
| 3914 } |
| 3915 |
| 3916 void test_getException() { |
| 3917 GenerateDartHintsTask task = new GenerateDartHintsTask(null, null, null); |
| 3918 expect(task.exception, isNull); |
| 3919 } |
| 3920 |
| 3921 void test_getHintMap() { |
| 3922 GenerateDartHintsTask task = new GenerateDartHintsTask(null, null, null); |
| 3923 expect(task.hintMap, isNull); |
| 3924 } |
| 3925 |
| 3926 void test_getLibraryElement() { |
| 3927 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 3928 LibraryElement element = ElementFactory.library(context, "lib"); |
| 3929 GenerateDartHintsTask task = |
| 3930 new GenerateDartHintsTask(context, null, element); |
| 3931 expect(task.libraryElement, same(element)); |
| 3932 } |
| 3933 |
| 3934 void test_perform() { |
| 3935 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 3936 ChangeSet changeSet = new ChangeSet(); |
| 3937 Source librarySource = |
| 3938 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 3939 changeSet.addedSource(librarySource); |
| 3940 Source unusedSource = |
| 3941 new FileBasedSource(FileUtilities2.createFile("/unused.dart")); |
| 3942 changeSet.addedSource(unusedSource); |
| 3943 Source partSource = |
| 3944 new FileBasedSource(FileUtilities2.createFile("/part.dart")); |
| 3945 changeSet.addedSource(partSource); |
| 3946 context.applyChanges(changeSet); |
| 3947 context.setContents( |
| 3948 librarySource, |
| 3949 r''' |
| 3950 library lib; |
| 3951 import 'unused.dart'; |
| 3952 part 'part.dart';'''); |
| 3953 context.setContents(unusedSource, "library unused;"); |
| 3954 context.setContents(partSource, "part of lib;"); |
| 3955 List<TimestampedData<CompilationUnit>> units = new List<TimestampedData>(2); |
| 3956 units[0] = new TimestampedData<CompilationUnit>( |
| 3957 context.getModificationStamp(librarySource), |
| 3958 context.resolveCompilationUnit2(librarySource, librarySource)); |
| 3959 units[1] = new TimestampedData<CompilationUnit>( |
| 3960 context.getModificationStamp(partSource), |
| 3961 context.resolveCompilationUnit2(partSource, librarySource)); |
| 3962 GenerateDartHintsTask task = new GenerateDartHintsTask( |
| 3963 context, units, context.computeLibraryElement(librarySource)); |
| 3964 task.perform( |
| 3965 new GenerateDartHintsTaskTestTV_perform(librarySource, partSource)); |
| 3966 } |
| 3967 } |
| 3968 |
| 3969 class GenerateDartHintsTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 3970 @override |
| 3971 bool visitGenerateDartHintsTask(GenerateDartHintsTask task) => true; |
| 3972 } |
| 3973 |
| 3974 class GenerateDartHintsTaskTestTV_perform extends TestTaskVisitor<bool> { |
| 3975 Source librarySource; |
| 3976 Source partSource; |
| 3977 GenerateDartHintsTaskTestTV_perform(this.librarySource, this.partSource); |
| 3978 @override |
| 3979 bool visitGenerateDartHintsTask(GenerateDartHintsTask task) { |
| 3980 CaughtException exception = task.exception; |
| 3981 if (exception != null) { |
| 3982 throw exception; |
| 3983 } |
| 3984 expect(task.libraryElement, isNotNull); |
| 3985 HashMap<Source, List<AnalysisError>> hintMap = task.hintMap; |
| 3986 expect(hintMap, hasLength(2)); |
| 3987 expect(hintMap[librarySource], hasLength(1)); |
| 3988 expect(hintMap[partSource], hasLength(0)); |
| 3989 return true; |
| 3990 } |
| 3991 } |
| 3992 |
| 3993 @reflectiveTest |
| 3994 class GenerateDartLintsTaskTest extends EngineTestCase { |
| 3995 void test_accept() { |
| 3996 GenerateDartLintsTask task = new GenerateDartLintsTask(null, null, null); |
| 3997 expect(task.accept(new GenerateDartLintsTaskTestTV_accept()), isTrue); |
| 3998 } |
| 3999 |
| 4000 void test_exception() { |
| 4001 GenerateDartLintsTask task = new GenerateDartLintsTask(null, null, null); |
| 4002 expect(task.exception, isNull); |
| 4003 } |
| 4004 |
| 4005 void test_libraryElement() { |
| 4006 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4007 LibraryElement element = ElementFactory.library(context, "lib"); |
| 4008 GenerateDartLintsTask task = |
| 4009 new GenerateDartLintsTask(context, null, element); |
| 4010 expect(task.libraryElement, same(element)); |
| 4011 } |
| 4012 |
| 4013 void test_lintMap() { |
| 4014 GenerateDartLintsTask task = new GenerateDartLintsTask(null, null, null); |
| 4015 expect(task.lintMap, isNull); |
| 4016 } |
| 4017 |
| 4018 void test_perform() { |
| 4019 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4020 ChangeSet changeSet = new ChangeSet(); |
| 4021 Source librarySource = |
| 4022 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 4023 changeSet.addedSource(librarySource); |
| 4024 context.applyChanges(changeSet); |
| 4025 context.setContents( |
| 4026 librarySource, |
| 4027 r''' |
| 4028 library lib; |
| 4029 '''); |
| 4030 List<TimestampedData<CompilationUnit>> units = new List<TimestampedData>(1); |
| 4031 units[0] = new TimestampedData<CompilationUnit>( |
| 4032 context.getModificationStamp(librarySource), |
| 4033 context.resolveCompilationUnit2(librarySource, librarySource)); |
| 4034 GenerateDartLintsTask task = new GenerateDartLintsTask( |
| 4035 context, units, context.computeLibraryElement(librarySource)); |
| 4036 task.perform(new GenerateDartLintsTaskTestTV_perform(librarySource)); |
| 4037 } |
| 4038 } |
| 4039 |
| 4040 class GenerateDartLintsTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 4041 @override |
| 4042 bool visitGenerateDartLintsTask(GenerateDartLintsTask task) => true; |
| 4043 } |
| 4044 |
| 4045 class GenerateDartLintsTaskTestTV_perform extends TestTaskVisitor<bool> { |
| 4046 Source librarySource; |
| 4047 GenerateDartLintsTaskTestTV_perform(this.librarySource); |
| 4048 @override |
| 4049 bool visitGenerateDartLintsTask(GenerateDartLintsTask task) { |
| 4050 CaughtException exception = task.exception; |
| 4051 if (exception != null) { |
| 4052 throw exception; |
| 4053 } |
| 4054 expect(task.libraryElement, isNotNull); |
| 4055 return true; |
| 4056 } |
| 4057 } |
| 4058 |
| 4059 @reflectiveTest |
| 4060 class GetContentTaskTest extends EngineTestCase { |
| 4061 void test_accept() { |
| 4062 Source source = new TestSource('/test.dart', ''); |
| 4063 GetContentTask task = new GetContentTask(null, source); |
| 4064 expect(task.accept(new GetContentTaskTestTV_accept()), isTrue); |
| 4065 } |
| 4066 |
| 4067 void test_getException() { |
| 4068 Source source = new TestSource('/test.dart', ''); |
| 4069 GetContentTask task = new GetContentTask(null, source); |
| 4070 expect(task.exception, isNull); |
| 4071 } |
| 4072 |
| 4073 void test_getModificationTime() { |
| 4074 Source source = new TestSource('/test.dart', ''); |
| 4075 GetContentTask task = new GetContentTask(null, source); |
| 4076 expect(task.modificationTime, -1); |
| 4077 } |
| 4078 |
| 4079 void test_getSource() { |
| 4080 Source source = new TestSource('/test.dart', ''); |
| 4081 GetContentTask task = new GetContentTask(null, source); |
| 4082 expect(task.source, same(source)); |
| 4083 } |
| 4084 |
| 4085 void test_perform_exception() { |
| 4086 TestSource source = new TestSource(); |
| 4087 source.generateExceptionOnRead = true; |
| 4088 // final InternalAnalysisContext context = new AnalysisContextImpl(); |
| 4089 // context.setSourceFactory(new SourceFactory(new FileUriResolver())); |
| 4090 GetContentTask task = new GetContentTask(null, source); |
| 4091 task.perform(new GetContentTaskTestTV_perform_exception()); |
| 4092 } |
| 4093 |
| 4094 void test_perform_valid() { |
| 4095 Source source = new TestSource('/test.dart', 'class A {}'); |
| 4096 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4097 GetContentTask task = new GetContentTask(context, source); |
| 4098 task.perform(new GetContentTaskTestTV_perform_valid(context, source)); |
| 4099 } |
| 4100 } |
| 4101 |
| 4102 class GetContentTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 4103 @override |
| 4104 bool visitGetContentTask(GetContentTask task) => true; |
| 4105 } |
| 4106 |
| 4107 class GetContentTaskTestTV_perform_exception extends TestTaskVisitor<bool> { |
| 4108 @override |
| 4109 bool visitGetContentTask(GetContentTask task) { |
| 4110 expect(task.exception, isNotNull); |
| 4111 return true; |
| 4112 } |
| 4113 } |
| 4114 |
| 4115 class GetContentTaskTestTV_perform_valid extends TestTaskVisitor<bool> { |
| 4116 InternalAnalysisContext context; |
| 4117 Source source; |
| 4118 GetContentTaskTestTV_perform_valid(this.context, this.source); |
| 4119 @override |
| 4120 bool visitGetContentTask(GetContentTask task) { |
| 4121 CaughtException exception = task.exception; |
| 4122 if (exception != null) { |
| 4123 throw exception; |
| 4124 } |
| 4125 expect(task.modificationTime, context.getModificationStamp(source)); |
| 4126 expect(task.source, same(source)); |
| 4127 return true; |
| 4128 } |
| 4129 } |
| 4130 |
| 4131 @reflectiveTest |
| 4132 class HtmlEntryTest extends EngineTestCase { |
| 4133 void set state(DataDescriptor descriptor) { |
| 4134 HtmlEntry entry = new HtmlEntry(); |
| 4135 expect(entry.getState(descriptor), isNot(same(CacheState.FLUSHED))); |
| 4136 entry.setState(descriptor, CacheState.FLUSHED); |
| 4137 expect(entry.getState(descriptor), same(CacheState.FLUSHED)); |
| 4138 } |
| 4139 |
| 4140 void test_creation() { |
| 4141 HtmlEntry entry = new HtmlEntry(); |
| 4142 expect(entry, isNotNull); |
| 4143 } |
| 4144 |
| 4145 void test_getAllErrors() { |
| 4146 Source source = new TestSource(); |
| 4147 HtmlEntry entry = new HtmlEntry(); |
| 4148 expect(entry.allErrors, hasLength(0)); |
| 4149 entry.setValue(HtmlEntry.PARSE_ERRORS, <AnalysisError>[ |
| 4150 new AnalysisError(source, 0, 0, ParserErrorCode.EXPECTED_TOKEN, [";"]) |
| 4151 ]); |
| 4152 entry.setValue(HtmlEntry.RESOLUTION_ERRORS, <AnalysisError>[ |
| 4153 new AnalysisError(source, 0, 0, HtmlWarningCode.INVALID_URI, ["-"]) |
| 4154 ]); |
| 4155 entry.setValue(HtmlEntry.HINTS, |
| 4156 <AnalysisError>[new AnalysisError(source, 0, 0, HintCode.DEAD_CODE)]); |
| 4157 expect(entry.allErrors, hasLength(3)); |
| 4158 } |
| 4159 |
| 4160 void test_invalidateAllResolutionInformation() { |
| 4161 HtmlEntry entry = _entryWithValidState(); |
| 4162 entry.invalidateAllResolutionInformation(false); |
| 4163 expect(entry.getState(HtmlEntry.ELEMENT), same(CacheState.INVALID)); |
| 4164 expect(entry.getState(HtmlEntry.HINTS), same(CacheState.INVALID)); |
| 4165 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 4166 expect(entry.getState(HtmlEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 4167 expect(entry.getState(HtmlEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 4168 expect( |
| 4169 entry.getState(HtmlEntry.REFERENCED_LIBRARIES), same(CacheState.VALID)); |
| 4170 expect( |
| 4171 entry.getState(HtmlEntry.RESOLUTION_ERRORS), same(CacheState.INVALID)); |
| 4172 } |
| 4173 |
| 4174 void test_invalidateAllResolutionInformation_includingUris() { |
| 4175 HtmlEntry entry = _entryWithValidState(); |
| 4176 entry.invalidateAllResolutionInformation(true); |
| 4177 expect(entry.getState(HtmlEntry.ELEMENT), same(CacheState.INVALID)); |
| 4178 expect(entry.getState(HtmlEntry.HINTS), same(CacheState.INVALID)); |
| 4179 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 4180 expect(entry.getState(HtmlEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 4181 expect(entry.getState(HtmlEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 4182 expect(entry.getState(HtmlEntry.REFERENCED_LIBRARIES), |
| 4183 same(CacheState.INVALID)); |
| 4184 expect( |
| 4185 entry.getState(HtmlEntry.RESOLUTION_ERRORS), same(CacheState.INVALID)); |
| 4186 } |
| 4187 |
| 4188 void test_setState_element() { |
| 4189 state = HtmlEntry.ELEMENT; |
| 4190 } |
| 4191 |
| 4192 void test_setState_hints() { |
| 4193 state = HtmlEntry.HINTS; |
| 4194 } |
| 4195 |
| 4196 void test_setState_lineInfo() { |
| 4197 state = SourceEntry.LINE_INFO; |
| 4198 } |
| 4199 |
| 4200 void test_setState_parsedUnit() { |
| 4201 state = HtmlEntry.PARSED_UNIT; |
| 4202 } |
| 4203 |
| 4204 void test_setState_parseErrors() { |
| 4205 state = HtmlEntry.PARSE_ERRORS; |
| 4206 } |
| 4207 |
| 4208 void test_setState_referencedLibraries() { |
| 4209 state = HtmlEntry.REFERENCED_LIBRARIES; |
| 4210 } |
| 4211 |
| 4212 void test_setState_resolutionErrors() { |
| 4213 state = HtmlEntry.RESOLUTION_ERRORS; |
| 4214 } |
| 4215 |
| 4216 void test_setValue_element() { |
| 4217 _setValue(HtmlEntry.ELEMENT, new HtmlElementImpl(null, "test.html")); |
| 4218 } |
| 4219 |
| 4220 void test_setValue_hints() { |
| 4221 _setValue(HtmlEntry.HINTS, |
| 4222 <AnalysisError>[new AnalysisError(null, 0, 0, HintCode.DEAD_CODE)]); |
| 4223 } |
| 4224 |
| 4225 void test_setValue_illegal() { |
| 4226 HtmlEntry entry = new HtmlEntry(); |
| 4227 try { |
| 4228 entry.setValue(DartEntry.ELEMENT, null); |
| 4229 fail("Expected ArgumentError for DartEntry.ELEMENT"); |
| 4230 } on ArgumentError {} |
| 4231 } |
| 4232 |
| 4233 void test_setValue_lineInfo() { |
| 4234 _setValue(SourceEntry.LINE_INFO, new LineInfo(<int>[0])); |
| 4235 } |
| 4236 |
| 4237 void test_setValue_parsedUnit() { |
| 4238 _setValue(HtmlEntry.PARSED_UNIT, new ht.HtmlUnit(null, null, null)); |
| 4239 } |
| 4240 |
| 4241 void test_setValue_parseErrors() { |
| 4242 _setValue(HtmlEntry.PARSE_ERRORS, <AnalysisError>[ |
| 4243 new AnalysisError(null, 0, 0, HtmlWarningCode.INVALID_URI, ["-"]) |
| 4244 ]); |
| 4245 } |
| 4246 |
| 4247 void test_setValue_referencedLibraries() { |
| 4248 _setValue(HtmlEntry.REFERENCED_LIBRARIES, <Source>[new TestSource()]); |
| 4249 } |
| 4250 |
| 4251 void test_setValue_resolutionErrors() { |
| 4252 _setValue(HtmlEntry.RESOLUTION_ERRORS, <AnalysisError>[ |
| 4253 new AnalysisError(null, 0, 0, HtmlWarningCode.INVALID_URI, ["-"]) |
| 4254 ]); |
| 4255 } |
| 4256 |
| 4257 HtmlEntry _entryWithValidState() { |
| 4258 HtmlEntry entry = new HtmlEntry(); |
| 4259 entry.setValue(HtmlEntry.ELEMENT, null); |
| 4260 entry.setValue(HtmlEntry.HINTS, null); |
| 4261 entry.setValue(SourceEntry.LINE_INFO, null); |
| 4262 entry.setValue(HtmlEntry.PARSE_ERRORS, null); |
| 4263 entry.setValue(HtmlEntry.PARSED_UNIT, null); |
| 4264 entry.setValue(HtmlEntry.REFERENCED_LIBRARIES, null); |
| 4265 entry.setValue(HtmlEntry.RESOLUTION_ERRORS, null); |
| 4266 expect(entry.getState(HtmlEntry.ELEMENT), same(CacheState.VALID)); |
| 4267 expect(entry.getState(HtmlEntry.HINTS), same(CacheState.VALID)); |
| 4268 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); |
| 4269 expect(entry.getState(HtmlEntry.PARSE_ERRORS), same(CacheState.VALID)); |
| 4270 expect(entry.getState(HtmlEntry.PARSED_UNIT), same(CacheState.VALID)); |
| 4271 expect( |
| 4272 entry.getState(HtmlEntry.REFERENCED_LIBRARIES), same(CacheState.VALID)); |
| 4273 expect(entry.getState(HtmlEntry.RESOLUTION_ERRORS), same(CacheState.VALID)); |
| 4274 return entry; |
| 4275 } |
| 4276 |
| 4277 void _setValue(DataDescriptor descriptor, Object newValue) { |
| 4278 HtmlEntry entry = new HtmlEntry(); |
| 4279 Object value = entry.getValue(descriptor); |
| 4280 expect(newValue, isNot(same(value))); |
| 4281 entry.setValue(descriptor, newValue); |
| 4282 expect(entry.getState(descriptor), same(CacheState.VALID)); |
| 4283 expect(entry.getValue(descriptor), same(newValue)); |
| 4284 } |
| 4285 } |
| 4286 |
| 4287 @reflectiveTest |
| 4288 class IncrementalAnalysisCacheTest { |
| 4289 Source _source = new TestSource(); |
| 4290 DartEntry _entry = new DartEntry(); |
| 4291 CompilationUnit _unit = new CompilationUnitMock(); |
| 4292 IncrementalAnalysisCache _result; |
| 4293 void setUp() { |
| 4294 _entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, _unit); |
| 4295 } |
| 4296 |
| 4297 void test_cacheResult() { |
| 4298 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4299 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4300 CompilationUnit newUnit = new CompilationUnitMock(); |
| 4301 _result = IncrementalAnalysisCache.cacheResult(cache, newUnit); |
| 4302 expect(_result, isNotNull); |
| 4303 expect(_result.source, same(_source)); |
| 4304 expect(_result.resolvedUnit, same(newUnit)); |
| 4305 expect(_result.oldContents, "hbazlo"); |
| 4306 expect(_result.newContents, "hbazlo"); |
| 4307 expect(_result.offset, 0); |
| 4308 expect(_result.oldLength, 0); |
| 4309 expect(_result.newLength, 0); |
| 4310 } |
| 4311 |
| 4312 void test_cacheResult_noCache() { |
| 4313 IncrementalAnalysisCache cache = null; |
| 4314 CompilationUnit newUnit = new CompilationUnitMock(); |
| 4315 _result = IncrementalAnalysisCache.cacheResult(cache, newUnit); |
| 4316 expect(_result, isNull); |
| 4317 } |
| 4318 |
| 4319 void test_cacheResult_noCacheNoResult() { |
| 4320 IncrementalAnalysisCache cache = null; |
| 4321 CompilationUnit newUnit = null; |
| 4322 _result = IncrementalAnalysisCache.cacheResult(cache, newUnit); |
| 4323 expect(_result, isNull); |
| 4324 } |
| 4325 |
| 4326 void test_cacheResult_noResult() { |
| 4327 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4328 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4329 CompilationUnit newUnit = null; |
| 4330 _result = IncrementalAnalysisCache.cacheResult(cache, newUnit); |
| 4331 expect(_result, isNull); |
| 4332 } |
| 4333 |
| 4334 void test_clear_differentSource() { |
| 4335 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4336 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4337 Source otherSource = new TestSource("blat.dart", "blat"); |
| 4338 _result = IncrementalAnalysisCache.clear(cache, otherSource); |
| 4339 expect(_result, same(cache)); |
| 4340 } |
| 4341 |
| 4342 void test_clear_nullCache() { |
| 4343 IncrementalAnalysisCache cache = null; |
| 4344 _result = IncrementalAnalysisCache.clear(cache, _source); |
| 4345 expect(_result, isNull); |
| 4346 } |
| 4347 |
| 4348 void test_clear_sameSource() { |
| 4349 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4350 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4351 _result = IncrementalAnalysisCache.clear(cache, _source); |
| 4352 expect(_result, isNull); |
| 4353 } |
| 4354 |
| 4355 void test_update_append() { |
| 4356 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4357 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4358 DartEntry newEntry = new DartEntry(); |
| 4359 _result = IncrementalAnalysisCache.update( |
| 4360 cache, _source, "hbazlo", "hbazxlo", 4, 0, 1, newEntry); |
| 4361 expect(_result, isNotNull); |
| 4362 expect(_result.source, same(_source)); |
| 4363 expect(_result.resolvedUnit, same(_unit)); |
| 4364 expect(_result.oldContents, "hello"); |
| 4365 expect(_result.newContents, "hbazxlo"); |
| 4366 expect(_result.offset, 1); |
| 4367 expect(_result.oldLength, 2); |
| 4368 expect(_result.newLength, 4); |
| 4369 } |
| 4370 |
| 4371 void test_update_appendToCachedResult() { |
| 4372 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4373 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4374 CompilationUnit newUnit = new CompilationUnitMock(); |
| 4375 cache = IncrementalAnalysisCache.cacheResult(cache, newUnit); |
| 4376 expect(cache, isNotNull); |
| 4377 DartEntry newEntry = new DartEntry(); |
| 4378 _result = IncrementalAnalysisCache.update( |
| 4379 cache, _source, "hbazlo", "hbazxlo", 4, 0, 1, newEntry); |
| 4380 expect(_result, isNotNull); |
| 4381 expect(_result.source, same(_source)); |
| 4382 expect(_result.resolvedUnit, same(newUnit)); |
| 4383 expect(_result.oldContents, "hbazlo"); |
| 4384 expect(_result.newContents, "hbazxlo"); |
| 4385 expect(_result.offset, 4); |
| 4386 expect(_result.oldLength, 0); |
| 4387 expect(_result.newLength, 1); |
| 4388 } |
| 4389 |
| 4390 void test_update_appendWithNewResolvedUnit() { |
| 4391 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4392 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4393 DartEntry newEntry = new DartEntry(); |
| 4394 CompilationUnit newUnit = new CompilationUnitMock(); |
| 4395 newEntry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, newUnit); |
| 4396 _result = IncrementalAnalysisCache.update( |
| 4397 cache, _source, "hbazlo", "hbazxlo", 4, 0, 1, newEntry); |
| 4398 expect(_result, isNotNull); |
| 4399 expect(_result.source, same(_source)); |
| 4400 expect(_result.resolvedUnit, same(newUnit)); |
| 4401 expect(_result.oldContents, "hbazlo"); |
| 4402 expect(_result.newContents, "hbazxlo"); |
| 4403 expect(_result.offset, 4); |
| 4404 expect(_result.oldLength, 0); |
| 4405 expect(_result.newLength, 1); |
| 4406 } |
| 4407 |
| 4408 void test_update_appendWithNoNewResolvedUnit() { |
| 4409 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4410 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4411 DartEntry newEntry = new DartEntry(); |
| 4412 _result = IncrementalAnalysisCache.update( |
| 4413 cache, _source, "hbazlo", "hbazxlo", 4, 0, 1, newEntry); |
| 4414 expect(_result, isNotNull); |
| 4415 expect(_result.source, same(_source)); |
| 4416 expect(_result.resolvedUnit, same(_unit)); |
| 4417 expect(_result.oldContents, "hello"); |
| 4418 expect(_result.newContents, "hbazxlo"); |
| 4419 expect(_result.offset, 1); |
| 4420 expect(_result.oldLength, 2); |
| 4421 expect(_result.newLength, 4); |
| 4422 } |
| 4423 |
| 4424 void test_update_delete() { |
| 4425 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4426 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4427 DartEntry newEntry = new DartEntry(); |
| 4428 _result = IncrementalAnalysisCache.update( |
| 4429 cache, _source, "hbazlo", "hzlo", 1, 2, 0, newEntry); |
| 4430 expect(_result, isNotNull); |
| 4431 expect(_result.source, same(_source)); |
| 4432 expect(_result.resolvedUnit, same(_unit)); |
| 4433 expect(_result.oldContents, "hello"); |
| 4434 expect(_result.newContents, "hzlo"); |
| 4435 expect(_result.offset, 1); |
| 4436 expect(_result.oldLength, 2); |
| 4437 expect(_result.newLength, 1); |
| 4438 } |
| 4439 |
| 4440 void test_update_insert_nonContiguous_after() { |
| 4441 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4442 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4443 DartEntry newEntry = new DartEntry(); |
| 4444 _result = IncrementalAnalysisCache.update( |
| 4445 cache, _source, "hbazlo", "hbazlox", 6, 0, 1, newEntry); |
| 4446 expect(_result, isNull); |
| 4447 } |
| 4448 |
| 4449 void test_update_insert_nonContiguous_before() { |
| 4450 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4451 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4452 DartEntry newEntry = new DartEntry(); |
| 4453 _result = IncrementalAnalysisCache.update( |
| 4454 cache, _source, "hbazlo", "xhbazlo", 0, 0, 1, newEntry); |
| 4455 expect(_result, isNull); |
| 4456 } |
| 4457 |
| 4458 void test_update_newSource_entry() { |
| 4459 Source oldSource = new TestSource("blat.dart", "blat"); |
| 4460 DartEntry oldEntry = new DartEntry(); |
| 4461 CompilationUnit oldUnit = new CompilationUnitMock(); |
| 4462 oldEntry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, oldUnit); |
| 4463 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4464 null, oldSource, "hello", "hbazlo", 1, 2, 3, oldEntry); |
| 4465 expect(cache.source, same(oldSource)); |
| 4466 expect(cache.resolvedUnit, same(oldUnit)); |
| 4467 _result = IncrementalAnalysisCache.update( |
| 4468 cache, _source, "foo", "foobz", 3, 0, 2, _entry); |
| 4469 expect(_result, isNotNull); |
| 4470 expect(_result.source, same(_source)); |
| 4471 expect(_result.resolvedUnit, same(_unit)); |
| 4472 expect(_result.oldContents, "foo"); |
| 4473 expect(_result.newContents, "foobz"); |
| 4474 expect(_result.offset, 3); |
| 4475 expect(_result.oldLength, 0); |
| 4476 expect(_result.newLength, 2); |
| 4477 } |
| 4478 |
| 4479 void test_update_newSource_noEntry() { |
| 4480 Source oldSource = new TestSource("blat.dart", "blat"); |
| 4481 DartEntry oldEntry = new DartEntry(); |
| 4482 CompilationUnit oldUnit = new CompilationUnitMock(); |
| 4483 oldEntry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, oldUnit); |
| 4484 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4485 null, oldSource, "hello", "hbazlo", 1, 2, 3, oldEntry); |
| 4486 expect(cache.source, same(oldSource)); |
| 4487 expect(cache.resolvedUnit, same(oldUnit)); |
| 4488 _result = IncrementalAnalysisCache.update( |
| 4489 cache, _source, "foo", "foobar", 3, 0, 3, null); |
| 4490 expect(_result, isNull); |
| 4491 } |
| 4492 |
| 4493 void test_update_noCache_entry() { |
| 4494 _result = IncrementalAnalysisCache.update( |
| 4495 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4496 expect(_result, isNotNull); |
| 4497 expect(_result.source, same(_source)); |
| 4498 expect(_result.resolvedUnit, same(_unit)); |
| 4499 expect(_result.oldContents, "hello"); |
| 4500 expect(_result.newContents, "hbazlo"); |
| 4501 expect(_result.offset, 1); |
| 4502 expect(_result.oldLength, 2); |
| 4503 expect(_result.newLength, 3); |
| 4504 expect(_result.hasWork, isTrue); |
| 4505 } |
| 4506 |
| 4507 void test_update_noCache_entry_noOldSource_append() { |
| 4508 _result = IncrementalAnalysisCache.update( |
| 4509 null, _source, null, "hellxo", 4, 0, 1, _entry); |
| 4510 expect(_result, isNotNull); |
| 4511 expect(_result.source, same(_source)); |
| 4512 expect(_result.resolvedUnit, same(_unit)); |
| 4513 expect(_result.oldContents, "hello"); |
| 4514 expect(_result.newContents, "hellxo"); |
| 4515 expect(_result.offset, 4); |
| 4516 expect(_result.oldLength, 0); |
| 4517 expect(_result.newLength, 1); |
| 4518 expect(_result.hasWork, isTrue); |
| 4519 } |
| 4520 |
| 4521 void test_update_noCache_entry_noOldSource_delete() { |
| 4522 _result = IncrementalAnalysisCache.update( |
| 4523 null, _source, null, "helo", 4, 1, 0, _entry); |
| 4524 expect(_result, isNull); |
| 4525 } |
| 4526 |
| 4527 void test_update_noCache_entry_noOldSource_replace() { |
| 4528 _result = IncrementalAnalysisCache.update( |
| 4529 null, _source, null, "helxo", 4, 1, 1, _entry); |
| 4530 expect(_result, isNull); |
| 4531 } |
| 4532 |
| 4533 void test_update_noCache_noEntry() { |
| 4534 _result = IncrementalAnalysisCache.update( |
| 4535 null, _source, "hello", "hbazlo", 1, 2, 3, null); |
| 4536 expect(_result, isNull); |
| 4537 } |
| 4538 |
| 4539 void test_update_replace() { |
| 4540 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4541 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4542 _result = IncrementalAnalysisCache.update( |
| 4543 cache, _source, "hbazlo", "hbarrlo", 3, 1, 2, null); |
| 4544 expect(_result, isNotNull); |
| 4545 expect(_result.source, same(_source)); |
| 4546 expect(_result.resolvedUnit, same(_unit)); |
| 4547 expect(_result.oldContents, "hello"); |
| 4548 expect(_result.newContents, "hbarrlo"); |
| 4549 expect(_result.offset, 1); |
| 4550 expect(_result.oldLength, 2); |
| 4551 expect(_result.newLength, 4); |
| 4552 } |
| 4553 |
| 4554 void test_verifyStructure_invalidUnit() { |
| 4555 String oldCode = "main() {foo;}"; |
| 4556 String newCode = "main() {boo;}"; |
| 4557 CompilationUnit badUnit = _parse("main() {bad;}"); |
| 4558 _entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, badUnit); |
| 4559 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4560 null, _source, oldCode, newCode, 8, 1, 1, _entry); |
| 4561 CompilationUnit newUnit = _parse(newCode); |
| 4562 _result = IncrementalAnalysisCache.verifyStructure(cache, _source, newUnit); |
| 4563 expect(_result, isNull); |
| 4564 } |
| 4565 |
| 4566 void test_verifyStructure_noCache() { |
| 4567 IncrementalAnalysisCache cache = null; |
| 4568 CompilationUnit newUnit = new CompilationUnitMock(); |
| 4569 _result = IncrementalAnalysisCache.verifyStructure(cache, _source, newUnit); |
| 4570 expect(_result, isNull); |
| 4571 } |
| 4572 |
| 4573 void test_verifyStructure_noCacheNoUnit() { |
| 4574 IncrementalAnalysisCache cache = null; |
| 4575 CompilationUnit newUnit = null; |
| 4576 _result = IncrementalAnalysisCache.verifyStructure(cache, _source, newUnit); |
| 4577 expect(_result, isNull); |
| 4578 } |
| 4579 |
| 4580 void test_verifyStructure_noUnit() { |
| 4581 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4582 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4583 CompilationUnit newUnit = null; |
| 4584 _result = IncrementalAnalysisCache.verifyStructure(cache, _source, newUnit); |
| 4585 expect(_result, same(cache)); |
| 4586 expect(_result.resolvedUnit, same(_unit)); |
| 4587 } |
| 4588 |
| 4589 void test_verifyStructure_otherSource() { |
| 4590 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4591 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); |
| 4592 CompilationUnit newUnit = new CompilationUnitMock(); |
| 4593 Source otherSource = new TestSource("blat.dart", "blat"); |
| 4594 _result = |
| 4595 IncrementalAnalysisCache.verifyStructure(cache, otherSource, newUnit); |
| 4596 expect(_result, same(cache)); |
| 4597 expect(_result.resolvedUnit, same(_unit)); |
| 4598 } |
| 4599 |
| 4600 void test_verifyStructure_validUnit() { |
| 4601 String oldCode = "main() {foo;}"; |
| 4602 String newCode = "main() {boo;}"; |
| 4603 CompilationUnit goodUnit = _parse(newCode); |
| 4604 _entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, goodUnit); |
| 4605 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4606 null, _source, oldCode, newCode, 1, 2, 3, _entry); |
| 4607 CompilationUnit newUnit = _parse(newCode); |
| 4608 _result = IncrementalAnalysisCache.verifyStructure(cache, _source, newUnit); |
| 4609 expect(_result, same(cache)); |
| 4610 expect(_result.resolvedUnit, same(goodUnit)); |
| 4611 } |
| 4612 |
| 4613 CompilationUnit _parse(String code) { |
| 4614 Scanner scanner = new Scanner(_source, new CharSequenceReader(code), |
| 4615 AnalysisErrorListener.NULL_LISTENER); |
| 4616 Parser parser = new Parser(_source, AnalysisErrorListener.NULL_LISTENER); |
| 4617 return parser.parseCompilationUnit(scanner.tokenize()); |
| 4618 } |
| 4619 } |
| 4620 |
| 4621 @reflectiveTest |
| 4622 class IncrementalAnalysisTaskTest extends EngineTestCase { |
| 4623 void test_accept() { |
| 4624 IncrementalAnalysisTask task = new IncrementalAnalysisTask(null, null); |
| 4625 expect(task.accept(new IncrementalAnalysisTaskTestTV_accept()), isTrue); |
| 4626 } |
| 4627 |
| 4628 void test_perform() { |
| 4629 // main() {} String foo; |
| 4630 // main() {String} String foo; |
| 4631 CompilationUnit newUnit = |
| 4632 _assertTask("main() {", "", "String", "} String foo;"); |
| 4633 NodeList<CompilationUnitMember> declarations = newUnit.declarations; |
| 4634 FunctionDeclaration main = declarations[0] as FunctionDeclaration; |
| 4635 expect(main.name.name, "main"); |
| 4636 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; |
| 4637 ExpressionStatement statement = |
| 4638 body.block.statements[0] as ExpressionStatement; |
| 4639 expect(statement.toSource(), "String;"); |
| 4640 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| 4641 expect(identifier.name, "String"); |
| 4642 expect(identifier.staticElement, isNotNull); |
| 4643 TopLevelVariableDeclaration fooDecl = |
| 4644 declarations[1] as TopLevelVariableDeclaration; |
| 4645 SimpleIdentifier fooName = fooDecl.variables.variables[0].name; |
| 4646 expect(fooName.name, "foo"); |
| 4647 expect(fooName.staticElement, isNotNull); |
| 4648 // assert element reference is preserved |
| 4649 } |
| 4650 |
| 4651 CompilationUnit _assertTask( |
| 4652 String prefix, String removed, String added, String suffix) { |
| 4653 String oldCode = "$prefix$removed$suffix"; |
| 4654 String newCode = "$prefix$added$suffix"; |
| 4655 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4656 Source source = new TestSource("/test.dart", oldCode); |
| 4657 DartEntry entry = new DartEntry(); |
| 4658 CompilationUnit oldUnit = context.resolveCompilationUnit2(source, source); |
| 4659 expect(oldUnit, isNotNull); |
| 4660 entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, source, oldUnit); |
| 4661 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( |
| 4662 null, |
| 4663 source, |
| 4664 oldCode, |
| 4665 newCode, |
| 4666 prefix.length, |
| 4667 removed.length, |
| 4668 added.length, |
| 4669 entry); |
| 4670 expect(cache, isNotNull); |
| 4671 IncrementalAnalysisTask task = new IncrementalAnalysisTask(context, cache); |
| 4672 CompilationUnit newUnit = |
| 4673 task.perform(new IncrementalAnalysisTaskTestTV_assertTask(task)); |
| 4674 expect(newUnit, isNotNull); |
| 4675 return newUnit; |
| 4676 } |
| 4677 } |
| 4678 |
| 4679 class IncrementalAnalysisTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 4680 @override |
| 4681 bool visitIncrementalAnalysisTask(IncrementalAnalysisTask task) => true; |
| 4682 } |
| 4683 |
| 4684 class IncrementalAnalysisTaskTestTV_assertTask |
| 4685 extends TestTaskVisitor<CompilationUnit> { |
| 4686 IncrementalAnalysisTask task; |
| 4687 IncrementalAnalysisTaskTestTV_assertTask(this.task); |
| 4688 @override |
| 4689 CompilationUnit visitIncrementalAnalysisTask( |
| 4690 IncrementalAnalysisTask incrementalAnalysisTask) => |
| 4691 task.compilationUnit; |
| 4692 } |
| 4693 |
| 4694 @reflectiveTest |
| 4695 class LintGeneratorTest extends EngineTestCase { |
| 4696 void test_generate() { |
| 4697 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4698 ChangeSet changeSet = new ChangeSet(); |
| 4699 Source librarySource = |
| 4700 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 4701 changeSet.addedSource(librarySource); |
| 4702 context.applyChanges(changeSet); |
| 4703 context.setContents( |
| 4704 librarySource, |
| 4705 r''' |
| 4706 library lib; |
| 4707 '''); |
| 4708 |
| 4709 CompilationUnit unit = |
| 4710 context.resolveCompilationUnit2(librarySource, librarySource); |
| 4711 List<CompilationUnit> units = <CompilationUnit>[]; |
| 4712 units.add(unit); |
| 4713 |
| 4714 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 4715 |
| 4716 LintGeneratorTest_Linter linter = new LintGeneratorTest_Linter(); |
| 4717 |
| 4718 LintGenerator lintGenerator = |
| 4719 new LintGenerator(units, errorListener, [linter]); |
| 4720 lintGenerator.generate(); |
| 4721 |
| 4722 linter.testExpectations(); |
| 4723 } |
| 4724 |
| 4725 void test_generate_null_visitor() { |
| 4726 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4727 ChangeSet changeSet = new ChangeSet(); |
| 4728 Source librarySource = |
| 4729 new FileBasedSource(FileUtilities2.createFile("/test.dart")); |
| 4730 changeSet.addedSource(librarySource); |
| 4731 context.applyChanges(changeSet); |
| 4732 context.setContents( |
| 4733 librarySource, |
| 4734 r''' |
| 4735 library lib; |
| 4736 '''); |
| 4737 |
| 4738 CompilationUnit unit = |
| 4739 context.resolveCompilationUnit2(librarySource, librarySource); |
| 4740 List<CompilationUnit> units = <CompilationUnit>[]; |
| 4741 units.add(unit); |
| 4742 |
| 4743 RecordingErrorListener errorListener = new RecordingErrorListener(); |
| 4744 |
| 4745 Linter badLinter = new LintGeneratorTest_Linter_Null_Visitor(); |
| 4746 LintGeneratorTest_Linter goodLinter = new LintGeneratorTest_Linter(); |
| 4747 |
| 4748 LintGenerator lintGenerator = |
| 4749 new LintGenerator(units, errorListener, [badLinter, goodLinter]); |
| 4750 // Test that generate does not fall down with a null visitor |
| 4751 lintGenerator.generate(); |
| 4752 // Well-formed linter should still get called |
| 4753 goodLinter.testExpectations(); |
| 4754 } |
| 4755 } |
| 4756 |
| 4757 class LintGeneratorTest_Linter extends Linter with SimpleAstVisitor<Object> { |
| 4758 bool visited; |
| 4759 |
| 4760 @override |
| 4761 AstVisitor getVisitor() => this; |
| 4762 |
| 4763 testExpectations() { |
| 4764 expect(reporter, isNotNull); |
| 4765 expect(visited, isTrue); |
| 4766 } |
| 4767 |
| 4768 @override |
| 4769 Object visitCompilationUnit(CompilationUnit node) { |
| 4770 visited = true; |
| 4771 return null; |
| 4772 } |
| 4773 } |
| 4774 |
| 4775 class LintGeneratorTest_Linter_Null_Visitor extends Linter { |
| 4776 @override |
| 4777 AstVisitor getVisitor() => null; |
| 4778 } |
| 4779 |
| 4780 class MockSourceFactory extends SourceFactory { |
| 4781 MockSourceFactory() : super([]); |
| 4782 Source resolveUri(Source containingSource, String containedUri) { |
| 4783 throw new JavaIOException(); |
| 4784 } |
| 4785 } |
| 4786 |
| 4787 @reflectiveTest |
| 4788 class ParseDartTaskTest extends EngineTestCase { |
| 4789 void test_accept() { |
| 4790 ParseDartTask task = new ParseDartTask(null, null, null, null); |
| 4791 expect(task.accept(new ParseDartTaskTestTV_accept()), isTrue); |
| 4792 } |
| 4793 |
| 4794 void test_getCompilationUnit() { |
| 4795 ParseDartTask task = new ParseDartTask(null, null, null, null); |
| 4796 expect(task.compilationUnit, isNull); |
| 4797 } |
| 4798 |
| 4799 void test_getErrors() { |
| 4800 ParseDartTask task = new ParseDartTask(null, null, null, null); |
| 4801 expect(task.errors, hasLength(0)); |
| 4802 } |
| 4803 |
| 4804 void test_getException() { |
| 4805 ParseDartTask task = new ParseDartTask(null, null, null, null); |
| 4806 expect(task.exception, isNull); |
| 4807 } |
| 4808 |
| 4809 void test_getSource() { |
| 4810 Source source = new TestSource('/test.dart'); |
| 4811 ParseDartTask task = new ParseDartTask(null, source, null, null); |
| 4812 expect(task.source, same(source)); |
| 4813 } |
| 4814 |
| 4815 void test_hasNonPartOfDirective() { |
| 4816 ParseDartTask task = new ParseDartTask(null, null, null, null); |
| 4817 expect(task.hasNonPartOfDirective, isFalse); |
| 4818 } |
| 4819 |
| 4820 void test_hasPartOfDirective() { |
| 4821 ParseDartTask task = new ParseDartTask(null, null, null, null); |
| 4822 expect(task.hasPartOfDirective, isFalse); |
| 4823 } |
| 4824 |
| 4825 void test_perform_exception() { |
| 4826 TestSource source = new TestSource(); |
| 4827 source.generateExceptionOnRead = true; |
| 4828 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4829 ParseDartTask task = new ParseDartTask(context, source, null, null); |
| 4830 task.perform(new ParseDartTaskTestTV_perform_exception()); |
| 4831 } |
| 4832 |
| 4833 void test_perform_library() { |
| 4834 String content = r''' |
| 4835 library lib; |
| 4836 import 'lib2.dart'; |
| 4837 export 'lib3.dart'; |
| 4838 part 'part.dart'; |
| 4839 class A {'''; |
| 4840 Source source = new TestSource('/test.dart', content); |
| 4841 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4842 ParseDartTask task = _createParseTask(context, source, content); |
| 4843 task.perform(new ParseDartTaskTestTV_perform_library(context, source)); |
| 4844 } |
| 4845 |
| 4846 void test_perform_part() { |
| 4847 String content = r''' |
| 4848 part of lib; |
| 4849 class B {}'''; |
| 4850 Source source = new TestSource('/test.dart', content); |
| 4851 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4852 ParseDartTask task = _createParseTask(context, source, content); |
| 4853 task.perform(new ParseDartTaskTestTV_perform_part(context, source)); |
| 4854 } |
| 4855 |
| 4856 void test_perform_validateDirectives() { |
| 4857 String content = r''' |
| 4858 library lib; |
| 4859 import '/does/not/exist.dart'; |
| 4860 import '://invaliduri.dart'; |
| 4861 export '${a}lib3.dart'; |
| 4862 part 'part.dart'; |
| 4863 class A {}'''; |
| 4864 Source source = new TestSource('/test.dart', content); |
| 4865 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4866 ParseDartTask task = _createParseTask(context, source, content); |
| 4867 task.perform( |
| 4868 new ParseDartTaskTestTV_perform_validateDirectives(context, source)); |
| 4869 } |
| 4870 |
| 4871 void test_resolveDirective_dartUri() { |
| 4872 GatheringErrorListener listener = new GatheringErrorListener(); |
| 4873 ImportDirective directive = AstFactory.importDirective3('dart:core', null); |
| 4874 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4875 Source source = |
| 4876 ParseDartTask.resolveDirective(context, null, directive, listener); |
| 4877 expect(source, isNotNull); |
| 4878 } |
| 4879 |
| 4880 void test_resolveDirective_exception() { |
| 4881 GatheringErrorListener listener = new GatheringErrorListener(); |
| 4882 ImportDirective directive = AstFactory.importDirective3('dart:core', null); |
| 4883 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4884 context.sourceFactory = new MockSourceFactory(); |
| 4885 Source source = |
| 4886 ParseDartTask.resolveDirective(context, null, directive, listener); |
| 4887 expect(source, isNull); |
| 4888 expect(listener.errors, hasLength(1)); |
| 4889 } |
| 4890 |
| 4891 /** |
| 4892 * Create and return a task that will parse the given content from the given s
ource in the given |
| 4893 * context. |
| 4894 * |
| 4895 * @param context the context to be passed to the task |
| 4896 * @param source the source to be parsed |
| 4897 * @param content the content of the source to be parsed |
| 4898 * @return the task that was created |
| 4899 * @throws AnalysisException if the task could not be created |
| 4900 */ |
| 4901 ParseDartTask _createParseTask( |
| 4902 InternalAnalysisContext context, Source source, String content) { |
| 4903 ScanDartTask scanTask = new ScanDartTask(context, source, content); |
| 4904 scanTask.perform(new ParseDartTaskTestTV_createParseTask()); |
| 4905 return new ParseDartTask( |
| 4906 context, source, scanTask.tokenStream, scanTask.lineInfo); |
| 4907 } |
| 4908 } |
| 4909 |
| 4910 class ParseDartTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 4911 @override |
| 4912 bool visitParseDartTask(ParseDartTask task) => true; |
| 4913 } |
| 4914 |
| 4915 class ParseDartTaskTestTV_createParseTask extends TestTaskVisitor<Object> { |
| 4916 @override |
| 4917 Object visitScanDartTask(ScanDartTask task) => null; |
| 4918 } |
| 4919 |
| 4920 class ParseDartTaskTestTV_perform_exception extends TestTaskVisitor<bool> { |
| 4921 @override |
| 4922 bool visitParseDartTask(ParseDartTask task) { |
| 4923 expect(task.exception, isNotNull); |
| 4924 return true; |
| 4925 } |
| 4926 } |
| 4927 |
| 4928 class ParseDartTaskTestTV_perform_library extends TestTaskVisitor<Object> { |
| 4929 InternalAnalysisContext context; |
| 4930 Source source; |
| 4931 ParseDartTaskTestTV_perform_library(this.context, this.source); |
| 4932 @override |
| 4933 Object visitParseDartTask(ParseDartTask task) { |
| 4934 CaughtException exception = task.exception; |
| 4935 if (exception != null) { |
| 4936 throw exception; |
| 4937 } |
| 4938 expect(task.compilationUnit, isNotNull); |
| 4939 expect(task.errors, hasLength(1)); |
| 4940 expect(task.source, same(source)); |
| 4941 expect(task.hasNonPartOfDirective, isTrue); |
| 4942 expect(task.hasPartOfDirective, isFalse); |
| 4943 return null; |
| 4944 } |
| 4945 } |
| 4946 |
| 4947 class ParseDartTaskTestTV_perform_part extends TestTaskVisitor<Object> { |
| 4948 InternalAnalysisContext context; |
| 4949 Source source; |
| 4950 ParseDartTaskTestTV_perform_part(this.context, this.source); |
| 4951 @override |
| 4952 Object visitParseDartTask(ParseDartTask task) { |
| 4953 CaughtException exception = task.exception; |
| 4954 if (exception != null) { |
| 4955 throw exception; |
| 4956 } |
| 4957 expect(task.compilationUnit, isNotNull); |
| 4958 expect(task.errors, hasLength(0)); |
| 4959 expect(task.source, same(source)); |
| 4960 expect(task.hasNonPartOfDirective, isFalse); |
| 4961 expect(task.hasPartOfDirective, isTrue); |
| 4962 return null; |
| 4963 } |
| 4964 } |
| 4965 |
| 4966 class ParseDartTaskTestTV_perform_validateDirectives |
| 4967 extends TestTaskVisitor<Object> { |
| 4968 InternalAnalysisContext context; |
| 4969 Source source; |
| 4970 ParseDartTaskTestTV_perform_validateDirectives(this.context, this.source); |
| 4971 @override |
| 4972 Object visitParseDartTask(ParseDartTask task) { |
| 4973 CaughtException exception = task.exception; |
| 4974 if (exception != null) { |
| 4975 throw exception; |
| 4976 } |
| 4977 expect(task.compilationUnit, isNotNull); |
| 4978 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4979 errorListener.addAll(task.errors); |
| 4980 errorListener.assertErrorsWithCodes([ |
| 4981 CompileTimeErrorCode.URI_WITH_INTERPOLATION, |
| 4982 CompileTimeErrorCode.INVALID_URI |
| 4983 ]); |
| 4984 expect(task.source, same(source)); |
| 4985 expect(task.hasNonPartOfDirective, isTrue); |
| 4986 expect(task.hasPartOfDirective, isFalse); |
| 4987 return null; |
| 4988 } |
| 4989 } |
| 4990 |
| 4991 @reflectiveTest |
| 4992 class ParseHtmlTaskTest extends EngineTestCase { |
| 4993 ParseHtmlTask parseContents(String contents, TestLogger testLogger) { |
| 4994 return parseSource( |
| 4995 new TestSource('/test.dart', contents), contents, testLogger); |
| 4996 } |
| 4997 |
| 4998 ParseHtmlTask parseSource( |
| 4999 Source source, String contents, TestLogger testLogger) { |
| 5000 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 5001 context.setContents(source, contents); |
| 5002 ParseHtmlTask task = new ParseHtmlTask(context, source, contents); |
| 5003 Logger oldLogger = AnalysisEngine.instance.logger; |
| 5004 try { |
| 5005 AnalysisEngine.instance.logger = testLogger; |
| 5006 task.perform(new ParseHtmlTaskTestTV_parseSource(context, source)); |
| 5007 } finally { |
| 5008 AnalysisEngine.instance.logger = oldLogger; |
| 5009 } |
| 5010 return task; |
| 5011 } |
| 5012 |
| 5013 void test_accept() { |
| 5014 ParseHtmlTask task = new ParseHtmlTask(null, null, ""); |
| 5015 expect(task.accept(new ParseHtmlTaskTestTV_accept()), isTrue); |
| 5016 } |
| 5017 |
| 5018 void test_getException() { |
| 5019 ParseHtmlTask task = new ParseHtmlTask(null, null, ""); |
| 5020 expect(task.exception, isNull); |
| 5021 } |
| 5022 |
| 5023 void test_getHtmlUnit() { |
| 5024 ParseHtmlTask task = new ParseHtmlTask(null, null, ""); |
| 5025 expect(task.htmlUnit, isNull); |
| 5026 } |
| 5027 |
| 5028 void test_getLineInfo() { |
| 5029 ParseHtmlTask task = new ParseHtmlTask(null, null, ""); |
| 5030 expect(task.lineInfo, isNull); |
| 5031 } |
| 5032 |
| 5033 void test_getReferencedLibraries() { |
| 5034 ParseHtmlTask task = new ParseHtmlTask(null, null, ""); |
| 5035 expect(task.referencedLibraries, hasLength(0)); |
| 5036 } |
| 5037 |
| 5038 void test_getSource() { |
| 5039 Source source = new TestSource('/test.dart'); |
| 5040 ParseHtmlTask task = new ParseHtmlTask(null, source, ""); |
| 5041 expect(task.source, same(source)); |
| 5042 } |
| 5043 |
| 5044 void test_perform_embedded_source() { |
| 5045 String contents = r''' |
| 5046 <html> |
| 5047 <head> |
| 5048 <script type='application/dart'> |
| 5049 void buttonPressed() {} |
| 5050 </script> |
| 5051 </head> |
| 5052 <body> |
| 5053 </body> |
| 5054 </html>'''; |
| 5055 TestLogger testLogger = new TestLogger(); |
| 5056 ParseHtmlTask task = parseContents(contents, testLogger); |
| 5057 expect(task.referencedLibraries, hasLength(0)); |
| 5058 expect(testLogger.errorCount, 0); |
| 5059 expect(testLogger.infoCount, 0); |
| 5060 } |
| 5061 |
| 5062 void test_perform_empty_source_reference() { |
| 5063 String contents = r''' |
| 5064 <html> |
| 5065 <head> |
| 5066 <script type='application/dart' src=''/> |
| 5067 </head> |
| 5068 <body> |
| 5069 </body> |
| 5070 </html>'''; |
| 5071 TestLogger testLogger = new TestLogger(); |
| 5072 ParseHtmlTask task = parseContents(contents, testLogger); |
| 5073 expect(task.referencedLibraries, hasLength(0)); |
| 5074 expect(testLogger.errorCount, 0); |
| 5075 expect(testLogger.infoCount, 0); |
| 5076 } |
| 5077 |
| 5078 void test_perform_invalid_source_reference() { |
| 5079 String contents = r''' |
| 5080 <html> |
| 5081 <head> |
| 5082 <script type='application/dart' src='an;invalid:[]uri'/> |
| 5083 </head> |
| 5084 <body> |
| 5085 </body> |
| 5086 </html>'''; |
| 5087 TestLogger testLogger = new TestLogger(); |
| 5088 ParseHtmlTask task = parseContents(contents, testLogger); |
| 5089 expect(task.referencedLibraries, hasLength(0)); |
| 5090 expect(testLogger.errorCount, 0); |
| 5091 expect(testLogger.infoCount, 0); |
| 5092 } |
| 5093 |
| 5094 void test_perform_non_existing_source_reference() { |
| 5095 String contents = r''' |
| 5096 <html> |
| 5097 <head> |
| 5098 <script type='application/dart' src='does/not/exist.dart'/> |
| 5099 </head> |
| 5100 <body> |
| 5101 </body> |
| 5102 </html>'''; |
| 5103 TestLogger testLogger = new TestLogger(); |
| 5104 ParseHtmlTask task = parseSource( |
| 5105 new ParseHtmlTaskTest_non_existing_source(contents), |
| 5106 contents, |
| 5107 testLogger); |
| 5108 expect(task.referencedLibraries, hasLength(0)); |
| 5109 expect(testLogger.errorCount, 0); |
| 5110 expect(testLogger.infoCount, 0); |
| 5111 } |
| 5112 |
| 5113 void test_perform_referenced_source() { |
| 5114 // TODO(scheglov) this test fails because we put into cache TestSource |
| 5115 // test.dart (and actually should test.html), but resolve |
| 5116 // src='test.dart' as a FileBasedSource |
| 5117 // We need to switch to a virtual file system and use it everywhere. |
| 5118 // String contents = EngineTestCase.createSource([ |
| 5119 // "<html>", |
| 5120 // "<head>", |
| 5121 // " <script type='application/dart' src='test.dart'/>", |
| 5122 // "</head>", |
| 5123 // "<body>", |
| 5124 // "</body>", |
| 5125 // "</html>"]); |
| 5126 // TestLogger testLogger = new TestLogger(); |
| 5127 // ParseHtmlTask task = parseContents(contents, testLogger); |
| 5128 // EngineTestCase.assertLength(1, task.referencedLibraries); |
| 5129 // JUnitTestCase.assertEquals(0, testLogger.errorCount); |
| 5130 // JUnitTestCase.assertEquals(0, testLogger.errorCount); |
| 5131 } |
| 5132 } |
| 5133 |
| 5134 class ParseHtmlTaskTest_non_existing_source extends TestSource { |
| 5135 ParseHtmlTaskTest_non_existing_source(String arg0) : super(arg0); |
| 5136 @override |
| 5137 Uri resolveRelativeUri(Uri containedUri) { |
| 5138 try { |
| 5139 return parseUriWithException("file:/does/not/exist.dart"); |
| 5140 } on URISyntaxException { |
| 5141 return null; |
| 5142 } |
| 5143 } |
| 5144 } |
| 5145 |
| 5146 class ParseHtmlTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 5147 @override |
| 5148 bool visitParseHtmlTask(ParseHtmlTask task) => true; |
| 5149 } |
| 5150 |
| 5151 class ParseHtmlTaskTestTV_parseSource extends TestTaskVisitor<bool> { |
| 5152 InternalAnalysisContext context; |
| 5153 Source source; |
| 5154 ParseHtmlTaskTestTV_parseSource(this.context, this.source); |
| 5155 @override |
| 5156 bool visitParseHtmlTask(ParseHtmlTask task) { |
| 5157 CaughtException exception = task.exception; |
| 5158 if (exception != null) { |
| 5159 throw exception; |
| 5160 } |
| 5161 expect(task.htmlUnit, isNotNull); |
| 5162 expect(task.lineInfo, isNotNull); |
| 5163 expect(task.source, same(source)); |
| 5164 return true; |
| 5165 } |
| 5166 } |
| 5167 |
| 5168 @reflectiveTest |
| 5169 class PartitionManagerTest extends EngineTestCase { |
| 5170 void test_clearCache() { |
| 5171 PartitionManager manager = new PartitionManager(); |
| 5172 DartSdk sdk = new MockDartSdk(); |
| 5173 SdkCachePartition oldPartition = manager.forSdk(sdk); |
| 5174 manager.clearCache(); |
| 5175 SdkCachePartition newPartition = manager.forSdk(sdk); |
| 5176 expect(newPartition, isNot(same(oldPartition))); |
| 5177 } |
| 5178 |
| 5179 void test_creation() { |
| 5180 expect(new PartitionManager(), isNotNull); |
| 5181 } |
| 5182 |
| 5183 void test_forSdk() { |
| 5184 PartitionManager manager = new PartitionManager(); |
| 5185 DartSdk sdk1 = new MockDartSdk(); |
| 5186 SdkCachePartition partition1 = manager.forSdk(sdk1); |
| 5187 expect(partition1, isNotNull); |
| 5188 expect(manager.forSdk(sdk1), same(partition1)); |
| 5189 DartSdk sdk2 = new MockDartSdk(); |
| 5190 SdkCachePartition partition2 = manager.forSdk(sdk2); |
| 5191 expect(partition2, isNotNull); |
| 5192 expect(manager.forSdk(sdk2), same(partition2)); |
| 5193 expect(partition2, isNot(same(partition1))); |
| 5194 } |
| 5195 } |
| 5196 |
| 5197 @reflectiveTest |
| 5198 class ResolveDartLibraryTaskTest extends EngineTestCase { |
| 5199 void test_accept() { |
| 5200 ResolveDartLibraryTask task = new ResolveDartLibraryTask(null, null, null); |
| 5201 expect(task.accept(new ResolveDartLibraryTaskTestTV_accept()), isTrue); |
| 5202 } |
| 5203 |
| 5204 void test_getException() { |
| 5205 ResolveDartLibraryTask task = new ResolveDartLibraryTask(null, null, null); |
| 5206 expect(task.exception, isNull); |
| 5207 } |
| 5208 |
| 5209 void test_getLibraryResolver() { |
| 5210 ResolveDartLibraryTask task = new ResolveDartLibraryTask(null, null, null); |
| 5211 expect(task.libraryResolver, isNull); |
| 5212 } |
| 5213 |
| 5214 void test_getLibrarySource() { |
| 5215 Source source = new TestSource('/test.dart'); |
| 5216 ResolveDartLibraryTask task = |
| 5217 new ResolveDartLibraryTask(null, null, source); |
| 5218 expect(task.librarySource, same(source)); |
| 5219 } |
| 5220 |
| 5221 void test_getUnitSource() { |
| 5222 Source source = new TestSource('/test.dart'); |
| 5223 ResolveDartLibraryTask task = |
| 5224 new ResolveDartLibraryTask(null, source, null); |
| 5225 expect(task.unitSource, same(source)); |
| 5226 } |
| 5227 |
| 5228 void test_perform_exception() { |
| 5229 TestSource source = new TestSource(); |
| 5230 source.generateExceptionOnRead = true; |
| 5231 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 5232 ResolveDartLibraryTask task = |
| 5233 new ResolveDartLibraryTask(context, source, source); |
| 5234 task.perform(new ResolveDartLibraryTaskTestTV_perform_exception()); |
| 5235 } |
| 5236 |
| 5237 void test_perform_library() { |
| 5238 Source source = new TestSource( |
| 5239 '/test.dart', |
| 5240 r''' |
| 5241 library lib; |
| 5242 class A {}'''); |
| 5243 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 5244 ResolveDartLibraryTask task = |
| 5245 new ResolveDartLibraryTask(context, source, source); |
| 5246 task.perform(new ResolveDartLibraryTaskTestTV_perform_library(source)); |
| 5247 } |
| 5248 } |
| 5249 |
| 5250 class ResolveDartLibraryTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 5251 @override |
| 5252 bool visitResolveDartLibraryTask(ResolveDartLibraryTask task) => true; |
| 5253 } |
| 5254 |
| 5255 class ResolveDartLibraryTaskTestTV_perform_exception |
| 5256 extends TestTaskVisitor<bool> { |
| 5257 @override |
| 5258 bool visitResolveDartLibraryTask(ResolveDartLibraryTask task) { |
| 5259 expect(task.exception, isNotNull); |
| 5260 return true; |
| 5261 } |
| 5262 } |
| 5263 |
| 5264 class ResolveDartLibraryTaskTestTV_perform_library |
| 5265 extends TestTaskVisitor<bool> { |
| 5266 Source source; |
| 5267 ResolveDartLibraryTaskTestTV_perform_library(this.source); |
| 5268 @override |
| 5269 bool visitResolveDartLibraryTask(ResolveDartLibraryTask task) { |
| 5270 CaughtException exception = task.exception; |
| 5271 if (exception != null) { |
| 5272 throw exception; |
| 5273 } |
| 5274 expect(task.libraryResolver, isNotNull); |
| 5275 expect(task.librarySource, same(source)); |
| 5276 expect(task.unitSource, same(source)); |
| 5277 return true; |
| 5278 } |
| 5279 } |
| 5280 |
| 5281 @reflectiveTest |
| 5282 class ResolveDartUnitTaskTest extends EngineTestCase { |
| 5283 void test_accept() { |
| 5284 ResolveDartUnitTask task = new ResolveDartUnitTask(null, null, null); |
| 5285 expect(task.accept(new ResolveDartUnitTaskTestTV_accept()), isTrue); |
| 5286 } |
| 5287 |
| 5288 void test_getException() { |
| 5289 ResolveDartUnitTask task = new ResolveDartUnitTask(null, null, null); |
| 5290 expect(task.exception, isNull); |
| 5291 } |
| 5292 |
| 5293 void test_getLibrarySource() { |
| 5294 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 5295 LibraryElementImpl element = ElementFactory.library(context, "lib"); |
| 5296 Source source = element.source; |
| 5297 ResolveDartUnitTask task = new ResolveDartUnitTask(null, null, element); |
| 5298 expect(task.librarySource, same(source)); |
| 5299 } |
| 5300 |
| 5301 void test_getResolvedUnit() { |
| 5302 ResolveDartUnitTask task = new ResolveDartUnitTask(null, null, null); |
| 5303 expect(task.resolvedUnit, isNull); |
| 5304 } |
| 5305 |
| 5306 void test_getSource() { |
| 5307 Source source = new TestSource('/test.dart'); |
| 5308 ResolveDartUnitTask task = new ResolveDartUnitTask(null, source, null); |
| 5309 expect(task.source, same(source)); |
| 5310 } |
| 5311 |
| 5312 void test_perform_exception() { |
| 5313 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 5314 LibraryElementImpl element = ElementFactory.library(context, "lib"); |
| 5315 TestSource source = new TestSource(); |
| 5316 source.generateExceptionOnRead = true; |
| 5317 (element.definingCompilationUnit as CompilationUnitElementImpl).source = |
| 5318 source; |
| 5319 ResolveDartUnitTask task = |
| 5320 new ResolveDartUnitTask(context, source, element); |
| 5321 task.perform(new ResolveDartUnitTaskTestTV_perform_exception()); |
| 5322 } |
| 5323 |
| 5324 void test_perform_library() { |
| 5325 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 5326 LibraryElementImpl libraryElement = ElementFactory.library(context, "lib"); |
| 5327 CompilationUnitElementImpl unitElement = |
| 5328 libraryElement.definingCompilationUnit as CompilationUnitElementImpl; |
| 5329 ClassElementImpl classElement = ElementFactory.classElement2("A"); |
| 5330 classElement.nameOffset = 19; |
| 5331 ConstructorElementImpl constructorElement = |
| 5332 ElementFactory.constructorElement2(classElement, null); |
| 5333 constructorElement.synthetic = true; |
| 5334 classElement.constructors = <ConstructorElement>[constructorElement]; |
| 5335 unitElement.types = <ClassElement>[classElement]; |
| 5336 Source source = unitElement.source; |
| 5337 context.setContents( |
| 5338 source, |
| 5339 r''' |
| 5340 library lib; |
| 5341 class A {}'''); |
| 5342 ResolveDartUnitTask task = |
| 5343 new ResolveDartUnitTask(context, source, libraryElement); |
| 5344 task.perform( |
| 5345 new ResolveDartUnitTaskTestTV_perform_library(source, context)); |
| 5346 } |
| 5347 } |
| 5348 |
| 5349 class ResolveDartUnitTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 5350 @override |
| 5351 bool visitResolveDartUnitTask(ResolveDartUnitTask task) => true; |
| 5352 } |
| 5353 |
| 5354 class ResolveDartUnitTaskTestTV_perform_exception |
| 5355 extends TestTaskVisitor<bool> { |
| 5356 @override |
| 5357 bool visitResolveDartUnitTask(ResolveDartUnitTask task) { |
| 5358 expect(task.exception, isNotNull); |
| 5359 return true; |
| 5360 } |
| 5361 } |
| 5362 |
| 5363 class ResolveDartUnitTaskTestTV_perform_library extends TestTaskVisitor<bool> { |
| 5364 Source source; |
| 5365 InternalAnalysisContext context; |
| 5366 ResolveDartUnitTaskTestTV_perform_library(this.source, this.context); |
| 5367 @override |
| 5368 bool visitResolveDartUnitTask(ResolveDartUnitTask task) { |
| 5369 CaughtException exception = task.exception; |
| 5370 if (exception != null) { |
| 5371 throw exception; |
| 5372 } |
| 5373 expect(task.librarySource, same(source)); |
| 5374 expect(task.resolvedUnit, isNotNull); |
| 5375 expect(task.source, same(source)); |
| 5376 return true; |
| 5377 } |
| 5378 } |
| 5379 |
| 5380 @reflectiveTest |
| 5381 class ResolveHtmlTaskTest extends EngineTestCase { |
| 5382 void test_accept() { |
| 5383 ResolveHtmlTask task = new ResolveHtmlTask(null, null, 0, null); |
| 5384 expect(task.accept(new ResolveHtmlTaskTestTV_accept()), isTrue); |
| 5385 } |
| 5386 |
| 5387 void test_getElement() { |
| 5388 ResolveHtmlTask task = new ResolveHtmlTask(null, null, 0, null); |
| 5389 expect(task.element, isNull); |
| 5390 } |
| 5391 |
| 5392 void test_getException() { |
| 5393 ResolveHtmlTask task = new ResolveHtmlTask(null, null, 0, null); |
| 5394 expect(task.exception, isNull); |
| 5395 } |
| 5396 |
| 5397 void test_getResolutionErrors() { |
| 5398 ResolveHtmlTask task = new ResolveHtmlTask(null, null, 0, null); |
| 5399 expect(task.resolutionErrors, hasLength(0)); |
| 5400 } |
| 5401 |
| 5402 void test_getSource() { |
| 5403 Source source = new TestSource('test.dart', ''); |
| 5404 ResolveHtmlTask task = new ResolveHtmlTask(null, source, 0, null); |
| 5405 expect(task.source, same(source)); |
| 5406 } |
| 5407 |
| 5408 void test_perform_exception() { |
| 5409 Source source = new TestSource(); |
| 5410 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 5411 ResolveHtmlTask task = new ResolveHtmlTask(context, source, 0, null); |
| 5412 task.perform(new ResolveHtmlTaskTestTV_perform_exception()); |
| 5413 } |
| 5414 |
| 5415 void test_perform_valid() { |
| 5416 int modificationStamp = 73; |
| 5417 String content = r''' |
| 5418 <html> |
| 5419 <head> |
| 5420 <script type='application/dart'> |
| 5421 void f() { x = 0; } |
| 5422 </script> |
| 5423 </head> |
| 5424 <body> |
| 5425 </body> |
| 5426 </html>'''; |
| 5427 Source source = new TestSource("/test.html", content); |
| 5428 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 5429 ParseHtmlTask parseTask = new ParseHtmlTask(context, source, content); |
| 5430 parseTask.perform(new ResolveHtmlTaskTestTV_perform_valid_2()); |
| 5431 ResolveHtmlTask task = new ResolveHtmlTask( |
| 5432 context, source, modificationStamp, parseTask.htmlUnit); |
| 5433 task.perform( |
| 5434 new ResolveHtmlTaskTestTV_perform_valid(modificationStamp, source)); |
| 5435 } |
| 5436 } |
| 5437 |
| 5438 class ResolveHtmlTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 5439 @override |
| 5440 bool visitResolveHtmlTask(ResolveHtmlTask task) => true; |
| 5441 } |
| 5442 |
| 5443 class ResolveHtmlTaskTestTV_perform_exception extends TestTaskVisitor<bool> { |
| 5444 @override |
| 5445 bool visitResolveHtmlTask(ResolveHtmlTask task) { |
| 5446 expect(task.exception, isNotNull); |
| 5447 return true; |
| 5448 } |
| 5449 } |
| 5450 |
| 5451 class ResolveHtmlTaskTestTV_perform_valid extends TestTaskVisitor<Object> { |
| 5452 int modificationStamp; |
| 5453 Source source; |
| 5454 ResolveHtmlTaskTestTV_perform_valid(this.modificationStamp, this.source); |
| 5455 @override |
| 5456 Object visitResolveHtmlTask(ResolveHtmlTask task) { |
| 5457 CaughtException exception = task.exception; |
| 5458 if (exception != null) { |
| 5459 throw exception; |
| 5460 } |
| 5461 expect(task.element, isNotNull); |
| 5462 expect(task.resolutionErrors, hasLength(1)); |
| 5463 expect(task.source, same(source)); |
| 5464 return null; |
| 5465 } |
| 5466 } |
| 5467 |
| 5468 class ResolveHtmlTaskTestTV_perform_valid_2 extends TestTaskVisitor<Object> { |
| 5469 @override |
| 5470 Object visitParseHtmlTask(ParseHtmlTask task) => null; |
| 5471 } |
| 5472 |
| 5473 @reflectiveTest |
| 5474 class ScanDartTaskTest extends EngineTestCase { |
| 5475 void test_accept() { |
| 5476 ScanDartTask task = new ScanDartTask(null, null, null); |
| 5477 expect(task.accept(new ScanDartTaskTestTV_accept()), isTrue); |
| 5478 } |
| 5479 |
| 5480 void test_getErrors() { |
| 5481 ScanDartTask task = new ScanDartTask(null, null, null); |
| 5482 expect(task.errors, hasLength(0)); |
| 5483 } |
| 5484 |
| 5485 void test_getException() { |
| 5486 ScanDartTask task = new ScanDartTask(null, null, null); |
| 5487 expect(task.exception, isNull); |
| 5488 } |
| 5489 |
| 5490 void test_getLineInfo() { |
| 5491 ScanDartTask task = new ScanDartTask(null, null, null); |
| 5492 expect(task.lineInfo, isNull); |
| 5493 } |
| 5494 |
| 5495 void test_getSource() { |
| 5496 Source source = new TestSource('test.dart', ''); |
| 5497 ScanDartTask task = new ScanDartTask(null, source, null); |
| 5498 expect(task.source, same(source)); |
| 5499 } |
| 5500 |
| 5501 void test_perform_valid() { |
| 5502 String content = 'class A {}'; |
| 5503 Source source = new TestSource('test.dart', content); |
| 5504 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 5505 ScanDartTask task = new ScanDartTask(context, source, content); |
| 5506 task.perform(new ScanDartTaskTestTV_perform_valid(context, source)); |
| 5507 } |
| 5508 } |
| 5509 |
| 5510 class ScanDartTaskTestTV_accept extends TestTaskVisitor<bool> { |
| 5511 @override |
| 5512 bool visitScanDartTask(ScanDartTask task) => true; |
| 5513 } |
| 5514 |
| 5515 class ScanDartTaskTestTV_perform_valid extends TestTaskVisitor<bool> { |
| 5516 InternalAnalysisContext context; |
| 5517 Source source; |
| 5518 ScanDartTaskTestTV_perform_valid(this.context, this.source); |
| 5519 @override |
| 5520 bool visitScanDartTask(ScanDartTask task) { |
| 5521 CaughtException exception = task.exception; |
| 5522 if (exception != null) { |
| 5523 throw exception; |
| 5524 } |
| 5525 expect(task.tokenStream, isNotNull); |
| 5526 expect(task.errors, hasLength(0)); |
| 5527 expect(task.lineInfo, isNotNull); |
| 5528 expect(task.source, same(source)); |
| 5529 return true; |
| 5530 } |
| 5531 } |
| 5532 |
| 5533 @reflectiveTest |
| 5534 class SdkCachePartitionTest extends EngineTestCase { |
| 5535 void test_contains_false() { |
| 5536 SdkCachePartition partition = new SdkCachePartition(null, 8); |
| 5537 Source source = new TestSource(); |
| 5538 expect(partition.contains(source), isFalse); |
| 5539 } |
| 5540 |
| 5541 void test_contains_true() { |
| 5542 SdkCachePartition partition = new SdkCachePartition(null, 8); |
| 5543 SourceFactory factory = new SourceFactory( |
| 5544 [new DartUriResolver(DirectoryBasedDartSdk.defaultSdk)]); |
| 5545 Source source = factory.forUri("dart:core"); |
| 5546 expect(partition.contains(source), isTrue); |
| 5547 } |
| 5548 |
| 5549 void test_creation() { |
| 5550 expect(new SdkCachePartition(null, 8), isNotNull); |
| 5551 } |
| 5552 } |
| 5553 |
| 5554 @reflectiveTest |
| 5555 class SourcesChangedEventTest { |
| 5556 void test_added() { |
| 5557 var source = new StringSource('', '/test.dart'); |
| 5558 var changeSet = new ChangeSet(); |
| 5559 changeSet.addedSource(source); |
| 5560 var event = new SourcesChangedEvent(changeSet); |
| 5561 assertEvent(event, wereSourcesAdded: true); |
| 5562 } |
| 5563 |
| 5564 void test_changedContent() { |
| 5565 var source = new StringSource('', '/test.dart'); |
| 5566 var changeSet = new ChangeSet(); |
| 5567 changeSet.changedContent(source, 'library A;'); |
| 5568 var event = new SourcesChangedEvent(changeSet); |
| 5569 assertEvent(event, changedSources: [source]); |
| 5570 } |
| 5571 |
| 5572 void test_changedContent2() { |
| 5573 var source = new StringSource('', '/test.dart'); |
| 5574 var event = new SourcesChangedEvent.changedContent(source, 'library A;'); |
| 5575 assertEvent(event, changedSources: [source]); |
| 5576 } |
| 5577 |
| 5578 void test_changedRange() { |
| 5579 var source = new StringSource('', '/test.dart'); |
| 5580 var changeSet = new ChangeSet(); |
| 5581 changeSet.changedRange(source, 'library A;', 0, 0, 13); |
| 5582 var event = new SourcesChangedEvent(changeSet); |
| 5583 assertEvent(event, changedSources: [source]); |
| 5584 } |
| 5585 |
| 5586 void test_changedRange2() { |
| 5587 var source = new StringSource('', '/test.dart'); |
| 5588 var event = |
| 5589 new SourcesChangedEvent.changedRange(source, 'library A;', 0, 0, 13); |
| 5590 assertEvent(event, changedSources: [source]); |
| 5591 } |
| 5592 |
| 5593 void test_changedSources() { |
| 5594 var source = new StringSource('', '/test.dart'); |
| 5595 var changeSet = new ChangeSet(); |
| 5596 changeSet.changedSource(source); |
| 5597 var event = new SourcesChangedEvent(changeSet); |
| 5598 assertEvent(event, changedSources: [source]); |
| 5599 } |
| 5600 |
| 5601 void test_deleted() { |
| 5602 var source = new StringSource('', '/test.dart'); |
| 5603 var changeSet = new ChangeSet(); |
| 5604 changeSet.deletedSource(source); |
| 5605 var event = new SourcesChangedEvent(changeSet); |
| 5606 assertEvent(event, wereSourcesRemovedOrDeleted: true); |
| 5607 } |
| 5608 |
| 5609 void test_empty() { |
| 5610 var changeSet = new ChangeSet(); |
| 5611 var event = new SourcesChangedEvent(changeSet); |
| 5612 assertEvent(event); |
| 5613 } |
| 5614 |
| 5615 void test_removed() { |
| 5616 var source = new StringSource('', '/test.dart'); |
| 5617 var changeSet = new ChangeSet(); |
| 5618 changeSet.removedSource(source); |
| 5619 var event = new SourcesChangedEvent(changeSet); |
| 5620 assertEvent(event, wereSourcesRemovedOrDeleted: true); |
| 5621 } |
| 5622 |
| 5623 static void assertEvent(SourcesChangedEvent event, |
| 5624 {bool wereSourcesAdded: false, |
| 5625 List<Source> changedSources: Source.EMPTY_LIST, |
| 5626 bool wereSourcesRemovedOrDeleted: false}) { |
| 5627 expect(event.wereSourcesAdded, wereSourcesAdded); |
| 5628 expect(event.changedSources, changedSources); |
| 5629 expect(event.wereSourcesRemovedOrDeleted, wereSourcesRemovedOrDeleted); |
| 5630 } |
| 5631 } |
| 5632 |
| 5633 class SourcesChangedListener { |
| 5634 List<SourcesChangedEvent> actualEvents = []; |
| 5635 |
| 5636 void assertEvent( |
| 5637 {bool wereSourcesAdded: false, |
| 5638 List<Source> changedSources: Source.EMPTY_LIST, |
| 5639 bool wereSourcesRemovedOrDeleted: false}) { |
| 5640 if (actualEvents.isEmpty) { |
| 5641 fail('Expected event but found none'); |
| 5642 } |
| 5643 SourcesChangedEvent actual = actualEvents.removeAt(0); |
| 5644 SourcesChangedEventTest.assertEvent(actual, |
| 5645 wereSourcesAdded: wereSourcesAdded, |
| 5646 changedSources: changedSources, |
| 5647 wereSourcesRemovedOrDeleted: wereSourcesRemovedOrDeleted); |
| 5648 } |
| 5649 |
| 5650 void assertNoMoreEvents() { |
| 5651 expect(actualEvents, []); |
| 5652 } |
| 5653 |
| 5654 void onData(SourcesChangedEvent event) { |
| 5655 actualEvents.add(event); |
| 5656 } |
| 5657 } |
| 5658 |
| 5659 /** |
| 5660 * Instances of the class `TestAnalysisContext` implement an analysis context in
which every |
| 5661 * method will cause a test to fail when invoked. |
| 5662 */ |
| 5663 class TestAnalysisContext implements InternalAnalysisContext { |
| 5664 @override |
| 5665 AnalysisCache get analysisCache { |
| 5666 fail("Unexpected invocation of analysisCache"); |
| 5667 return null; |
| 5668 } |
| 5669 |
| 5670 @override |
| 5671 AnalysisOptions get analysisOptions { |
| 5672 fail("Unexpected invocation of getAnalysisOptions"); |
| 5673 return null; |
| 5674 } |
| 5675 |
| 5676 @override |
| 5677 void set analysisOptions(AnalysisOptions options) { |
| 5678 fail("Unexpected invocation of setAnalysisOptions"); |
| 5679 } |
| 5680 |
| 5681 @override |
| 5682 void set analysisPriorityOrder(List<Source> sources) { |
| 5683 fail("Unexpected invocation of setAnalysisPriorityOrder"); |
| 5684 } |
| 5685 |
| 5686 @override |
| 5687 set contentCache(ContentCache value) { |
| 5688 fail("Unexpected invocation of setContentCache"); |
| 5689 } |
| 5690 |
| 5691 @override |
| 5692 DeclaredVariables get declaredVariables { |
| 5693 fail("Unexpected invocation of getDeclaredVariables"); |
| 5694 return null; |
| 5695 } |
| 5696 |
| 5697 @override |
| 5698 List<AnalysisTarget> get explicitTargets { |
| 5699 fail("Unexpected invocation of visitCacheItems"); |
| 5700 return null; |
| 5701 } |
| 5702 |
| 5703 @override |
| 5704 List<Source> get htmlSources { |
| 5705 fail("Unexpected invocation of getHtmlSources"); |
| 5706 return null; |
| 5707 } |
| 5708 |
| 5709 @override |
| 5710 Stream<ImplicitAnalysisEvent> get implicitAnalysisEvents { |
| 5711 fail("Unexpected invocation of analyzedSources"); |
| 5712 return null; |
| 5713 } |
| 5714 |
| 5715 @override |
| 5716 bool get isDisposed { |
| 5717 fail("Unexpected invocation of isDisposed"); |
| 5718 return false; |
| 5719 } |
| 5720 |
| 5721 @override |
| 5722 List<Source> get launchableClientLibrarySources { |
| 5723 fail("Unexpected invocation of getLaunchableClientLibrarySources"); |
| 5724 return null; |
| 5725 } |
| 5726 |
| 5727 @override |
| 5728 List<Source> get launchableServerLibrarySources { |
| 5729 fail("Unexpected invocation of getLaunchableServerLibrarySources"); |
| 5730 return null; |
| 5731 } |
| 5732 |
| 5733 @override |
| 5734 LibraryResolverFactory get libraryResolverFactory { |
| 5735 fail("Unexpected invocation of getLibraryResolverFactory"); |
| 5736 return null; |
| 5737 } |
| 5738 |
| 5739 @override |
| 5740 List<Source> get librarySources { |
| 5741 fail("Unexpected invocation of getLibrarySources"); |
| 5742 return null; |
| 5743 } |
| 5744 |
| 5745 @override |
| 5746 String get name { |
| 5747 fail("Unexpected invocation of name"); |
| 5748 return null; |
| 5749 } |
| 5750 |
| 5751 @override |
| 5752 set name(String value) { |
| 5753 fail("Unexpected invocation of name"); |
| 5754 } |
| 5755 |
| 5756 @override |
| 5757 Stream<SourcesChangedEvent> get onSourcesChanged { |
| 5758 fail("Unexpected invocation of onSourcesChanged"); |
| 5759 return null; |
| 5760 } |
| 5761 |
| 5762 @override |
| 5763 List<Source> get prioritySources { |
| 5764 fail("Unexpected invocation of getPrioritySources"); |
| 5765 return null; |
| 5766 } |
| 5767 |
| 5768 @override |
| 5769 List<AnalysisTarget> get priorityTargets { |
| 5770 fail("Unexpected invocation of visitCacheItems"); |
| 5771 return null; |
| 5772 } |
| 5773 |
| 5774 @override |
| 5775 CachePartition get privateAnalysisCachePartition { |
| 5776 fail("Unexpected invocation of privateAnalysisCachePartition"); |
| 5777 return null; |
| 5778 } |
| 5779 |
| 5780 @override |
| 5781 ResolverVisitorFactory get resolverVisitorFactory { |
| 5782 fail("Unexpected invocation of getResolverVisitorFactory"); |
| 5783 return null; |
| 5784 } |
| 5785 |
| 5786 @override |
| 5787 SourceFactory get sourceFactory { |
| 5788 fail("Unexpected invocation of getSourceFactory"); |
| 5789 return null; |
| 5790 } |
| 5791 |
| 5792 @override |
| 5793 void set sourceFactory(SourceFactory factory) { |
| 5794 fail("Unexpected invocation of setSourceFactory"); |
| 5795 } |
| 5796 |
| 5797 @override |
| 5798 List<Source> get sources { |
| 5799 fail("Unexpected invocation of sources"); |
| 5800 return null; |
| 5801 } |
| 5802 |
| 5803 @override |
| 5804 AnalysisContextStatistics get statistics { |
| 5805 fail("Unexpected invocation of getStatistics"); |
| 5806 return null; |
| 5807 } |
| 5808 |
| 5809 @override |
| 5810 TypeProvider get typeProvider { |
| 5811 fail("Unexpected invocation of getTypeProvider"); |
| 5812 return null; |
| 5813 } |
| 5814 |
| 5815 @override |
| 5816 void set typeProvider(TypeProvider typeProvider) { |
| 5817 fail("Unexpected invocation of set typeProvider"); |
| 5818 } |
| 5819 |
| 5820 @override |
| 5821 TypeSystem get typeSystem { |
| 5822 fail("Unexpected invocation of getTypeSystem"); |
| 5823 return null; |
| 5824 } |
| 5825 |
| 5826 @override |
| 5827 TypeResolverVisitorFactory get typeResolverVisitorFactory { |
| 5828 fail("Unexpected invocation of getTypeResolverVisitorFactory"); |
| 5829 return null; |
| 5830 } |
| 5831 |
| 5832 @override |
| 5833 void addListener(AnalysisListener listener) { |
| 5834 fail("Unexpected invocation of addListener"); |
| 5835 } |
| 5836 |
| 5837 @override |
| 5838 void applyAnalysisDelta(AnalysisDelta delta) { |
| 5839 fail("Unexpected invocation of applyAnalysisDelta"); |
| 5840 } |
| 5841 |
| 5842 @override |
| 5843 void applyChanges(ChangeSet changeSet) { |
| 5844 fail("Unexpected invocation of applyChanges"); |
| 5845 } |
| 5846 |
| 5847 @override |
| 5848 String computeDocumentationComment(Element element) { |
| 5849 fail("Unexpected invocation of computeDocumentationComment"); |
| 5850 return null; |
| 5851 } |
| 5852 |
| 5853 @override |
| 5854 List<AnalysisError> computeErrors(Source source) { |
| 5855 fail("Unexpected invocation of computeErrors"); |
| 5856 return null; |
| 5857 } |
| 5858 |
| 5859 @override |
| 5860 List<Source> computeExportedLibraries(Source source) { |
| 5861 fail("Unexpected invocation of computeExportedLibraries"); |
| 5862 return null; |
| 5863 } |
| 5864 |
| 5865 @override |
| 5866 @deprecated |
| 5867 HtmlElement computeHtmlElement(Source source) { |
| 5868 fail("Unexpected invocation of computeHtmlElement"); |
| 5869 return null; |
| 5870 } |
| 5871 |
| 5872 @override |
| 5873 List<Source> computeImportedLibraries(Source source) { |
| 5874 fail("Unexpected invocation of computeImportedLibraries"); |
| 5875 return null; |
| 5876 } |
| 5877 |
| 5878 @override |
| 5879 SourceKind computeKindOf(Source source) { |
| 5880 fail("Unexpected invocation of computeKindOf"); |
| 5881 return null; |
| 5882 } |
| 5883 |
| 5884 @override |
| 5885 LibraryElement computeLibraryElement(Source source) { |
| 5886 fail("Unexpected invocation of computeLibraryElement"); |
| 5887 return null; |
| 5888 } |
| 5889 |
| 5890 @override |
| 5891 LineInfo computeLineInfo(Source source) { |
| 5892 fail("Unexpected invocation of computeLineInfo"); |
| 5893 return null; |
| 5894 } |
| 5895 |
| 5896 @override |
| 5897 CompilationUnit computeResolvableCompilationUnit(Source source) { |
| 5898 fail("Unexpected invocation of computeResolvableCompilationUnit"); |
| 5899 return null; |
| 5900 } |
| 5901 |
| 5902 @override |
| 5903 Future<CompilationUnit> computeResolvedCompilationUnitAsync( |
| 5904 Source source, Source librarySource) { |
| 5905 fail("Unexpected invocation of getResolvedCompilationUnitFuture"); |
| 5906 return null; |
| 5907 } |
| 5908 |
| 5909 @override |
| 5910 Object computeResult(AnalysisTarget target, ResultDescriptor result) { |
| 5911 fail("Unexpected invocation of computeResult"); |
| 5912 return null; |
| 5913 } |
| 5914 |
| 5915 @override |
| 5916 void dispose() { |
| 5917 fail("Unexpected invocation of dispose"); |
| 5918 } |
| 5919 |
| 5920 @override |
| 5921 List<CompilationUnit> ensureResolvedDartUnits(Source source) { |
| 5922 fail("Unexpected invocation of ensureResolvedDartUnits"); |
| 5923 return null; |
| 5924 } |
| 5925 |
| 5926 @override |
| 5927 bool exists(Source source) { |
| 5928 fail("Unexpected invocation of exists"); |
| 5929 return false; |
| 5930 } |
| 5931 |
| 5932 @override |
| 5933 CacheEntry getCacheEntry(AnalysisTarget target) { |
| 5934 fail("Unexpected invocation of visitCacheItems"); |
| 5935 return null; |
| 5936 } |
| 5937 |
| 5938 @override |
| 5939 CompilationUnitElement getCompilationUnitElement( |
| 5940 Source unitSource, Source librarySource) { |
| 5941 fail("Unexpected invocation of getCompilationUnitElement"); |
| 5942 return null; |
| 5943 } |
| 5944 |
| 5945 @override |
| 5946 TimestampedData<String> getContents(Source source) { |
| 5947 fail("Unexpected invocation of getContents"); |
| 5948 return null; |
| 5949 } |
| 5950 |
| 5951 @override |
| 5952 InternalAnalysisContext getContextFor(Source source) { |
| 5953 fail("Unexpected invocation of getContextFor"); |
| 5954 return null; |
| 5955 } |
| 5956 |
| 5957 @override |
| 5958 Element getElement(ElementLocation location) { |
| 5959 fail("Unexpected invocation of getElement"); |
| 5960 return null; |
| 5961 } |
| 5962 |
| 5963 @override |
| 5964 AnalysisErrorInfo getErrors(Source source) { |
| 5965 fail("Unexpected invocation of getErrors"); |
| 5966 return null; |
| 5967 } |
| 5968 |
| 5969 @override |
| 5970 @deprecated |
| 5971 HtmlElement getHtmlElement(Source source) { |
| 5972 fail("Unexpected invocation of getHtmlElement"); |
| 5973 return null; |
| 5974 } |
| 5975 |
| 5976 @override |
| 5977 List<Source> getHtmlFilesReferencing(Source source) { |
| 5978 fail("Unexpected invocation of getHtmlFilesReferencing"); |
| 5979 return null; |
| 5980 } |
| 5981 |
| 5982 @override |
| 5983 SourceKind getKindOf(Source source) { |
| 5984 fail("Unexpected invocation of getKindOf"); |
| 5985 return null; |
| 5986 } |
| 5987 |
| 5988 @override |
| 5989 List<Source> getLibrariesContaining(Source source) { |
| 5990 fail("Unexpected invocation of getLibrariesContaining"); |
| 5991 return null; |
| 5992 } |
| 5993 |
| 5994 @override |
| 5995 List<Source> getLibrariesDependingOn(Source librarySource) { |
| 5996 fail("Unexpected invocation of getLibrariesDependingOn"); |
| 5997 return null; |
| 5998 } |
| 5999 |
| 6000 @override |
| 6001 List<Source> getLibrariesReferencedFromHtml(Source htmlSource) { |
| 6002 fail("Unexpected invocation of getLibrariesReferencedFromHtml"); |
| 6003 return null; |
| 6004 } |
| 6005 |
| 6006 @override |
| 6007 LibraryElement getLibraryElement(Source source) { |
| 6008 fail("Unexpected invocation of getLibraryElement"); |
| 6009 return null; |
| 6010 } |
| 6011 |
| 6012 @override |
| 6013 LineInfo getLineInfo(Source source) { |
| 6014 fail("Unexpected invocation of getLineInfo"); |
| 6015 return null; |
| 6016 } |
| 6017 |
| 6018 @override |
| 6019 int getModificationStamp(Source source) { |
| 6020 fail("Unexpected invocation of getModificationStamp"); |
| 6021 return 0; |
| 6022 } |
| 6023 |
| 6024 @override |
| 6025 ChangeNoticeImpl getNotice(Source source) { |
| 6026 fail("Unexpected invocation of getNotice"); |
| 6027 return null; |
| 6028 } |
| 6029 |
| 6030 @override |
| 6031 Namespace getPublicNamespace(LibraryElement library) { |
| 6032 fail("Unexpected invocation of getPublicNamespace"); |
| 6033 return null; |
| 6034 } |
| 6035 |
| 6036 @override |
| 6037 CompilationUnit getResolvedCompilationUnit( |
| 6038 Source unitSource, LibraryElement library) { |
| 6039 fail("Unexpected invocation of getResolvedCompilationUnit"); |
| 6040 return null; |
| 6041 } |
| 6042 |
| 6043 @override |
| 6044 CompilationUnit getResolvedCompilationUnit2( |
| 6045 Source unitSource, Source librarySource) { |
| 6046 fail("Unexpected invocation of getResolvedCompilationUnit"); |
| 6047 return null; |
| 6048 } |
| 6049 |
| 6050 @override |
| 6051 @deprecated |
| 6052 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource) { |
| 6053 fail("Unexpected invocation of getResolvedHtmlUnit"); |
| 6054 return null; |
| 6055 } |
| 6056 |
| 6057 @override |
| 6058 Object getResult(AnalysisTarget target, ResultDescriptor result) { |
| 6059 fail("Unexpected invocation of getResult"); |
| 6060 return null; |
| 6061 } |
| 6062 |
| 6063 @override |
| 6064 List<Source> getSourcesWithFullName(String path) { |
| 6065 fail("Unexpected invocation of getSourcesWithFullName"); |
| 6066 return null; |
| 6067 } |
| 6068 |
| 6069 @override |
| 6070 bool handleContentsChanged( |
| 6071 Source source, String originalContents, String newContents, bool notify) { |
| 6072 fail("Unexpected invocation of handleContentsChanged"); |
| 6073 return false; |
| 6074 } |
| 6075 |
| 6076 @override |
| 6077 void invalidateLibraryHints(Source librarySource) { |
| 6078 fail("Unexpected invocation of invalidateLibraryHints"); |
| 6079 } |
| 6080 |
| 6081 @override |
| 6082 bool isClientLibrary(Source librarySource) { |
| 6083 fail("Unexpected invocation of isClientLibrary"); |
| 6084 return false; |
| 6085 } |
| 6086 |
| 6087 @override |
| 6088 bool isServerLibrary(Source librarySource) { |
| 6089 fail("Unexpected invocation of isServerLibrary"); |
| 6090 return false; |
| 6091 } |
| 6092 |
| 6093 @override |
| 6094 Stream<ComputedResult> onResultComputed(ResultDescriptor descriptor) { |
| 6095 fail("Unexpected invocation of onResultComputed"); |
| 6096 return null; |
| 6097 } |
| 6098 |
| 6099 @override |
| 6100 CompilationUnit parseCompilationUnit(Source source) { |
| 6101 fail("Unexpected invocation of parseCompilationUnit"); |
| 6102 return null; |
| 6103 } |
| 6104 |
| 6105 @override |
| 6106 Document parseHtmlDocument(Source source) { |
| 6107 fail("Unexpected invocation of parseHtmlDocument"); |
| 6108 return null; |
| 6109 } |
| 6110 |
| 6111 @override |
| 6112 ht.HtmlUnit parseHtmlUnit(Source source) { |
| 6113 fail("Unexpected invocation of parseHtmlUnit"); |
| 6114 return null; |
| 6115 } |
| 6116 |
| 6117 @override |
| 6118 AnalysisResult performAnalysisTask() { |
| 6119 fail("Unexpected invocation of performAnalysisTask"); |
| 6120 return null; |
| 6121 } |
| 6122 |
| 6123 @override |
| 6124 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { |
| 6125 fail("Unexpected invocation of recordLibraryElements"); |
| 6126 } |
| 6127 |
| 6128 @override |
| 6129 void removeListener(AnalysisListener listener) { |
| 6130 fail("Unexpected invocation of removeListener"); |
| 6131 } |
| 6132 |
| 6133 @override |
| 6134 CompilationUnit resolveCompilationUnit( |
| 6135 Source unitSource, LibraryElement library) { |
| 6136 fail("Unexpected invocation of resolveCompilationUnit"); |
| 6137 return null; |
| 6138 } |
| 6139 |
| 6140 @override |
| 6141 CompilationUnit resolveCompilationUnit2( |
| 6142 Source unitSource, Source librarySource) { |
| 6143 fail("Unexpected invocation of resolveCompilationUnit"); |
| 6144 return null; |
| 6145 } |
| 6146 |
| 6147 @override |
| 6148 @deprecated |
| 6149 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { |
| 6150 fail("Unexpected invocation of resolveHtmlUnit"); |
| 6151 return null; |
| 6152 } |
| 6153 |
| 6154 @override |
| 6155 void setChangedContents(Source source, String contents, int offset, |
| 6156 int oldLength, int newLength) { |
| 6157 fail("Unexpected invocation of setChangedContents"); |
| 6158 } |
| 6159 |
| 6160 @override |
| 6161 void setContents(Source source, String contents) { |
| 6162 fail("Unexpected invocation of setContents"); |
| 6163 } |
| 6164 |
| 6165 @override |
| 6166 bool shouldErrorsBeAnalyzed(Source source, Object entry) { |
| 6167 fail("Unexpected invocation of shouldErrorsBeAnalyzed"); |
| 6168 return false; |
| 6169 } |
| 6170 |
| 6171 @override |
| 6172 void test_flushAstStructures(Source source) { |
| 6173 fail("Unexpected invocation of test_flushAstStructures"); |
| 6174 } |
| 6175 |
| 6176 @override |
| 6177 bool validateCacheConsistency() { |
| 6178 fail("Unexpected invocation of validateCacheConsistency"); |
| 6179 return false; |
| 6180 } |
| 6181 |
| 6182 @deprecated |
| 6183 @override |
| 6184 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, |
| 6185 DataDescriptor rowDesc, CacheState state)) { |
| 6186 fail("Unexpected invocation of visitCacheItems"); |
| 6187 } |
| 6188 |
| 6189 @override |
| 6190 void visitContentCache(ContentCacheVisitor visitor) { |
| 6191 fail("Unexpected invocation of visitContentCache"); |
| 6192 } |
| 6193 } |
| 6194 |
| 6195 class TestAnalysisContext_test_applyChanges extends TestAnalysisContext { |
| 6196 bool invoked = false; |
| 6197 TestAnalysisContext_test_applyChanges(); |
| 6198 @override |
| 6199 void applyChanges(ChangeSet changeSet) { |
| 6200 invoked = true; |
| 6201 } |
| 6202 } |
| 6203 |
| 6204 class TestAnalysisContext_test_computeDocumentationComment |
| 6205 extends TestAnalysisContext { |
| 6206 bool invoked = false; |
| 6207 TestAnalysisContext_test_computeDocumentationComment(); |
| 6208 @override |
| 6209 String computeDocumentationComment(Element element) { |
| 6210 invoked = true; |
| 6211 return null; |
| 6212 } |
| 6213 } |
| 6214 |
| 6215 class TestAnalysisContext_test_computeErrors extends TestAnalysisContext { |
| 6216 bool invoked = false; |
| 6217 TestAnalysisContext_test_computeErrors(); |
| 6218 @override |
| 6219 List<AnalysisError> computeErrors(Source source) { |
| 6220 invoked = true; |
| 6221 return AnalysisError.NO_ERRORS; |
| 6222 } |
| 6223 } |
| 6224 |
| 6225 class TestAnalysisContext_test_computeExportedLibraries |
| 6226 extends TestAnalysisContext { |
| 6227 bool invoked = false; |
| 6228 TestAnalysisContext_test_computeExportedLibraries(); |
| 6229 @override |
| 6230 List<Source> computeExportedLibraries(Source source) { |
| 6231 invoked = true; |
| 6232 return null; |
| 6233 } |
| 6234 } |
| 6235 |
| 6236 class TestAnalysisContext_test_computeHtmlElement extends TestAnalysisContext { |
| 6237 bool invoked = false; |
| 6238 TestAnalysisContext_test_computeHtmlElement(); |
| 6239 @override |
| 6240 @deprecated |
| 6241 HtmlElement computeHtmlElement(Source source) { |
| 6242 invoked = true; |
| 6243 return null; |
| 6244 } |
| 6245 } |
| 6246 |
| 6247 class TestAnalysisContext_test_computeImportedLibraries |
| 6248 extends TestAnalysisContext { |
| 6249 bool invoked = false; |
| 6250 TestAnalysisContext_test_computeImportedLibraries(); |
| 6251 @override |
| 6252 List<Source> computeImportedLibraries(Source source) { |
| 6253 invoked = true; |
| 6254 return null; |
| 6255 } |
| 6256 } |
| 6257 |
| 6258 class TestAnalysisContext_test_computeKindOf extends TestAnalysisContext { |
| 6259 bool invoked = false; |
| 6260 TestAnalysisContext_test_computeKindOf(); |
| 6261 @override |
| 6262 SourceKind computeKindOf(Source source) { |
| 6263 invoked = true; |
| 6264 return null; |
| 6265 } |
| 6266 } |
| 6267 |
| 6268 class TestAnalysisContext_test_computeLibraryElement |
| 6269 extends TestAnalysisContext { |
| 6270 bool invoked = false; |
| 6271 TestAnalysisContext_test_computeLibraryElement(); |
| 6272 @override |
| 6273 LibraryElement computeLibraryElement(Source source) { |
| 6274 invoked = true; |
| 6275 return null; |
| 6276 } |
| 6277 } |
| 6278 |
| 6279 class TestAnalysisContext_test_computeLineInfo extends TestAnalysisContext { |
| 6280 bool invoked = false; |
| 6281 TestAnalysisContext_test_computeLineInfo(); |
| 6282 @override |
| 6283 LineInfo computeLineInfo(Source source) { |
| 6284 invoked = true; |
| 6285 return null; |
| 6286 } |
| 6287 } |
| 6288 |
| 6289 class TestAnalysisContext_test_computeResolvableCompilationUnit |
| 6290 extends TestAnalysisContext { |
| 6291 bool invoked = false; |
| 6292 TestAnalysisContext_test_computeResolvableCompilationUnit(); |
| 6293 @override |
| 6294 CompilationUnit computeResolvableCompilationUnit(Source source) { |
| 6295 invoked = true; |
| 6296 return null; |
| 6297 } |
| 6298 } |
| 6299 |
| 6300 class TestAnalysisContext_test_dispose extends TestAnalysisContext { |
| 6301 bool invoked = false; |
| 6302 TestAnalysisContext_test_dispose(); |
| 6303 @override |
| 6304 void dispose() { |
| 6305 invoked = true; |
| 6306 } |
| 6307 } |
| 6308 |
| 6309 class TestAnalysisContext_test_exists extends TestAnalysisContext { |
| 6310 bool invoked = false; |
| 6311 TestAnalysisContext_test_exists(); |
| 6312 @override |
| 6313 bool exists(Source source) { |
| 6314 invoked = true; |
| 6315 return false; |
| 6316 } |
| 6317 } |
| 6318 |
| 6319 class TestAnalysisContext_test_getAnalysisOptions extends TestAnalysisContext { |
| 6320 bool invoked = false; |
| 6321 TestAnalysisContext_test_getAnalysisOptions(); |
| 6322 @override |
| 6323 AnalysisOptions get analysisOptions { |
| 6324 invoked = true; |
| 6325 return null; |
| 6326 } |
| 6327 } |
| 6328 |
| 6329 class TestAnalysisContext_test_getCompilationUnitElement |
| 6330 extends TestAnalysisContext { |
| 6331 bool invoked = false; |
| 6332 TestAnalysisContext_test_getCompilationUnitElement(); |
| 6333 @override |
| 6334 CompilationUnitElement getCompilationUnitElement( |
| 6335 Source unitSource, Source librarySource) { |
| 6336 invoked = true; |
| 6337 return null; |
| 6338 } |
| 6339 } |
| 6340 |
| 6341 class TestAnalysisContext_test_getContents extends TestAnalysisContext { |
| 6342 bool invoked = false; |
| 6343 TestAnalysisContext_test_getContents(); |
| 6344 @override |
| 6345 TimestampedData<String> getContents(Source source) { |
| 6346 invoked = true; |
| 6347 return null; |
| 6348 } |
| 6349 } |
| 6350 |
| 6351 class TestAnalysisContext_test_getElement extends TestAnalysisContext { |
| 6352 bool invoked = false; |
| 6353 TestAnalysisContext_test_getElement(); |
| 6354 @override |
| 6355 Element getElement(ElementLocation location) { |
| 6356 invoked = true; |
| 6357 return null; |
| 6358 } |
| 6359 } |
| 6360 |
| 6361 class TestAnalysisContext_test_getErrors extends TestAnalysisContext { |
| 6362 bool invoked = false; |
| 6363 TestAnalysisContext_test_getErrors(); |
| 6364 @override |
| 6365 AnalysisErrorInfo getErrors(Source source) { |
| 6366 invoked = true; |
| 6367 return new AnalysisErrorInfoImpl(AnalysisError.NO_ERRORS, null); |
| 6368 } |
| 6369 } |
| 6370 |
| 6371 class TestAnalysisContext_test_getHtmlElement extends TestAnalysisContext { |
| 6372 bool invoked = false; |
| 6373 TestAnalysisContext_test_getHtmlElement(); |
| 6374 @override |
| 6375 @deprecated |
| 6376 HtmlElement getHtmlElement(Source source) { |
| 6377 invoked = true; |
| 6378 return null; |
| 6379 } |
| 6380 } |
| 6381 |
| 6382 class TestAnalysisContext_test_getHtmlFilesReferencing |
| 6383 extends TestAnalysisContext { |
| 6384 bool invoked = false; |
| 6385 TestAnalysisContext_test_getHtmlFilesReferencing(); |
| 6386 @override |
| 6387 List<Source> getHtmlFilesReferencing(Source source) { |
| 6388 invoked = true; |
| 6389 return Source.EMPTY_LIST; |
| 6390 } |
| 6391 } |
| 6392 |
| 6393 class TestAnalysisContext_test_getHtmlSources extends TestAnalysisContext { |
| 6394 bool invoked = false; |
| 6395 TestAnalysisContext_test_getHtmlSources(); |
| 6396 @override |
| 6397 List<Source> get htmlSources { |
| 6398 invoked = true; |
| 6399 return Source.EMPTY_LIST; |
| 6400 } |
| 6401 } |
| 6402 |
| 6403 class TestAnalysisContext_test_getKindOf extends TestAnalysisContext { |
| 6404 bool invoked = false; |
| 6405 TestAnalysisContext_test_getKindOf(); |
| 6406 @override |
| 6407 SourceKind getKindOf(Source source) { |
| 6408 invoked = true; |
| 6409 return null; |
| 6410 } |
| 6411 } |
| 6412 |
| 6413 class TestAnalysisContext_test_getLaunchableClientLibrarySources |
| 6414 extends TestAnalysisContext { |
| 6415 bool invoked = false; |
| 6416 TestAnalysisContext_test_getLaunchableClientLibrarySources(); |
| 6417 @override |
| 6418 List<Source> get launchableClientLibrarySources { |
| 6419 invoked = true; |
| 6420 return Source.EMPTY_LIST; |
| 6421 } |
| 6422 } |
| 6423 |
| 6424 class TestAnalysisContext_test_getLaunchableServerLibrarySources |
| 6425 extends TestAnalysisContext { |
| 6426 bool invoked = false; |
| 6427 TestAnalysisContext_test_getLaunchableServerLibrarySources(); |
| 6428 @override |
| 6429 List<Source> get launchableServerLibrarySources { |
| 6430 invoked = true; |
| 6431 return Source.EMPTY_LIST; |
| 6432 } |
| 6433 } |
| 6434 |
| 6435 class TestAnalysisContext_test_getLibrariesContaining |
| 6436 extends TestAnalysisContext { |
| 6437 bool invoked = false; |
| 6438 TestAnalysisContext_test_getLibrariesContaining(); |
| 6439 @override |
| 6440 List<Source> getLibrariesContaining(Source source) { |
| 6441 invoked = true; |
| 6442 return Source.EMPTY_LIST; |
| 6443 } |
| 6444 } |
| 6445 |
| 6446 class TestAnalysisContext_test_getLibrariesDependingOn |
| 6447 extends TestAnalysisContext { |
| 6448 bool invoked = false; |
| 6449 TestAnalysisContext_test_getLibrariesDependingOn(); |
| 6450 @override |
| 6451 List<Source> getLibrariesDependingOn(Source librarySource) { |
| 6452 invoked = true; |
| 6453 return Source.EMPTY_LIST; |
| 6454 } |
| 6455 } |
| 6456 |
| 6457 class TestAnalysisContext_test_getLibrariesReferencedFromHtml |
| 6458 extends TestAnalysisContext { |
| 6459 bool invoked = false; |
| 6460 TestAnalysisContext_test_getLibrariesReferencedFromHtml(); |
| 6461 @override |
| 6462 List<Source> getLibrariesReferencedFromHtml(Source htmlSource) { |
| 6463 invoked = true; |
| 6464 return null; |
| 6465 } |
| 6466 } |
| 6467 |
| 6468 class TestAnalysisContext_test_getLibraryElement extends TestAnalysisContext { |
| 6469 bool invoked = false; |
| 6470 TestAnalysisContext_test_getLibraryElement(); |
| 6471 @override |
| 6472 LibraryElement getLibraryElement(Source source) { |
| 6473 invoked = true; |
| 6474 return null; |
| 6475 } |
| 6476 } |
| 6477 |
| 6478 class TestAnalysisContext_test_getLibrarySources extends TestAnalysisContext { |
| 6479 bool invoked = false; |
| 6480 TestAnalysisContext_test_getLibrarySources(); |
| 6481 @override |
| 6482 List<Source> get librarySources { |
| 6483 invoked = true; |
| 6484 return Source.EMPTY_LIST; |
| 6485 } |
| 6486 } |
| 6487 |
| 6488 class TestAnalysisContext_test_getLineInfo extends TestAnalysisContext { |
| 6489 bool invoked = false; |
| 6490 TestAnalysisContext_test_getLineInfo(); |
| 6491 @override |
| 6492 LineInfo getLineInfo(Source source) { |
| 6493 invoked = true; |
| 6494 return null; |
| 6495 } |
| 6496 } |
| 6497 |
| 6498 class TestAnalysisContext_test_getModificationStamp |
| 6499 extends TestAnalysisContext { |
| 6500 bool invoked = false; |
| 6501 TestAnalysisContext_test_getModificationStamp(); |
| 6502 @override |
| 6503 int getModificationStamp(Source source) { |
| 6504 invoked = true; |
| 6505 return 0; |
| 6506 } |
| 6507 } |
| 6508 |
| 6509 class TestAnalysisContext_test_getPublicNamespace extends TestAnalysisContext { |
| 6510 bool invoked = false; |
| 6511 TestAnalysisContext_test_getPublicNamespace(); |
| 6512 @override |
| 6513 Namespace getPublicNamespace(LibraryElement library) { |
| 6514 invoked = true; |
| 6515 return null; |
| 6516 } |
| 6517 } |
| 6518 |
| 6519 class TestAnalysisContext_test_getResolvedCompilationUnit_element |
| 6520 extends TestAnalysisContext { |
| 6521 bool invoked = false; |
| 6522 TestAnalysisContext_test_getResolvedCompilationUnit_element(); |
| 6523 @override |
| 6524 CompilationUnit getResolvedCompilationUnit( |
| 6525 Source unitSource, LibraryElement library) { |
| 6526 invoked = true; |
| 6527 return null; |
| 6528 } |
| 6529 } |
| 6530 |
| 6531 class TestAnalysisContext_test_getResolvedCompilationUnit_source |
| 6532 extends TestAnalysisContext { |
| 6533 bool invoked = false; |
| 6534 TestAnalysisContext_test_getResolvedCompilationUnit_source(); |
| 6535 @override |
| 6536 CompilationUnit getResolvedCompilationUnit2( |
| 6537 Source unitSource, Source librarySource) { |
| 6538 invoked = true; |
| 6539 return null; |
| 6540 } |
| 6541 } |
| 6542 |
| 6543 class TestAnalysisContext_test_getResolvedHtmlUnit extends TestAnalysisContext { |
| 6544 bool invoked = false; |
| 6545 TestAnalysisContext_test_getResolvedHtmlUnit(); |
| 6546 @override |
| 6547 @deprecated |
| 6548 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource) { |
| 6549 invoked = true; |
| 6550 return null; |
| 6551 } |
| 6552 } |
| 6553 |
| 6554 class TestAnalysisContext_test_getSourceFactory extends TestAnalysisContext { |
| 6555 bool invoked = false; |
| 6556 TestAnalysisContext_test_getSourceFactory(); |
| 6557 @override |
| 6558 SourceFactory get sourceFactory { |
| 6559 invoked = true; |
| 6560 return null; |
| 6561 } |
| 6562 } |
| 6563 |
| 6564 class TestAnalysisContext_test_getStatistics extends TestAnalysisContext { |
| 6565 bool invoked = false; |
| 6566 TestAnalysisContext_test_getStatistics(); |
| 6567 @override |
| 6568 AnalysisContextStatistics get statistics { |
| 6569 invoked = true; |
| 6570 return null; |
| 6571 } |
| 6572 } |
| 6573 |
| 6574 class TestAnalysisContext_test_getTypeProvider extends TestAnalysisContext { |
| 6575 bool invoked = false; |
| 6576 TestAnalysisContext_test_getTypeProvider(); |
| 6577 @override |
| 6578 TypeProvider get typeProvider { |
| 6579 invoked = true; |
| 6580 return null; |
| 6581 } |
| 6582 } |
| 6583 |
| 6584 class TestAnalysisContext_test_isClientLibrary extends TestAnalysisContext { |
| 6585 bool invoked = false; |
| 6586 TestAnalysisContext_test_isClientLibrary(); |
| 6587 @override |
| 6588 bool isClientLibrary(Source librarySource) { |
| 6589 invoked = true; |
| 6590 return false; |
| 6591 } |
| 6592 } |
| 6593 |
| 6594 class TestAnalysisContext_test_isDisposed extends TestAnalysisContext { |
| 6595 bool invoked = false; |
| 6596 TestAnalysisContext_test_isDisposed(); |
| 6597 @override |
| 6598 bool get isDisposed { |
| 6599 invoked = true; |
| 6600 return false; |
| 6601 } |
| 6602 } |
| 6603 |
| 6604 class TestAnalysisContext_test_isServerLibrary extends TestAnalysisContext { |
| 6605 bool invoked = false; |
| 6606 TestAnalysisContext_test_isServerLibrary(); |
| 6607 @override |
| 6608 bool isServerLibrary(Source librarySource) { |
| 6609 invoked = true; |
| 6610 return false; |
| 6611 } |
| 6612 } |
| 6613 |
| 6614 class TestAnalysisContext_test_parseCompilationUnit |
| 6615 extends TestAnalysisContext { |
| 6616 bool invoked = false; |
| 6617 TestAnalysisContext_test_parseCompilationUnit(); |
| 6618 @override |
| 6619 CompilationUnit parseCompilationUnit(Source source) { |
| 6620 invoked = true; |
| 6621 return null; |
| 6622 } |
| 6623 } |
| 6624 |
| 6625 class TestAnalysisContext_test_parseHtmlUnit extends TestAnalysisContext { |
| 6626 bool invoked = false; |
| 6627 TestAnalysisContext_test_parseHtmlUnit(); |
| 6628 @override |
| 6629 ht.HtmlUnit parseHtmlUnit(Source source) { |
| 6630 invoked = true; |
| 6631 return null; |
| 6632 } |
| 6633 } |
| 6634 |
| 6635 class TestAnalysisContext_test_performAnalysisTask extends TestAnalysisContext { |
| 6636 bool invoked = false; |
| 6637 TestAnalysisContext_test_performAnalysisTask(); |
| 6638 @override |
| 6639 AnalysisResult performAnalysisTask() { |
| 6640 invoked = true; |
| 6641 return new AnalysisResult(new List<ChangeNotice>(0), 0, null, 0); |
| 6642 } |
| 6643 } |
| 6644 |
| 6645 class TestAnalysisContext_test_recordLibraryElements |
| 6646 extends TestAnalysisContext { |
| 6647 bool invoked = false; |
| 6648 TestAnalysisContext_test_recordLibraryElements(); |
| 6649 @override |
| 6650 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { |
| 6651 invoked = true; |
| 6652 } |
| 6653 } |
| 6654 |
| 6655 class TestAnalysisContext_test_resolveCompilationUnit |
| 6656 extends TestAnalysisContext { |
| 6657 bool invoked = false; |
| 6658 TestAnalysisContext_test_resolveCompilationUnit(); |
| 6659 @override |
| 6660 CompilationUnit resolveCompilationUnit2( |
| 6661 Source unitSource, Source librarySource) { |
| 6662 invoked = true; |
| 6663 return null; |
| 6664 } |
| 6665 } |
| 6666 |
| 6667 class TestAnalysisContext_test_resolveCompilationUnit_element |
| 6668 extends TestAnalysisContext { |
| 6669 bool invoked = false; |
| 6670 TestAnalysisContext_test_resolveCompilationUnit_element(); |
| 6671 @override |
| 6672 CompilationUnit resolveCompilationUnit( |
| 6673 Source unitSource, LibraryElement library) { |
| 6674 invoked = true; |
| 6675 return null; |
| 6676 } |
| 6677 } |
| 6678 |
| 6679 class TestAnalysisContext_test_resolveHtmlUnit extends TestAnalysisContext { |
| 6680 bool invoked = false; |
| 6681 TestAnalysisContext_test_resolveHtmlUnit(); |
| 6682 @override |
| 6683 @deprecated |
| 6684 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { |
| 6685 invoked = true; |
| 6686 return null; |
| 6687 } |
| 6688 } |
| 6689 |
| 6690 class TestAnalysisContext_test_setAnalysisOptions extends TestAnalysisContext { |
| 6691 bool invoked = false; |
| 6692 TestAnalysisContext_test_setAnalysisOptions(); |
| 6693 @override |
| 6694 void set analysisOptions(AnalysisOptions options) { |
| 6695 invoked = true; |
| 6696 } |
| 6697 } |
| 6698 |
| 6699 class TestAnalysisContext_test_setAnalysisPriorityOrder |
| 6700 extends TestAnalysisContext { |
| 6701 bool invoked = false; |
| 6702 TestAnalysisContext_test_setAnalysisPriorityOrder(); |
| 6703 @override |
| 6704 void set analysisPriorityOrder(List<Source> sources) { |
| 6705 invoked = true; |
| 6706 } |
| 6707 } |
| 6708 |
| 6709 class TestAnalysisContext_test_setChangedContents extends TestAnalysisContext { |
| 6710 bool invoked = false; |
| 6711 TestAnalysisContext_test_setChangedContents(); |
| 6712 @override |
| 6713 void setChangedContents(Source source, String contents, int offset, |
| 6714 int oldLength, int newLength) { |
| 6715 invoked = true; |
| 6716 } |
| 6717 } |
| 6718 |
| 6719 class TestAnalysisContext_test_setContents extends TestAnalysisContext { |
| 6720 bool invoked = false; |
| 6721 TestAnalysisContext_test_setContents(); |
| 6722 @override |
| 6723 void setContents(Source source, String contents) { |
| 6724 invoked = true; |
| 6725 } |
| 6726 } |
| 6727 |
| 6728 class TestAnalysisContext_test_setSourceFactory extends TestAnalysisContext { |
| 6729 bool invoked = false; |
| 6730 TestAnalysisContext_test_setSourceFactory(); |
| 6731 @override |
| 6732 void set sourceFactory(SourceFactory factory) { |
| 6733 invoked = true; |
| 6734 } |
| 6735 } |
| 6736 |
| 6737 /** |
| 6738 * Instances of the class `TestTaskVisitor` implement a task visitor that fails
if any of its |
| 6739 * methods are invoked. Subclasses typically override the expected methods to no
t cause a test |
| 6740 * failure. |
| 6741 */ |
| 6742 class TestTaskVisitor<E> implements AnalysisTaskVisitor<E> { |
| 6743 @override |
| 6744 E visitGenerateDartErrorsTask(GenerateDartErrorsTask task) { |
| 6745 fail("Unexpectedly invoked visitGenerateDartErrorsTask"); |
| 6746 return null; |
| 6747 } |
| 6748 |
| 6749 @override |
| 6750 E visitGenerateDartHintsTask(GenerateDartHintsTask task) { |
| 6751 fail("Unexpectedly invoked visitGenerateDartHintsTask"); |
| 6752 return null; |
| 6753 } |
| 6754 |
| 6755 @override |
| 6756 E visitGenerateDartLintsTask(GenerateDartLintsTask task) { |
| 6757 fail("Unexpectedly invoked visitGenerateDartLintsTask"); |
| 6758 return null; |
| 6759 } |
| 6760 |
| 6761 @override |
| 6762 E visitGetContentTask(GetContentTask task) { |
| 6763 fail("Unexpectedly invoked visitGetContentsTask"); |
| 6764 return null; |
| 6765 } |
| 6766 |
| 6767 @override |
| 6768 E visitIncrementalAnalysisTask( |
| 6769 IncrementalAnalysisTask incrementalAnalysisTask) { |
| 6770 fail("Unexpectedly invoked visitIncrementalAnalysisTask"); |
| 6771 return null; |
| 6772 } |
| 6773 |
| 6774 @override |
| 6775 E visitParseDartTask(ParseDartTask task) { |
| 6776 fail("Unexpectedly invoked visitParseDartTask"); |
| 6777 return null; |
| 6778 } |
| 6779 |
| 6780 @override |
| 6781 E visitParseHtmlTask(ParseHtmlTask task) { |
| 6782 fail("Unexpectedly invoked visitParseHtmlTask"); |
| 6783 return null; |
| 6784 } |
| 6785 |
| 6786 @override |
| 6787 E visitResolveDartLibraryCycleTask(ResolveDartLibraryCycleTask task) { |
| 6788 fail("Unexpectedly invoked visitResolveDartLibraryCycleTask"); |
| 6789 return null; |
| 6790 } |
| 6791 |
| 6792 @override |
| 6793 E visitResolveDartLibraryTask(ResolveDartLibraryTask task) { |
| 6794 fail("Unexpectedly invoked visitResolveDartLibraryTask"); |
| 6795 return null; |
| 6796 } |
| 6797 |
| 6798 @override |
| 6799 E visitResolveDartUnitTask(ResolveDartUnitTask task) { |
| 6800 fail("Unexpectedly invoked visitResolveDartUnitTask"); |
| 6801 return null; |
| 6802 } |
| 6803 |
| 6804 @override |
| 6805 E visitResolveHtmlTask(ResolveHtmlTask task) { |
| 6806 fail("Unexpectedly invoked visitResolveHtmlTask"); |
| 6807 return null; |
| 6808 } |
| 6809 |
| 6810 @override |
| 6811 E visitScanDartTask(ScanDartTask task) { |
| 6812 fail("Unexpectedly invoked visitScanDartTask"); |
| 6813 return null; |
| 6814 } |
| 6815 } |
| 6816 |
| 6817 @reflectiveTest |
| 6818 class UniversalCachePartitionTest extends EngineTestCase { |
| 6819 void test_contains() { |
| 6820 UniversalCachePartition partition = |
| 6821 new UniversalCachePartition(null, 8, null); |
| 6822 TestSource source = new TestSource(); |
| 6823 expect(partition.contains(source), isTrue); |
| 6824 } |
| 6825 |
| 6826 void test_creation() { |
| 6827 expect(new UniversalCachePartition(null, 8, null), isNotNull); |
| 6828 } |
| 6829 |
| 6830 void test_entrySet() { |
| 6831 UniversalCachePartition partition = |
| 6832 new UniversalCachePartition(null, 8, null); |
| 6833 TestSource source = new TestSource(); |
| 6834 DartEntry entry = new DartEntry(); |
| 6835 partition.put(source, entry); |
| 6836 Map<Source, SourceEntry> entryMap = partition.map; |
| 6837 expect(entryMap.length, 1); |
| 6838 Source entryKey = entryMap.keys.first; |
| 6839 expect(entryKey, same(source)); |
| 6840 expect(entryMap[entryKey], same(entry)); |
| 6841 } |
| 6842 |
| 6843 void test_get() { |
| 6844 UniversalCachePartition partition = |
| 6845 new UniversalCachePartition(null, 8, null); |
| 6846 TestSource source = new TestSource(); |
| 6847 expect(partition.get(source), isNull); |
| 6848 } |
| 6849 |
| 6850 void test_put_noFlush() { |
| 6851 UniversalCachePartition partition = |
| 6852 new UniversalCachePartition(null, 8, null); |
| 6853 TestSource source = new TestSource(); |
| 6854 DartEntry entry = new DartEntry(); |
| 6855 partition.put(source, entry); |
| 6856 expect(partition.get(source), same(entry)); |
| 6857 } |
| 6858 |
| 6859 void test_remove() { |
| 6860 UniversalCachePartition partition = |
| 6861 new UniversalCachePartition(null, 8, null); |
| 6862 TestSource source = new TestSource(); |
| 6863 DartEntry entry = new DartEntry(); |
| 6864 partition.put(source, entry); |
| 6865 expect(partition.get(source), same(entry)); |
| 6866 partition.remove(source); |
| 6867 expect(partition.get(source), isNull); |
| 6868 } |
| 6869 |
| 6870 void test_setMaxCacheSize() { |
| 6871 UniversalCachePartition partition = new UniversalCachePartition( |
| 6872 null, 8, new _UniversalCachePartitionTest_test_setMaxCacheSize()); |
| 6873 int size = 6; |
| 6874 for (int i = 0; i < size; i++) { |
| 6875 Source source = new TestSource("/test$i.dart"); |
| 6876 DartEntry entry = new DartEntry(); |
| 6877 entry.setValue(DartEntry.PARSED_UNIT, null); |
| 6878 partition.put(source, entry); |
| 6879 partition.accessedAst(source); |
| 6880 } |
| 6881 _assertNonFlushedCount(size, partition); |
| 6882 int newSize = size - 2; |
| 6883 partition.maxCacheSize = newSize; |
| 6884 _assertNonFlushedCount(newSize, partition); |
| 6885 } |
| 6886 |
| 6887 void test_size() { |
| 6888 UniversalCachePartition partition = |
| 6889 new UniversalCachePartition(null, 8, null); |
| 6890 int size = 4; |
| 6891 for (int i = 0; i < size; i++) { |
| 6892 Source source = new TestSource("/test$i.dart"); |
| 6893 partition.put(source, new DartEntry()); |
| 6894 partition.accessedAst(source); |
| 6895 } |
| 6896 expect(partition.size(), size); |
| 6897 } |
| 6898 |
| 6899 void _assertNonFlushedCount( |
| 6900 int expectedCount, UniversalCachePartition partition) { |
| 6901 int nonFlushedCount = 0; |
| 6902 Map<Source, SourceEntry> entryMap = partition.map; |
| 6903 entryMap.values.forEach((SourceEntry value) { |
| 6904 if (value.getState(DartEntry.PARSED_UNIT) != CacheState.FLUSHED) { |
| 6905 nonFlushedCount++; |
| 6906 } |
| 6907 }); |
| 6908 expect(nonFlushedCount, expectedCount); |
| 6909 } |
| 6910 } |
| 6911 |
| 6912 @reflectiveTest |
| 6913 class WorkManagerTest extends EngineTestCase { |
| 6914 void test_addFirst() { |
| 6915 TestSource source1 = new TestSource("/f1.dart"); |
| 6916 TestSource source2 = new TestSource("/f2.dart"); |
| 6917 WorkManager manager = new WorkManager(); |
| 6918 manager.add(source1, SourcePriority.UNKNOWN); |
| 6919 manager.addFirst(source2, SourcePriority.UNKNOWN); |
| 6920 WorkManager_WorkIterator iterator = manager.iterator(); |
| 6921 expect(iterator.next(), same(source2)); |
| 6922 expect(iterator.next(), same(source1)); |
| 6923 } |
| 6924 |
| 6925 void test_creation() { |
| 6926 expect(new WorkManager(), isNotNull); |
| 6927 } |
| 6928 |
| 6929 void test_iterator_empty() { |
| 6930 WorkManager manager = new WorkManager(); |
| 6931 WorkManager_WorkIterator iterator = manager.iterator(); |
| 6932 expect(iterator.hasNext, isFalse); |
| 6933 try { |
| 6934 iterator.next(); |
| 6935 fail("Expected NoSuchElementException"); |
| 6936 } on NoSuchElementException {} |
| 6937 } |
| 6938 |
| 6939 void test_iterator_nonEmpty() { |
| 6940 TestSource source = new TestSource(); |
| 6941 WorkManager manager = new WorkManager(); |
| 6942 manager.add(source, SourcePriority.UNKNOWN); |
| 6943 WorkManager_WorkIterator iterator = manager.iterator(); |
| 6944 expect(iterator.hasNext, isTrue); |
| 6945 expect(iterator.next(), same(source)); |
| 6946 } |
| 6947 |
| 6948 void test_remove() { |
| 6949 TestSource source1 = new TestSource("/f1.dart"); |
| 6950 TestSource source2 = new TestSource("/f2.dart"); |
| 6951 TestSource source3 = new TestSource("/f3.dart"); |
| 6952 WorkManager manager = new WorkManager(); |
| 6953 manager.add(source1, SourcePriority.UNKNOWN); |
| 6954 manager.add(source2, SourcePriority.UNKNOWN); |
| 6955 manager.add(source3, SourcePriority.UNKNOWN); |
| 6956 manager.remove(source2); |
| 6957 WorkManager_WorkIterator iterator = manager.iterator(); |
| 6958 expect(iterator.next(), same(source1)); |
| 6959 expect(iterator.next(), same(source3)); |
| 6960 } |
| 6961 |
| 6962 void test_toString_empty() { |
| 6963 WorkManager manager = new WorkManager(); |
| 6964 expect(manager.toString(), isNotNull); |
| 6965 } |
| 6966 |
| 6967 void test_toString_nonEmpty() { |
| 6968 WorkManager manager = new WorkManager(); |
| 6969 manager.add(new TestSource(), SourcePriority.HTML); |
| 6970 manager.add(new TestSource(), SourcePriority.LIBRARY); |
| 6971 manager.add(new TestSource(), SourcePriority.NORMAL_PART); |
| 6972 manager.add(new TestSource(), SourcePriority.PRIORITY_PART); |
| 6973 manager.add(new TestSource(), SourcePriority.UNKNOWN); |
| 6974 expect(manager.toString(), isNotNull); |
| 6975 } |
| 6976 } |
| 6977 |
| 6978 class _AnalysisCacheTest_test_setMaxCacheSize implements CacheRetentionPolicy { |
| 6979 @override |
| 6980 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => |
| 6981 RetentionPriority.LOW; |
| 6982 } |
| 6983 |
| 6984 class _AnalysisContext_sourceChangeDuringResolution |
| 6985 extends AnalysisContextForTests { |
| 6986 @override |
| 6987 DartEntry recordResolveDartLibraryTaskResults(ResolveDartLibraryTask task) { |
| 6988 ChangeSet changeSet = new ChangeSet(); |
| 6989 changeSet.changedSource(task.librarySource); |
| 6990 applyChanges(changeSet); |
| 6991 return super.recordResolveDartLibraryTaskResults(task); |
| 6992 } |
| 6993 } |
| 6994 |
| 6995 class _AnalysisContextImplTest_test_applyChanges_removeContainer |
| 6996 implements SourceContainer { |
| 6997 Source libB; |
| 6998 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); |
| 6999 @override |
| 7000 bool contains(Source source) => source == libB; |
| 7001 } |
| 7002 |
| 7003 class _Source_getContent_throwException extends NonExistingSource { |
| 7004 _Source_getContent_throwException(String name) |
| 7005 : super(name, pathos.toUri(name), UriKind.FILE_URI); |
| 7006 |
| 7007 @override |
| 7008 TimestampedData<String> get contents { |
| 7009 throw 'Read error'; |
| 7010 } |
| 7011 |
| 7012 @override |
| 7013 bool exists() => true; |
| 7014 } |
| 7015 |
| 7016 class _UniversalCachePartitionTest_test_setMaxCacheSize |
| 7017 implements CacheRetentionPolicy { |
| 7018 @override |
| 7019 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => |
| 7020 RetentionPriority.LOW; |
| 7021 } |
OLD | NEW |