| 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 test.src.context.context_test; | 5 library test.src.context.context_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/cancelable_future.dart'; | 10 import 'package:analyzer/src/cancelable_future.dart'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; | 44 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; |
| 45 import 'package:analyzer/src/generated/utilities_dart.dart'; | 45 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 46 import 'package:analyzer/src/plugin/engine_plugin.dart'; | 46 import 'package:analyzer/src/plugin/engine_plugin.dart'; |
| 47 import 'package:plugin/manager.dart'; | 47 import 'package:plugin/manager.dart'; |
| 48 import 'package:unittest/unittest.dart'; | 48 import 'package:unittest/unittest.dart'; |
| 49 import 'package:watcher/src/utils.dart'; | 49 import 'package:watcher/src/utils.dart'; |
| 50 | 50 |
| 51 import '../../generated/engine_test.dart'; | 51 import '../../generated/engine_test.dart'; |
| 52 import '../../generated/test_support.dart'; | 52 import '../../generated/test_support.dart'; |
| 53 import '../../reflective_tests.dart'; | 53 import '../../reflective_tests.dart'; |
| 54 import 'package:analyzer/task/dart.dart'; |
| 55 import '../mock_sdk.dart'; |
| 54 | 56 |
| 55 main() { | 57 main() { |
| 56 groupSep = ' | '; | 58 groupSep = ' | '; |
| 57 runReflectiveTests(AnalysisContextImplTest); | 59 runReflectiveTests(AnalysisContextImplTest); |
| 58 } | 60 } |
| 59 | 61 |
| 60 contextWithCore() { | 62 contextWithCore() { |
| 61 return new AnalysisContextForTests(); | 63 return new AnalysisContextForTests(); |
| 62 } | 64 } |
| 63 | 65 |
| 64 /** | 66 /** |
| 65 * An analysis context that has a fake SDK that is much smaller and faster for | 67 * An analysis context that has a fake SDK that is much smaller and faster for |
| 66 * testing purposes. | 68 * testing purposes. |
| 67 */ | 69 */ |
| 68 class AnalysisContextForTests extends AnalysisContextImpl { | 70 class AnalysisContextForTests extends AnalysisContextImpl { |
| 69 AnalysisContextForTests() { | 71 AnalysisContextForTests() { |
| 70 initWithCore(); | 72 DartSdk sdk = new MockSdk(); |
| 73 SourceFactory sourceFactory = |
| 74 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]); |
| 75 this.sourceFactory = sourceFactory; |
| 76 // initWithCore(); |
| 71 } | 77 } |
| 72 | 78 |
| 73 @override | 79 @override |
| 74 void set analysisOptions(AnalysisOptions options) { | 80 void set analysisOptions(AnalysisOptions options) { |
| 75 AnalysisOptions currentOptions = analysisOptions; | 81 AnalysisOptions currentOptions = analysisOptions; |
| 76 bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate != | 82 bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate != |
| 77 options.analyzeFunctionBodiesPredicate || | 83 options.analyzeFunctionBodiesPredicate || |
| 78 currentOptions.generateImplicitErrors != | 84 currentOptions.generateImplicitErrors != |
| 79 options.generateImplicitErrors || | 85 options.generateImplicitErrors || |
| 80 currentOptions.generateSdkErrors != options.generateSdkErrors || | 86 currentOptions.generateSdkErrors != options.generateSdkErrors || |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return super.getModificationStamp(source); | 120 return super.getModificationStamp(source); |
| 115 } | 121 } |
| 116 | 122 |
| 117 /** | 123 /** |
| 118 * Initialize the given analysis context with a fake core library already reso
lved. | 124 * Initialize the given analysis context with a fake core library already reso
lved. |
| 119 * | 125 * |
| 120 * @param context the context to be initialized (not `null`) | 126 * @param context the context to be initialized (not `null`) |
| 121 * @return the analysis context that was created | 127 * @return the analysis context that was created |
| 122 */ | 128 */ |
| 123 void initWithCore() { | 129 void initWithCore() { |
| 124 DirectoryBasedDartSdk sdk = new FakeSdk(new JavaFile("/fake/sdk")); | 130 AnalysisContext coreContext = sourceFactory.dartSdk.context; |
| 125 SourceFactory sourceFactory = | |
| 126 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]); | |
| 127 this.sourceFactory = sourceFactory; | |
| 128 AnalysisContext coreContext = sdk.context; | |
| 129 // | 131 // |
| 130 // dart:core | 132 // dart:core |
| 131 // | 133 // |
| 132 TestTypeProvider provider = new TestTypeProvider(); | 134 TestTypeProvider provider = new TestTypeProvider(); |
| 133 typeProvider = provider; | 135 typeProvider = provider; |
| 134 CompilationUnitElementImpl coreUnit = | 136 CompilationUnitElementImpl coreUnit = |
| 135 new CompilationUnitElementImpl("core.dart"); | 137 new CompilationUnitElementImpl("core.dart"); |
| 136 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); | 138 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); |
| 137 coreContext.setContents(coreSource, ""); | 139 coreContext.setContents(coreSource, ""); |
| 138 coreUnit.source = coreSource; | 140 coreUnit.source = coreSource; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // | 356 // |
| 355 // Record the elements. | 357 // Record the elements. |
| 356 // | 358 // |
| 357 HashMap<Source, LibraryElement> elementMap = | 359 HashMap<Source, LibraryElement> elementMap = |
| 358 new HashMap<Source, LibraryElement>(); | 360 new HashMap<Source, LibraryElement>(); |
| 359 elementMap[coreSource] = coreLibrary; | 361 elementMap[coreSource] = coreLibrary; |
| 360 elementMap[asyncSource] = asyncLibrary; | 362 elementMap[asyncSource] = asyncLibrary; |
| 361 elementMap[htmlSource] = htmlLibrary; | 363 elementMap[htmlSource] = htmlLibrary; |
| 362 elementMap[mathSource] = mathLibrary; | 364 elementMap[mathSource] = mathLibrary; |
| 363 recordLibraryElements(elementMap); | 365 recordLibraryElements(elementMap); |
| 366 elementMap.forEach((Source librarySource, LibraryElement library) { |
| 367 CompilationUnit unit = new CompilationUnit(null, null, null, null, null); |
| 368 unit.element = library.definingCompilationUnit; |
| 369 CacheEntry entry = getCacheEntry(librarySource); |
| 370 entry.setValue(PARSED_UNIT, unit); |
| 371 }); |
| 364 } | 372 } |
| 365 | 373 |
| 366 /** | 374 /** |
| 367 * Set the analysis options, even if they would force re-analysis. This method
should only be | 375 * Set the analysis options, even if they would force re-analysis. This method
should only be |
| 368 * invoked before the fake SDK is initialized. | 376 * invoked before the fake SDK is initialized. |
| 369 * | 377 * |
| 370 * @param options the analysis options to be set | 378 * @param options the analysis options to be set |
| 371 */ | 379 */ |
| 372 void _internalSetAnalysisOptions(AnalysisOptions options) { | 380 void _internalSetAnalysisOptions(AnalysisOptions options) { |
| 373 super.analysisOptions = options; | 381 super.analysisOptions = options; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 392 Source librarySource = _addSource("/lib.dart", r''' | 400 Source librarySource = _addSource("/lib.dart", r''' |
| 393 library lib; | 401 library lib; |
| 394 int a = 0;'''); | 402 int a = 0;'''); |
| 395 expect(_context.computeLibraryElement(librarySource), isNotNull); | 403 expect(_context.computeLibraryElement(librarySource), isNotNull); |
| 396 _context.setContents(librarySource, r''' | 404 _context.setContents(librarySource, r''' |
| 397 library lib; | 405 library lib; |
| 398 int aa = 0;'''); | 406 int aa = 0;'''); |
| 399 expect(_context.getLibraryElement(librarySource), isNull); | 407 expect(_context.getLibraryElement(librarySource), isNull); |
| 400 } | 408 } |
| 401 | 409 |
| 402 Future fail_applyChanges_change_multiple() { | 410 Future test_applyChanges_change_multiple() { |
| 403 _context = contextWithCore(); | 411 _context = contextWithCore(); |
| 404 SourcesChangedListener listener = new SourcesChangedListener(); | 412 SourcesChangedListener listener = new SourcesChangedListener(); |
| 405 _context.onSourcesChanged.listen(listener.onData); | 413 _context.onSourcesChanged.listen(listener.onData); |
| 406 _sourceFactory = _context.sourceFactory; | 414 _sourceFactory = _context.sourceFactory; |
| 407 String libraryContents1 = r''' | 415 String libraryContents1 = r''' |
| 408 library lib; | 416 library lib; |
| 409 part 'part.dart'; | 417 part 'part.dart'; |
| 410 int a = 0;'''; | 418 int a = 0;'''; |
| 411 Source librarySource = _addSource("/lib.dart", libraryContents1); | 419 Source librarySource = _addSource("/lib.dart", libraryContents1); |
| 412 String partContents1 = r''' | 420 String partContents1 = r''' |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 return pumpEventQueue().then((_) { | 545 return pumpEventQueue().then((_) { |
| 538 listener.assertEvent(wereSourcesAdded: true); | 546 listener.assertEvent(wereSourcesAdded: true); |
| 539 listener.assertEvent(changedSources: [libA]); | 547 listener.assertEvent(changedSources: [libA]); |
| 540 listener.assertEvent(wereSourcesAdded: true); | 548 listener.assertEvent(wereSourcesAdded: true); |
| 541 listener.assertEvent(changedSources: [libB]); | 549 listener.assertEvent(changedSources: [libB]); |
| 542 listener.assertEvent(wereSourcesRemovedOrDeleted: true); | 550 listener.assertEvent(wereSourcesRemovedOrDeleted: true); |
| 543 listener.assertNoMoreEvents(); | 551 listener.assertNoMoreEvents(); |
| 544 }); | 552 }); |
| 545 } | 553 } |
| 546 | 554 |
| 547 void fail_computeDocumentationComment_block() { | 555 void test_computeDocumentationComment_block() { |
| 548 _context = contextWithCore(); | 556 _context = contextWithCore(); |
| 549 _sourceFactory = _context.sourceFactory; | 557 _sourceFactory = _context.sourceFactory; |
| 550 String comment = "/** Comment */"; | 558 String comment = "/** Comment */"; |
| 551 Source source = _addSource("/test.dart", """ | 559 Source source = _addSource("/test.dart", """ |
| 552 $comment | 560 $comment |
| 553 class A {}"""); | 561 class A {}"""); |
| 554 LibraryElement libraryElement = _context.computeLibraryElement(source); | 562 LibraryElement libraryElement = _context.computeLibraryElement(source); |
| 555 expect(libraryElement, isNotNull); | 563 expect(libraryElement, isNotNull); |
| 556 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | 564 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
| 557 expect(libraryElement, isNotNull); | 565 expect(libraryElement, isNotNull); |
| 558 expect(_context.computeDocumentationComment(classElement), comment); | 566 expect(_context.computeDocumentationComment(classElement), comment); |
| 559 } | 567 } |
| 560 | 568 |
| 561 void fail_computeDocumentationComment_none() { | 569 void test_computeDocumentationComment_none() { |
| 562 _context = contextWithCore(); | 570 _context = contextWithCore(); |
| 563 _sourceFactory = _context.sourceFactory; | 571 _sourceFactory = _context.sourceFactory; |
| 564 Source source = _addSource("/test.dart", "class A {}"); | 572 Source source = _addSource("/test.dart", "class A {}"); |
| 565 LibraryElement libraryElement = _context.computeLibraryElement(source); | 573 LibraryElement libraryElement = _context.computeLibraryElement(source); |
| 566 expect(libraryElement, isNotNull); | 574 expect(libraryElement, isNotNull); |
| 567 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | 575 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
| 568 expect(libraryElement, isNotNull); | 576 expect(libraryElement, isNotNull); |
| 569 expect(_context.computeDocumentationComment(classElement), isNull); | 577 expect(_context.computeDocumentationComment(classElement), isNull); |
| 570 } | 578 } |
| 571 | 579 |
| 572 void fail_computeDocumentationComment_singleLine_multiple_EOL_n() { | 580 void test_computeDocumentationComment_singleLine_multiple_EOL_n() { |
| 573 _context = contextWithCore(); | 581 _context = contextWithCore(); |
| 574 _sourceFactory = _context.sourceFactory; | 582 _sourceFactory = _context.sourceFactory; |
| 575 String comment = "/// line 1\n/// line 2\n/// line 3\n"; | 583 String comment = "/// line 1\n/// line 2\n/// line 3\n"; |
| 576 Source source = _addSource("/test.dart", "${comment}class A {}"); | 584 Source source = _addSource("/test.dart", "${comment}class A {}"); |
| 577 LibraryElement libraryElement = _context.computeLibraryElement(source); | 585 LibraryElement libraryElement = _context.computeLibraryElement(source); |
| 578 expect(libraryElement, isNotNull); | 586 expect(libraryElement, isNotNull); |
| 579 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | 587 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
| 580 expect(libraryElement, isNotNull); | 588 expect(libraryElement, isNotNull); |
| 581 String actual = _context.computeDocumentationComment(classElement); | 589 String actual = _context.computeDocumentationComment(classElement); |
| 582 expect(actual, "/// line 1\n/// line 2\n/// line 3"); | 590 expect(actual, "/// line 1\n/// line 2\n/// line 3"); |
| 583 } | 591 } |
| 584 | 592 |
| 585 void fail_computeDocumentationComment_singleLine_multiple_EOL_rn() { | 593 void test_computeDocumentationComment_singleLine_multiple_EOL_rn() { |
| 586 _context = contextWithCore(); | 594 _context = contextWithCore(); |
| 587 _sourceFactory = _context.sourceFactory; | 595 _sourceFactory = _context.sourceFactory; |
| 588 String comment = "/// line 1\r\n/// line 2\r\n/// line 3\r\n"; | 596 String comment = "/// line 1\r\n/// line 2\r\n/// line 3\r\n"; |
| 589 Source source = _addSource("/test.dart", "${comment}class A {}"); | 597 Source source = _addSource("/test.dart", "${comment}class A {}"); |
| 590 LibraryElement libraryElement = _context.computeLibraryElement(source); | 598 LibraryElement libraryElement = _context.computeLibraryElement(source); |
| 591 expect(libraryElement, isNotNull); | 599 expect(libraryElement, isNotNull); |
| 592 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | 600 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
| 593 expect(libraryElement, isNotNull); | 601 expect(libraryElement, isNotNull); |
| 594 String actual = _context.computeDocumentationComment(classElement); | 602 String actual = _context.computeDocumentationComment(classElement); |
| 595 expect(actual, "/// line 1\n/// line 2\n/// line 3"); | 603 expect(actual, "/// line 1\n/// line 2\n/// line 3"); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 Source source = _addSource( | 650 Source source = _addSource( |
| 643 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); | 651 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); |
| 644 expect(_context.computeImportedLibraries(source), hasLength(2)); | 652 expect(_context.computeImportedLibraries(source), hasLength(2)); |
| 645 } | 653 } |
| 646 | 654 |
| 647 void fail_computeKindOf_html() { | 655 void fail_computeKindOf_html() { |
| 648 Source source = _addSource("/test.html", ""); | 656 Source source = _addSource("/test.html", ""); |
| 649 expect(_context.computeKindOf(source), same(SourceKind.HTML)); | 657 expect(_context.computeKindOf(source), same(SourceKind.HTML)); |
| 650 } | 658 } |
| 651 | 659 |
| 652 void fail_computeLibraryElement() { | 660 void test_computeLibraryElement() { |
| 653 _context = contextWithCore(); | 661 _context = contextWithCore(); |
| 654 _sourceFactory = _context.sourceFactory; | 662 _sourceFactory = _context.sourceFactory; |
| 655 Source source = _addSource("/test.dart", "library lib;"); | 663 Source source = _addSource("/test.dart", "library lib;"); |
| 656 LibraryElement element = _context.computeLibraryElement(source); | 664 LibraryElement element = _context.computeLibraryElement(source); |
| 657 expect(element, isNotNull); | 665 expect(element, isNotNull); |
| 658 } | 666 } |
| 659 | 667 |
| 660 void fail_computeResolvableCompilationUnit_dart_exception() { | 668 void fail_computeResolvableCompilationUnit_dart_exception() { |
| 661 TestSource source = _addSourceWithException("/test.dart"); | 669 TestSource source = _addSourceWithException("/test.dart"); |
| 662 try { | 670 try { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 completed = true; | 712 completed = true; |
| 705 }); | 713 }); |
| 706 return pumpEventQueue().then((_) { | 714 return pumpEventQueue().then((_) { |
| 707 expect(completed, isFalse); | 715 expect(completed, isFalse); |
| 708 _performPendingAnalysisTasks(); | 716 _performPendingAnalysisTasks(); |
| 709 }).then((_) => pumpEventQueue()).then((_) { | 717 }).then((_) => pumpEventQueue()).then((_) { |
| 710 expect(completed, isTrue); | 718 expect(completed, isTrue); |
| 711 }); | 719 }); |
| 712 } | 720 } |
| 713 | 721 |
| 714 Future fail_computeResolvedCompilationUnitAsync_afterDispose() { | 722 Future test_computeResolvedCompilationUnitAsync_afterDispose() { |
| 715 _context = contextWithCore(); | 723 _context = contextWithCore(); |
| 716 _sourceFactory = _context.sourceFactory; | 724 _sourceFactory = _context.sourceFactory; |
| 717 Source source = _addSource("/lib.dart", "library lib;"); | 725 Source source = _addSource("/lib.dart", "library lib;"); |
| 718 // Complete all pending analysis tasks and flush the AST so that it won't | 726 // Complete all pending analysis tasks and flush the AST so that it won't |
| 719 // be available immediately. | 727 // be available immediately. |
| 720 _performPendingAnalysisTasks(); | 728 _performPendingAnalysisTasks(); |
| 721 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); | 729 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); |
| 722 entry.flushAstStructures(); | 730 entry.flushAstStructures(); |
| 723 // Dispose of the context. | 731 // Dispose of the context. |
| 724 _context.dispose(); | 732 _context.dispose(); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 <script type='application/dart' src='test.js'/> | 1001 <script type='application/dart' src='test.js'/> |
| 994 </head></html>'''); | 1002 </head></html>'''); |
| 995 Source librarySource = _addSource("/test.dart", "library lib;"); | 1003 Source librarySource = _addSource("/test.dart", "library lib;"); |
| 996 _context.computeLibraryElement(librarySource); | 1004 _context.computeLibraryElement(librarySource); |
| 997 _context.parseHtmlUnit(htmlSource); | 1005 _context.parseHtmlUnit(htmlSource); |
| 998 List<Source> result = _context.getLibrariesReferencedFromHtml(htmlSource); | 1006 List<Source> result = _context.getLibrariesReferencedFromHtml(htmlSource); |
| 999 expect(result, hasLength(1)); | 1007 expect(result, hasLength(1)); |
| 1000 expect(result[0], librarySource); | 1008 expect(result[0], librarySource); |
| 1001 } | 1009 } |
| 1002 | 1010 |
| 1003 void fail_getLibraryElement() { | 1011 void test_getLibraryElement() { |
| 1004 _context = contextWithCore(); | 1012 _context = contextWithCore(); |
| 1005 _sourceFactory = _context.sourceFactory; | 1013 _sourceFactory = _context.sourceFactory; |
| 1006 Source source = _addSource("/test.dart", "library lib;"); | 1014 Source source = _addSource("/test.dart", "library lib;"); |
| 1007 LibraryElement element = _context.getLibraryElement(source); | 1015 LibraryElement element = _context.getLibraryElement(source); |
| 1008 expect(element, isNull); | 1016 expect(element, isNull); |
| 1009 _context.computeLibraryElement(source); | 1017 _context.computeLibraryElement(source); |
| 1010 element = _context.getLibraryElement(source); | 1018 element = _context.getLibraryElement(source); |
| 1011 expect(element, isNotNull); | 1019 expect(element, isNotNull); |
| 1012 } | 1020 } |
| 1013 | 1021 |
| 1014 void fail_getPublicNamespace_element() { | 1022 void test_getPublicNamespace_element() { |
| 1015 _context = contextWithCore(); | 1023 _context = contextWithCore(); |
| 1016 _sourceFactory = _context.sourceFactory; | 1024 _sourceFactory = _context.sourceFactory; |
| 1017 Source source = _addSource("/test.dart", "class A {}"); | 1025 Source source = _addSource("/test.dart", "class A {}"); |
| 1018 LibraryElement library = _context.computeLibraryElement(source); | 1026 LibraryElement library = _context.computeLibraryElement(source); |
| 1019 expect(library, isNotNull); | 1027 expect(library, isNotNull); |
| 1020 Namespace namespace = _context.getPublicNamespace(library); | 1028 Namespace namespace = _context.getPublicNamespace(library); |
| 1021 expect(namespace, isNotNull); | 1029 expect(namespace, isNotNull); |
| 1022 EngineTestCase.assertInstanceOf( | 1030 EngineTestCase.assertInstanceOf( |
| 1023 (obj) => obj is ClassElement, ClassElement, namespace.get("A")); | 1031 (obj) => obj is ClassElement, ClassElement, namespace.get("A")); |
| 1024 } | 1032 } |
| 1025 | 1033 |
| 1026 void fail_getResolvedCompilationUnit_library() { | 1034 void fail_getResolvedCompilationUnit_library() { |
| 1027 _context = contextWithCore(); | 1035 _context = contextWithCore(); |
| 1028 _sourceFactory = _context.sourceFactory; | 1036 _sourceFactory = _context.sourceFactory; |
| 1029 Source source = _addSource("/lib.dart", "library libb;"); | 1037 Source source = _addSource("/lib.dart", "library libb;"); |
| 1030 LibraryElement library = _context.computeLibraryElement(source); | 1038 LibraryElement library = _context.computeLibraryElement(source); |
| 1031 expect(_context.getResolvedCompilationUnit(source, library), isNotNull); | 1039 expect(_context.getResolvedCompilationUnit(source, library), isNotNull); |
| 1032 _context.setContents(source, "library lib;"); | 1040 _context.setContents(source, "library lib;"); |
| 1033 expect(_context.getResolvedCompilationUnit(source, library), isNull); | 1041 expect(_context.getResolvedCompilationUnit(source, library), isNull); |
| 1034 } | 1042 } |
| 1035 | 1043 |
| 1036 void fail_getResolvedCompilationUnit_source_dart() { | 1044 void test_getResolvedCompilationUnit_source_dart() { |
| 1037 _context = contextWithCore(); | 1045 _context = contextWithCore(); |
| 1038 _sourceFactory = _context.sourceFactory; | 1046 _sourceFactory = _context.sourceFactory; |
| 1039 Source source = _addSource("/lib.dart", "library lib;"); | 1047 Source source = _addSource("/lib.dart", "library lib;"); |
| 1040 expect(_context.getResolvedCompilationUnit2(source, source), isNull); | 1048 expect(_context.getResolvedCompilationUnit2(source, source), isNull); |
| 1041 _context.resolveCompilationUnit2(source, source); | 1049 _context.resolveCompilationUnit2(source, source); |
| 1042 expect(_context.getResolvedCompilationUnit2(source, source), isNotNull); | 1050 expect(_context.getResolvedCompilationUnit2(source, source), isNotNull); |
| 1043 } | 1051 } |
| 1044 | 1052 |
| 1045 void fail_getResolvedHtmlUnit() { | 1053 void fail_getResolvedHtmlUnit() { |
| 1046 _context = contextWithCore(); | 1054 _context = contextWithCore(); |
| 1047 _sourceFactory = _context.sourceFactory; | 1055 _sourceFactory = _context.sourceFactory; |
| 1048 Source source = _addSource("/test.html", "<html></html>"); | 1056 Source source = _addSource("/test.html", "<html></html>"); |
| 1049 expect(_context.getResolvedHtmlUnit(source), isNull); | 1057 expect(_context.getResolvedHtmlUnit(source), isNull); |
| 1050 _context.resolveHtmlUnit(source); | 1058 _context.resolveHtmlUnit(source); |
| 1051 expect(_context.getResolvedHtmlUnit(source), isNotNull); | 1059 expect(_context.getResolvedHtmlUnit(source), isNotNull); |
| 1052 } | 1060 } |
| 1053 | 1061 |
| 1054 void fail_mergeContext() { | 1062 void fail_mergeContext() { |
| 1055 fail("Implement this"); | 1063 fail("Implement this"); |
| 1056 } | 1064 } |
| 1057 | 1065 |
| 1058 void fail_parseCompilationUnit_errors() { | 1066 void test_parseCompilationUnit_errors() { |
| 1059 Source source = _addSource("/lib.dart", "library {"); | 1067 Source source = _addSource("/lib.dart", "library {"); |
| 1060 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); | 1068 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); |
| 1061 expect(compilationUnit, isNotNull); | 1069 expect(compilationUnit, isNotNull); |
| 1062 var errorInfo = _context.getErrors(source); | 1070 var errorInfo = _context.getErrors(source); |
| 1063 expect(errorInfo, isNotNull); | 1071 expect(errorInfo, isNotNull); |
| 1064 List<AnalysisError> errors = errorInfo.errors; | 1072 List<AnalysisError> errors = errorInfo.errors; |
| 1065 expect(errors, isNotNull); | 1073 expect(errors, isNotNull); |
| 1066 expect(errors.length > 0, isTrue); | 1074 expect(errors.length > 0, isTrue); |
| 1067 } | 1075 } |
| 1068 | 1076 |
| 1069 void fail_parseCompilationUnit_exception() { | 1077 void test_parseCompilationUnit_exception() { |
| 1070 Source source = _addSourceWithException("/test.dart"); | 1078 Source source = _addSourceWithException("/test.dart"); |
| 1071 try { | 1079 try { |
| 1072 _context.parseCompilationUnit(source); | 1080 _context.parseCompilationUnit(source); |
| 1073 fail("Expected AnalysisException"); | 1081 fail("Expected AnalysisException"); |
| 1074 } on AnalysisException { | 1082 } on AnalysisException { |
| 1075 // Expected | 1083 // Expected |
| 1076 } | 1084 } |
| 1077 } | 1085 } |
| 1078 | 1086 |
| 1079 void fail_parseCompilationUnit_noErrors() { | 1087 void test_parseCompilationUnit_noErrors() { |
| 1080 Source source = _addSource("/lib.dart", "library lib;"); | 1088 Source source = _addSource("/lib.dart", "library lib;"); |
| 1081 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); | 1089 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); |
| 1082 expect(compilationUnit, isNotNull); | 1090 expect(compilationUnit, isNotNull); |
| 1083 AnalysisErrorInfo errorInfo = _context.getErrors(source); | 1091 AnalysisErrorInfo errorInfo = _context.getErrors(source); |
| 1084 expect(errorInfo, isNotNull); | 1092 expect(errorInfo, isNotNull); |
| 1085 expect(errorInfo.errors, hasLength(0)); | 1093 expect(errorInfo.errors, hasLength(0)); |
| 1086 } | 1094 } |
| 1087 | 1095 |
| 1088 void fail_parseCompilationUnit_nonExistentSource() { | 1096 void test_parseCompilationUnit_nonExistentSource() { |
| 1089 Source source = | 1097 Source source = |
| 1090 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); | 1098 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); |
| 1091 try { | 1099 try { |
| 1092 _context.parseCompilationUnit(source); | 1100 _context.parseCompilationUnit(source); |
| 1093 fail("Expected AnalysisException because file does not exist"); | 1101 fail("Expected AnalysisException because file does not exist"); |
| 1094 } on AnalysisException { | 1102 } on AnalysisException { |
| 1095 // Expected result | 1103 // Expected result |
| 1096 } | 1104 } |
| 1097 } | 1105 } |
| 1098 | 1106 |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 CompilationUnit compilationUnit = | 1510 CompilationUnit compilationUnit = |
| 1503 _context.resolveCompilationUnit2(sourceA, sourceA); | 1511 _context.resolveCompilationUnit2(sourceA, sourceA); |
| 1504 expect(compilationUnit, isNotNull); | 1512 expect(compilationUnit, isNotNull); |
| 1505 LibraryElement library = compilationUnit.element.library; | 1513 LibraryElement library = compilationUnit.element.library; |
| 1506 List<LibraryElement> importedLibraries = library.importedLibraries; | 1514 List<LibraryElement> importedLibraries = library.importedLibraries; |
| 1507 assertNamedElements(importedLibraries, ["dart.core", "libB"]); | 1515 assertNamedElements(importedLibraries, ["dart.core", "libB"]); |
| 1508 List<LibraryElement> visibleLibraries = library.visibleLibraries; | 1516 List<LibraryElement> visibleLibraries = library.visibleLibraries; |
| 1509 assertNamedElements(visibleLibraries, ["dart.core", "libA", "libB"]); | 1517 assertNamedElements(visibleLibraries, ["dart.core", "libA", "libB"]); |
| 1510 } | 1518 } |
| 1511 | 1519 |
| 1512 void fail_resolveCompilationUnit_library() { | 1520 void test_resolveCompilationUnit_library() { |
| 1513 _context = contextWithCore(); | 1521 _context = contextWithCore(); |
| 1514 _sourceFactory = _context.sourceFactory; | 1522 _sourceFactory = _context.sourceFactory; |
| 1515 Source source = _addSource("/lib.dart", "library lib;"); | 1523 Source source = _addSource("/lib.dart", "library lib;"); |
| 1516 LibraryElement library = _context.computeLibraryElement(source); | 1524 LibraryElement library = _context.computeLibraryElement(source); |
| 1517 CompilationUnit compilationUnit = | 1525 CompilationUnit compilationUnit = |
| 1518 _context.resolveCompilationUnit(source, library); | 1526 _context.resolveCompilationUnit(source, library); |
| 1519 expect(compilationUnit, isNotNull); | 1527 expect(compilationUnit, isNotNull); |
| 1520 expect(compilationUnit.element, isNotNull); | 1528 expect(compilationUnit.element, isNotNull); |
| 1521 } | 1529 } |
| 1522 | 1530 |
| 1523 void fail_resolveCompilationUnit_source() { | 1531 void test_resolveCompilationUnit_source() { |
| 1524 _context = contextWithCore(); | 1532 _context = contextWithCore(); |
| 1525 _sourceFactory = _context.sourceFactory; | 1533 _sourceFactory = _context.sourceFactory; |
| 1526 Source source = _addSource("/lib.dart", "library lib;"); | 1534 Source source = _addSource("/lib.dart", "library lib;"); |
| 1527 CompilationUnit compilationUnit = | 1535 CompilationUnit compilationUnit = |
| 1528 _context.resolveCompilationUnit2(source, source); | 1536 _context.resolveCompilationUnit2(source, source); |
| 1529 expect(compilationUnit, isNotNull); | 1537 expect(compilationUnit, isNotNull); |
| 1530 } | 1538 } |
| 1531 | 1539 |
| 1532 void fail_resolveHtmlUnit() { | 1540 void fail_resolveHtmlUnit() { |
| 1533 Source source = _addSource("/lib.html", "<html></html>"); | 1541 Source source = _addSource("/lib.html", "<html></html>"); |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2473 List<AnalysisError> errors = errorInfo.errors; | 2481 List<AnalysisError> errors = errorInfo.errors; |
| 2474 for (AnalysisError analysisError in errors) { | 2482 for (AnalysisError analysisError in errors) { |
| 2475 if (analysisError.errorCode.errorSeverity == ErrorSeverity.ERROR) { | 2483 if (analysisError.errorCode.errorSeverity == ErrorSeverity.ERROR) { |
| 2476 return true; | 2484 return true; |
| 2477 } | 2485 } |
| 2478 } | 2486 } |
| 2479 return false; | 2487 return false; |
| 2480 } | 2488 } |
| 2481 } | 2489 } |
| 2482 | 2490 |
| 2483 class FakeSdk extends DirectoryBasedDartSdk { | 2491 //class FakeSdk extends DirectoryBasedDartSdk { |
| 2484 FakeSdk(JavaFile arg0) : super(arg0); | 2492 // FakeSdk(JavaFile arg0) : super(arg0); |
| 2485 | 2493 // |
| 2486 @override | 2494 // @override |
| 2487 LibraryMap initialLibraryMap(bool useDart2jsPaths) { | 2495 // LibraryMap initialLibraryMap(bool useDart2jsPaths) { |
| 2488 LibraryMap map = new LibraryMap(); | 2496 // LibraryMap map = new LibraryMap(); |
| 2489 _addLibrary(map, DartSdk.DART_ASYNC, false, "async.dart"); | 2497 // _addLibrary(map, DartSdk.DART_ASYNC, false, "async.dart"); |
| 2490 _addLibrary(map, DartSdk.DART_CORE, false, "core.dart"); | 2498 // _addLibrary(map, DartSdk.DART_CORE, false, "core.dart"); |
| 2491 _addLibrary(map, DartSdk.DART_HTML, false, "html_dartium.dart"); | 2499 // _addLibrary(map, DartSdk.DART_HTML, false, "html_dartium.dart"); |
| 2492 _addLibrary(map, "dart:math", false, "math.dart"); | 2500 // _addLibrary(map, "dart:math", false, "math.dart"); |
| 2493 _addLibrary(map, "dart:_interceptors", true, "_interceptors.dart"); | 2501 // _addLibrary(map, "dart:_interceptors", true, "_interceptors.dart"); |
| 2494 _addLibrary(map, "dart:_js_helper", true, "_js_helper.dart"); | 2502 // _addLibrary(map, "dart:_js_helper", true, "_js_helper.dart"); |
| 2495 return map; | 2503 // return map; |
| 2496 } | 2504 // } |
| 2497 | 2505 // |
| 2498 void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { | 2506 // void _addLibrary(LibraryMap map, String uri, bool isInternal, String path) { |
| 2499 SdkLibraryImpl library = new SdkLibraryImpl(uri); | 2507 // SdkLibraryImpl library = new SdkLibraryImpl(uri); |
| 2500 if (isInternal) { | 2508 // if (isInternal) { |
| 2501 library.category = "Internal"; | 2509 // library.category = "Internal"; |
| 2502 } | 2510 // } |
| 2503 library.path = path; | 2511 // library.path = path; |
| 2504 map.setLibrary(uri, library); | 2512 // map.setLibrary(uri, library); |
| 2505 } | 2513 // } |
| 2506 } | 2514 //} |
| 2507 | 2515 |
| 2508 class _AnalysisContextImplTest_test_applyChanges_removeContainer | 2516 class _AnalysisContextImplTest_test_applyChanges_removeContainer |
| 2509 implements SourceContainer { | 2517 implements SourceContainer { |
| 2510 Source libB; | 2518 Source libB; |
| 2511 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); | 2519 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); |
| 2512 @override | 2520 @override |
| 2513 bool contains(Source source) => source == libB; | 2521 bool contains(Source source) => source == libB; |
| 2514 } | 2522 } |
| 2515 | 2523 |
| 2516 class _Source_getContent_throwException extends NonExistingSource { | 2524 class _Source_getContent_throwException extends NonExistingSource { |
| 2517 _Source_getContent_throwException(String name) | 2525 _Source_getContent_throwException(String name) |
| 2518 : super(name, UriKind.FILE_URI); | 2526 : super(name, UriKind.FILE_URI); |
| 2519 | 2527 |
| 2520 @override | 2528 @override |
| 2521 TimestampedData<String> get contents { | 2529 TimestampedData<String> get contents { |
| 2522 throw 'Read error'; | 2530 throw 'Read error'; |
| 2523 } | 2531 } |
| 2524 | 2532 |
| 2525 @override | 2533 @override |
| 2526 bool exists() => true; | 2534 bool exists() => true; |
| 2527 } | 2535 } |
| OLD | NEW |