Index: pkg/analyzer_plugin/test/plugin/plugin_test.dart |
diff --git a/pkg/analyzer_plugin/test/plugin/plugin_test.dart b/pkg/analyzer_plugin/test/plugin/plugin_test.dart |
index 9ebb327f3cfd9ed7c37716fea45e5ed8dc5c4ae5..8d0213d3f6fa78752c4484fc2c95e868fffa410c 100644 |
--- a/pkg/analyzer_plugin/test/plugin/plugin_test.dart |
+++ b/pkg/analyzer_plugin/test/plugin/plugin_test.dart |
@@ -2,6 +2,8 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
+import 'dart:async'; |
+ |
import 'package:analyzer/file_system/file_system.dart'; |
import 'package:analyzer/file_system/memory_file_system.dart'; |
import 'package:analyzer/src/dart/analysis/driver.dart'; |
@@ -362,6 +364,39 @@ class ServerPluginTest { |
expect(result.version, '0.1.0'); |
} |
+ test_sendNotificationsForFile() { |
+ AnalysisService service1 = AnalysisService.FOLDING; |
+ AnalysisService service2 = AnalysisService.NAVIGATION; |
+ AnalysisService service3 = AnalysisService.OUTLINE; |
+ plugin.subscriptionManager.setSubscriptions({ |
+ service1: [filePath1, filePath2], |
+ service2: [filePath1], |
+ service3: [filePath2] |
+ }); |
+ plugin.sendNotificationsForFile(filePath1); |
+ Map<String, List<AnalysisService>> notifications = plugin.sentNotifications; |
+ expect(notifications, hasLength(1)); |
+ List<AnalysisService> services = notifications[filePath1]; |
+ expect(services, unorderedEquals([service1, service2])); |
+ } |
+ |
+ test_sendNotificationsForSubscriptions() { |
+ Map<String, List<AnalysisService>> subscriptions = |
+ <String, List<AnalysisService>>{}; |
+ |
+ plugin.sendNotificationsForSubscriptions(subscriptions); |
+ Map<String, List<AnalysisService>> notifications = plugin.sentNotifications; |
+ expect(notifications, hasLength(subscriptions.length)); |
+ for (String path in subscriptions.keys) { |
+ List<AnalysisService> subscribedServices = subscriptions[path]; |
+ List<AnalysisService> notifiedServices = notifications[path]; |
+ expect(notifiedServices, isNotNull, |
+ reason: 'Not notified for file $path'); |
+ expect(notifiedServices, unorderedEquals(subscribedServices), |
+ reason: 'Wrong notifications for file $path'); |
+ } |
+ } |
+ |
AnalysisDriverGeneric _getDriver(ContextRoot targetRoot) { |
for (ContextRoot root in plugin.driverMap.keys) { |
if (root.root == targetRoot.root) { |
@@ -373,14 +408,43 @@ class ServerPluginTest { |
} |
class _TestServerPlugin extends MockServerPlugin { |
- Map<String, List<AnalysisService>> latestSubscriptions; |
+ Map<String, List<AnalysisService>> sentNotifications = |
+ <String, List<AnalysisService>>{}; |
_TestServerPlugin(ResourceProvider resourceProvider) |
: super(resourceProvider); |
@override |
- void sendNotificationsForSubscriptions( |
- Map<String, List<AnalysisService>> subscriptions) { |
- latestSubscriptions = subscriptions; |
+ Future<Null> sendFoldingNotification(String path) { |
+ _sent(path, AnalysisService.FOLDING); |
+ return new Future.value(); |
+ } |
+ |
+ @override |
+ Future<Null> sendHighlightsNotification(String path) { |
+ _sent(path, AnalysisService.HIGHLIGHTS); |
+ return new Future.value(); |
+ } |
+ |
+ @override |
+ Future<Null> sendNavigationNotification(String path) { |
+ _sent(path, AnalysisService.NAVIGATION); |
+ return new Future.value(); |
+ } |
+ |
+ @override |
+ Future<Null> sendOccurrencesNotification(String path) { |
+ _sent(path, AnalysisService.OCCURRENCES); |
+ return new Future.value(); |
+ } |
+ |
+ @override |
+ Future<Null> sendOutlineNotification(String path) { |
+ _sent(path, AnalysisService.OUTLINE); |
+ return new Future.value(); |
+ } |
+ |
+ void _sent(String path, AnalysisService service) { |
+ sentNotifications.putIfAbsent(path, () => <AnalysisService>[]).add(service); |
} |
} |