mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 21:21:18 +00:00
Add utility method to SubscriptionManager
R=mfairhurst@google.com Review-Url: https://codereview.chromium.org/2983913002 .
This commit is contained in:
parent
3e563c6e9e
commit
8a275e6df8
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue