| 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 | 8 |
| 9 import 'package:analyzer/file_system/memory_file_system.dart'; | 9 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 10 import 'package:analyzer/src/cancelable_future.dart'; | 10 import 'package:analyzer/src/cancelable_future.dart'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 import 'abstract_context.dart'; | 48 import 'abstract_context.dart'; |
| 49 | 49 |
| 50 main() { | 50 main() { |
| 51 groupSep = ' | '; | 51 groupSep = ' | '; |
| 52 runReflectiveTests(AnalysisContextImplTest); | 52 runReflectiveTests(AnalysisContextImplTest); |
| 53 runReflectiveTests(LimitedInvalidateTest); | 53 runReflectiveTests(LimitedInvalidateTest); |
| 54 } | 54 } |
| 55 | 55 |
| 56 @reflectiveTest | 56 @reflectiveTest |
| 57 class AnalysisContextImplTest extends AbstractContextTest { | 57 class AnalysisContextImplTest extends AbstractContextTest { |
| 58 Future fail_analyzedSources_removed() async { | 58 Future fail_implicitAnalysisEvents_removed() async { |
| 59 AnalyzedSourcesListener listener = new AnalyzedSourcesListener(); | 59 AnalyzedSourcesListener listener = new AnalyzedSourcesListener(); |
| 60 context.implicitAnalysisEvents.listen(listener.onData); | 60 context.implicitAnalysisEvents.listen(listener.onData); |
| 61 // | 61 // |
| 62 // Create a file that references an file that is not explicitly being | 62 // Create a file that references an file that is not explicitly being |
| 63 // analyzed and fully analyze it. Ensure that the listener is told about | 63 // analyzed and fully analyze it. Ensure that the listener is told about |
| 64 // the implicitly analyzed file. | 64 // the implicitly analyzed file. |
| 65 // | 65 // |
| 66 Source sourceA = newSource('/a.dart', "library a; import 'b.dart';"); | 66 Source sourceA = newSource('/a.dart', "library a; import 'b.dart';"); |
| 67 Source sourceB = newSource('/b.dart', "library b;"); | 67 Source sourceB = newSource('/b.dart', "library b;"); |
| 68 ChangeSet changeSet = new ChangeSet(); | 68 ChangeSet changeSet = new ChangeSet(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 fail("Implement this"); | 109 fail("Implement this"); |
| 110 } | 110 } |
| 111 | 111 |
| 112 @override | 112 @override |
| 113 void tearDown() { | 113 void tearDown() { |
| 114 context = null; | 114 context = null; |
| 115 sourceFactory = null; | 115 sourceFactory = null; |
| 116 super.tearDown(); | 116 super.tearDown(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 Future test_analyzedSources_added() async { | |
| 120 AnalyzedSourcesListener listener = new AnalyzedSourcesListener(); | |
| 121 context.implicitAnalysisEvents.listen(listener.onData); | |
| 122 // | |
| 123 // Create a file that references an file that is not explicitly being | |
| 124 // analyzed and fully analyze it. Ensure that the listener is told about | |
| 125 // the implicitly analyzed file. | |
| 126 // | |
| 127 Source sourceA = newSource('/a.dart', "library a; import 'b.dart';"); | |
| 128 Source sourceB = newSource('/b.dart', "library b;"); | |
| 129 ChangeSet changeSet = new ChangeSet(); | |
| 130 changeSet.addedSource(sourceA); | |
| 131 context.applyChanges(changeSet); | |
| 132 context.computeErrors(sourceA); | |
| 133 await pumpEventQueue(); | |
| 134 listener.expectAnalyzed(sourceB); | |
| 135 } | |
| 136 | |
| 137 Future test_applyChanges_add() { | 119 Future test_applyChanges_add() { |
| 138 SourcesChangedListener listener = new SourcesChangedListener(); | 120 SourcesChangedListener listener = new SourcesChangedListener(); |
| 139 context.onSourcesChanged.listen(listener.onData); | 121 context.onSourcesChanged.listen(listener.onData); |
| 140 expect(context.sourcesNeedingProcessing, isEmpty); | 122 expect(context.sourcesNeedingProcessing, isEmpty); |
| 141 Source source = newSource('/test.dart'); | 123 Source source = newSource('/test.dart'); |
| 142 ChangeSet changeSet = new ChangeSet(); | 124 ChangeSet changeSet = new ChangeSet(); |
| 143 changeSet.addedSource(source); | 125 changeSet.addedSource(source); |
| 144 context.applyChanges(changeSet); | 126 context.applyChanges(changeSet); |
| 145 expect(context.sourcesNeedingProcessing, contains(source)); | 127 expect(context.sourcesNeedingProcessing, contains(source)); |
| 146 return pumpEventQueue().then((_) { | 128 return pumpEventQueue().then((_) { |
| (...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 _analyzeAll_assertFinished(); | 1225 _analyzeAll_assertFinished(); |
| 1244 expect(context.getResolvedCompilationUnit2(source, source), isNotNull); | 1226 expect(context.getResolvedCompilationUnit2(source, source), isNotNull); |
| 1245 // new contents | 1227 // new contents |
| 1246 contentCache.setContents(source, newContents); | 1228 contentCache.setContents(source, newContents); |
| 1247 context.handleContentsChanged(source, oldContents, newContents, true); | 1229 context.handleContentsChanged(source, oldContents, newContents, true); |
| 1248 // there is some work to do | 1230 // there is some work to do |
| 1249 AnalysisResult analysisResult = context.performAnalysisTask(); | 1231 AnalysisResult analysisResult = context.performAnalysisTask(); |
| 1250 expect(analysisResult.changeNotices, isNotNull); | 1232 expect(analysisResult.changeNotices, isNotNull); |
| 1251 } | 1233 } |
| 1252 | 1234 |
| 1235 Future test_implicitAnalysisEvents_added() async { |
| 1236 AnalyzedSourcesListener listener = new AnalyzedSourcesListener(); |
| 1237 context.implicitAnalysisEvents.listen(listener.onData); |
| 1238 // |
| 1239 // Create a file that references an file that is not explicitly being |
| 1240 // analyzed and fully analyze it. Ensure that the listener is told about |
| 1241 // the implicitly analyzed file. |
| 1242 // |
| 1243 Source sourceA = newSource('/a.dart', "library a; import 'b.dart';"); |
| 1244 Source sourceB = newSource('/b.dart', "library b;"); |
| 1245 ChangeSet changeSet = new ChangeSet(); |
| 1246 changeSet.addedSource(sourceA); |
| 1247 context.applyChanges(changeSet); |
| 1248 context.computeErrors(sourceA); |
| 1249 await pumpEventQueue(); |
| 1250 listener.expectAnalyzed(sourceB); |
| 1251 } |
| 1252 |
| 1253 void test_isClientLibrary_dart() { | 1253 void test_isClientLibrary_dart() { |
| 1254 Source source = addSource("/test.dart", r''' | 1254 Source source = addSource("/test.dart", r''' |
| 1255 import 'dart:html'; | 1255 import 'dart:html'; |
| 1256 | 1256 |
| 1257 main() {}'''); | 1257 main() {}'''); |
| 1258 expect(context.isClientLibrary(source), isFalse); | 1258 expect(context.isClientLibrary(source), isFalse); |
| 1259 expect(context.isServerLibrary(source), isFalse); | 1259 expect(context.isServerLibrary(source), isFalse); |
| 1260 context.computeLibraryElement(source); | 1260 context.computeLibraryElement(source); |
| 1261 expect(context.isClientLibrary(source), isTrue); | 1261 expect(context.isClientLibrary(source), isTrue); |
| 1262 expect(context.isServerLibrary(source), isFalse); | 1262 expect(context.isServerLibrary(source), isFalse); |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2350 } | 2350 } |
| 2351 } | 2351 } |
| 2352 | 2352 |
| 2353 class _AnalysisContextImplTest_test_applyChanges_removeContainer | 2353 class _AnalysisContextImplTest_test_applyChanges_removeContainer |
| 2354 implements SourceContainer { | 2354 implements SourceContainer { |
| 2355 Source libB; | 2355 Source libB; |
| 2356 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); | 2356 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); |
| 2357 @override | 2357 @override |
| 2358 bool contains(Source source) => source == libB; | 2358 bool contains(Source source) => source == libB; |
| 2359 } | 2359 } |
| OLD | NEW |