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