Add utility method to SubscriptionManager

R=mfairhurst@google.com

Review-Url: https://codereview.chromium.org/2983913002 .
This commit is contained in:
Brian Wilkerson 2017-07-21 07:24:54 -07:00
parent 3e563c6e9e
commit 8a275e6df8
2 changed files with 37 additions and 3 deletions

View file

@ -20,6 +20,18 @@ class SubscriptionManager {
*/
SubscriptionManager();
/**
* Return `true` if the file with the given [filePath] has a subscription for
* the given [service].
*/
bool hasSubscriptionForFile(String filePath, AnalysisService service) {
if (_subscriptions == null) {
return false;
}
List<String> files = _subscriptions[service];
return files != null && files.contains(filePath);
}
/**
* Return a list of the services for which the file with the given [filePath]
* has been subscribed.

View file

@ -15,14 +15,36 @@ void main() {
class SubscriptionManagerTest {
SubscriptionManager manager = new SubscriptionManager();
String fooPath = '/project/lib/foo.dart';
String barPath = '/project/lib/bar.dart';
String bazPath = '/project/lib/baz.dart';
test_hasSubscriptionForFile_differentSubscription() {
manager.setSubscriptions({
AnalysisService.NAVIGATION: [barPath]
});
expect(manager.hasSubscriptionForFile(fooPath, AnalysisService.HIGHLIGHTS),
isFalse);
}
test_hasSubscriptionForFile_hasSubscription() {
manager.setSubscriptions({
AnalysisService.HIGHLIGHTS: [fooPath]
});
expect(manager.hasSubscriptionForFile(fooPath, AnalysisService.HIGHLIGHTS),
isTrue);
}
test_hasSubscriptionForFile_noSubscription() {
expect(manager.hasSubscriptionForFile(fooPath, AnalysisService.HIGHLIGHTS),
isFalse);
}
test_servicesForFile() {
expect(manager.servicesForFile('/project/lib/test.dart'), hasLength(0));
}
test_setSubscriptions() {
String fooPath = '/project/lib/foo.dart';
String barPath = '/project/lib/bar.dart';
String bazPath = '/project/lib/baz.dart';
//
// Set the initial set of subscriptions.
//