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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
7 | 7 |
8 library engine.engine_test; | 8 library engine.engine_test; |
9 | 9 |
10 import 'dart:async'; | 10 import 'dart:async'; |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 void test_computeResolvableCompilationUnit_valid() { | 662 void test_computeResolvableCompilationUnit_valid() { |
663 Source source = _addSource("/lib.dart", "library lib;"); | 663 Source source = _addSource("/lib.dart", "library lib;"); |
664 CompilationUnit parsedUnit = _context.parseCompilationUnit(source); | 664 CompilationUnit parsedUnit = _context.parseCompilationUnit(source); |
665 expect(parsedUnit, isNotNull); | 665 expect(parsedUnit, isNotNull); |
666 CompilationUnit resolvedUnit = | 666 CompilationUnit resolvedUnit = |
667 _context.computeResolvableCompilationUnit(source); | 667 _context.computeResolvableCompilationUnit(source); |
668 expect(resolvedUnit, isNotNull); | 668 expect(resolvedUnit, isNotNull); |
669 expect(resolvedUnit, same(parsedUnit)); | 669 expect(resolvedUnit, same(parsedUnit)); |
670 } | 670 } |
671 | 671 |
| 672 Future test_computeResolvedCompilationUnitAsync() { |
| 673 _context = AnalysisContextFactory.contextWithCore(); |
| 674 _sourceFactory = _context.sourceFactory; |
| 675 Source source = _addSource("/lib.dart", "library lib;"); |
| 676 // Complete all pending analysis tasks and flush the AST so that it won't |
| 677 // be available immediately. |
| 678 _performPendingAnalysisTasks(); |
| 679 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); |
| 680 dartEntry.flushAstStructures(); |
| 681 bool completed = false; |
| 682 _context.computeResolvedCompilationUnitAsync( |
| 683 source, |
| 684 source).then((CompilationUnit unit) { |
| 685 expect(unit, isNotNull); |
| 686 completed = true; |
| 687 }); |
| 688 return pumpEventQueue().then((_) { |
| 689 expect(completed, isFalse); |
| 690 _performPendingAnalysisTasks(); |
| 691 }).then((_) => pumpEventQueue()).then((_) { |
| 692 expect(completed, isTrue); |
| 693 }); |
| 694 } |
| 695 |
| 696 Future test_computeResolvedCompilationUnitAsync_afterDispose() { |
| 697 _context = AnalysisContextFactory.contextWithCore(); |
| 698 _sourceFactory = _context.sourceFactory; |
| 699 Source source = _addSource("/lib.dart", "library lib;"); |
| 700 // Complete all pending analysis tasks and flush the AST so that it won't |
| 701 // be available immediately. |
| 702 _performPendingAnalysisTasks(); |
| 703 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); |
| 704 dartEntry.flushAstStructures(); |
| 705 // Dispose of the context. |
| 706 _context.dispose(); |
| 707 // Any attempt to start an asynchronous computation should return a future |
| 708 // which completes with error. |
| 709 CancelableFuture<CompilationUnit> future = |
| 710 _context.computeResolvedCompilationUnitAsync(source, source); |
| 711 bool completed = false; |
| 712 future.then((CompilationUnit unit) { |
| 713 fail('Future should have completed with error'); |
| 714 }, onError: (error) { |
| 715 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); |
| 716 completed = true; |
| 717 }); |
| 718 return pumpEventQueue().then((_) { |
| 719 expect(completed, isTrue); |
| 720 }); |
| 721 } |
| 722 |
| 723 Future test_computeResolvedCompilationUnitAsync_cancel() { |
| 724 _context = AnalysisContextFactory.contextWithCore(); |
| 725 _sourceFactory = _context.sourceFactory; |
| 726 Source source = _addSource("/lib.dart", "library lib;"); |
| 727 // Complete all pending analysis tasks and flush the AST so that it won't |
| 728 // be available immediately. |
| 729 _performPendingAnalysisTasks(); |
| 730 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); |
| 731 dartEntry.flushAstStructures(); |
| 732 CancelableFuture<CompilationUnit> future = |
| 733 _context.computeResolvedCompilationUnitAsync(source, source); |
| 734 bool completed = false; |
| 735 future.then((CompilationUnit unit) { |
| 736 fail('Future should have been canceled'); |
| 737 }, onError: (error) { |
| 738 expect(error, new isInstanceOf<FutureCanceledError>()); |
| 739 completed = true; |
| 740 }); |
| 741 expect(completed, isFalse); |
| 742 expect(_context.pendingFutureSources_forTesting, isNotEmpty); |
| 743 future.cancel(); |
| 744 expect(_context.pendingFutureSources_forTesting, isEmpty); |
| 745 return pumpEventQueue().then((_) { |
| 746 expect(completed, isTrue); |
| 747 expect(_context.pendingFutureSources_forTesting, isEmpty); |
| 748 }); |
| 749 } |
| 750 |
| 751 Future test_computeResolvedCompilationUnitAsync_dispose() { |
| 752 _context = AnalysisContextFactory.contextWithCore(); |
| 753 _sourceFactory = _context.sourceFactory; |
| 754 Source source = _addSource("/lib.dart", "library lib;"); |
| 755 // Complete all pending analysis tasks and flush the AST so that it won't |
| 756 // be available immediately. |
| 757 _performPendingAnalysisTasks(); |
| 758 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); |
| 759 dartEntry.flushAstStructures(); |
| 760 CancelableFuture<CompilationUnit> future = |
| 761 _context.computeResolvedCompilationUnitAsync(source, source); |
| 762 bool completed = false; |
| 763 future.then((CompilationUnit unit) { |
| 764 fail('Future should have completed with error'); |
| 765 }, onError: (error) { |
| 766 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); |
| 767 completed = true; |
| 768 }); |
| 769 expect(completed, isFalse); |
| 770 expect(_context.pendingFutureSources_forTesting, isNotEmpty); |
| 771 // Disposing of the context should cause all pending futures to complete |
| 772 // with AnalysisNotScheduled, so that no clients are left hanging. |
| 773 _context.dispose(); |
| 774 expect(_context.pendingFutureSources_forTesting, isEmpty); |
| 775 return pumpEventQueue().then((_) { |
| 776 expect(completed, isTrue); |
| 777 expect(_context.pendingFutureSources_forTesting, isEmpty); |
| 778 }); |
| 779 } |
| 780 |
| 781 Future test_computeResolvedCompilationUnitAsync_unrelatedLibrary() { |
| 782 _context = AnalysisContextFactory.contextWithCore(); |
| 783 _sourceFactory = _context.sourceFactory; |
| 784 Source librarySource = _addSource("/lib.dart", "library lib;"); |
| 785 Source partSource = _addSource("/part.dart", "part of foo;"); |
| 786 bool completed = false; |
| 787 _context.computeResolvedCompilationUnitAsync( |
| 788 partSource, |
| 789 librarySource).then((_) { |
| 790 fail('Expected resolution to fail'); |
| 791 }, onError: (e) { |
| 792 expect(e, new isInstanceOf<AnalysisNotScheduledError>()); |
| 793 completed = true; |
| 794 }); |
| 795 return pumpEventQueue().then((_) { |
| 796 expect(completed, isFalse); |
| 797 _performPendingAnalysisTasks(); |
| 798 }).then((_) => pumpEventQueue()).then((_) { |
| 799 expect(completed, isTrue); |
| 800 }); |
| 801 } |
| 802 |
672 void test_dispose() { | 803 void test_dispose() { |
673 expect(_context.isDisposed, isFalse); | 804 expect(_context.isDisposed, isFalse); |
674 _context.dispose(); | 805 _context.dispose(); |
675 expect(_context.isDisposed, isTrue); | 806 expect(_context.isDisposed, isTrue); |
676 } | 807 } |
677 | 808 |
678 void test_exists_false() { | 809 void test_exists_false() { |
679 TestSource source = new TestSource(); | 810 TestSource source = new TestSource(); |
680 source.exists2 = false; | 811 source.exists2 = false; |
681 expect(_context.exists(source), isFalse); | 812 expect(_context.exists(source), isFalse); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 | 1253 |
1123 void test_getResolvedCompilationUnit_source_html() { | 1254 void test_getResolvedCompilationUnit_source_html() { |
1124 _context = AnalysisContextFactory.contextWithCore(); | 1255 _context = AnalysisContextFactory.contextWithCore(); |
1125 _sourceFactory = _context.sourceFactory; | 1256 _sourceFactory = _context.sourceFactory; |
1126 Source source = _addSource("/test.html", "<html></html>"); | 1257 Source source = _addSource("/test.html", "<html></html>"); |
1127 expect(_context.getResolvedCompilationUnit2(source, source), isNull); | 1258 expect(_context.getResolvedCompilationUnit2(source, source), isNull); |
1128 expect(_context.resolveCompilationUnit2(source, source), isNull); | 1259 expect(_context.resolveCompilationUnit2(source, source), isNull); |
1129 expect(_context.getResolvedCompilationUnit2(source, source), isNull); | 1260 expect(_context.getResolvedCompilationUnit2(source, source), isNull); |
1130 } | 1261 } |
1131 | 1262 |
1132 Future test_getResolvedCompilationUnitFuture() { | |
1133 _context = AnalysisContextFactory.contextWithCore(); | |
1134 _sourceFactory = _context.sourceFactory; | |
1135 Source source = _addSource("/lib.dart", "library lib;"); | |
1136 // Complete all pending analysis tasks and flush the AST so that it won't | |
1137 // be available immediately. | |
1138 _performPendingAnalysisTasks(); | |
1139 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); | |
1140 dartEntry.flushAstStructures(); | |
1141 bool completed = false; | |
1142 _context.computeResolvedCompilationUnitAsync( | |
1143 source, | |
1144 source).then((CompilationUnit unit) { | |
1145 expect(unit, isNotNull); | |
1146 completed = true; | |
1147 }); | |
1148 return pumpEventQueue().then((_) { | |
1149 expect(completed, isFalse); | |
1150 _performPendingAnalysisTasks(); | |
1151 }).then((_) => pumpEventQueue()).then((_) { | |
1152 expect(completed, isTrue); | |
1153 }); | |
1154 } | |
1155 | |
1156 Future test_getResolvedCompilationUnitFuture_cancel() { | |
1157 _context = AnalysisContextFactory.contextWithCore(); | |
1158 _sourceFactory = _context.sourceFactory; | |
1159 Source source = _addSource("/lib.dart", "library lib;"); | |
1160 // Complete all pending analysis tasks and flush the AST so that it won't | |
1161 // be available immediately. | |
1162 _performPendingAnalysisTasks(); | |
1163 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); | |
1164 dartEntry.flushAstStructures(); | |
1165 CancelableFuture<CompilationUnit> future = | |
1166 _context.computeResolvedCompilationUnitAsync(source, source); | |
1167 bool completed = false; | |
1168 future.then((CompilationUnit unit) { | |
1169 fail('Future should have been canceled'); | |
1170 }, onError: (error) { | |
1171 expect(error, new isInstanceOf<FutureCanceledError>()); | |
1172 completed = true; | |
1173 }); | |
1174 expect(completed, isFalse); | |
1175 expect(_context.pendingFutureSources_forTesting, isNotEmpty); | |
1176 future.cancel(); | |
1177 expect(_context.pendingFutureSources_forTesting, isEmpty); | |
1178 return pumpEventQueue().then((_) { | |
1179 expect(completed, isTrue); | |
1180 expect(_context.pendingFutureSources_forTesting, isEmpty); | |
1181 }); | |
1182 } | |
1183 | |
1184 Future test_getResolvedCompilationUnitFuture_unrelatedLibrary() { | |
1185 _context = AnalysisContextFactory.contextWithCore(); | |
1186 _sourceFactory = _context.sourceFactory; | |
1187 Source librarySource = _addSource("/lib.dart", "library lib;"); | |
1188 Source partSource = _addSource("/part.dart", "part of foo;"); | |
1189 bool completed = false; | |
1190 _context.computeResolvedCompilationUnitAsync( | |
1191 partSource, | |
1192 librarySource).then((_) { | |
1193 fail('Expected resolution to fail'); | |
1194 }, onError: (e) { | |
1195 expect(e, new isInstanceOf<AnalysisNotScheduledError>()); | |
1196 completed = true; | |
1197 }); | |
1198 return pumpEventQueue().then((_) { | |
1199 expect(completed, isFalse); | |
1200 _performPendingAnalysisTasks(); | |
1201 }).then((_) => pumpEventQueue()).then((_) { | |
1202 expect(completed, isTrue); | |
1203 }); | |
1204 } | |
1205 | |
1206 void test_getResolvedHtmlUnit() { | 1263 void test_getResolvedHtmlUnit() { |
1207 _context = AnalysisContextFactory.contextWithCore(); | 1264 _context = AnalysisContextFactory.contextWithCore(); |
1208 _sourceFactory = _context.sourceFactory; | 1265 _sourceFactory = _context.sourceFactory; |
1209 Source source = _addSource("/test.html", "<html></html>"); | 1266 Source source = _addSource("/test.html", "<html></html>"); |
1210 expect(_context.getResolvedHtmlUnit(source), isNull); | 1267 expect(_context.getResolvedHtmlUnit(source), isNull); |
1211 _context.resolveHtmlUnit(source); | 1268 _context.resolveHtmlUnit(source); |
1212 expect(_context.getResolvedHtmlUnit(source), isNotNull); | 1269 expect(_context.getResolvedHtmlUnit(source), isNotNull); |
1213 } | 1270 } |
1214 | 1271 |
1215 void test_getSourceFactory() { | 1272 void test_getSourceFactory() { |
(...skipping 5875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7091 bool contains(Source source) => source == libB; | 7148 bool contains(Source source) => source == libB; |
7092 } | 7149 } |
7093 | 7150 |
7094 | 7151 |
7095 class _UniversalCachePartitionTest_test_setMaxCacheSize implements | 7152 class _UniversalCachePartitionTest_test_setMaxCacheSize implements |
7096 CacheRetentionPolicy { | 7153 CacheRetentionPolicy { |
7097 @override | 7154 @override |
7098 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => | 7155 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => |
7099 RetentionPriority.LOW; | 7156 RetentionPriority.LOW; |
7100 } | 7157 } |
OLD | NEW |