OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 import 'dart:async'; |
| 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 10 import 'package:analyzer_plugin/plugin/highlights_mixin.dart'; |
| 11 import 'package:analyzer_plugin/protocol/protocol.dart'; |
| 12 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 13 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
| 14 import 'package:analyzer_plugin/src/utilities/highlights/highlights.dart'; |
| 15 import 'package:analyzer_plugin/utilities/highlights/highlights.dart'; |
| 16 import 'package:path/src/context.dart'; |
| 17 import 'package:test/test.dart'; |
| 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 19 |
| 20 import 'mocks.dart'; |
| 21 |
| 22 void main() { |
| 23 defineReflectiveTests(HighlightsMixinTest); |
| 24 } |
| 25 |
| 26 @reflectiveTest |
| 27 class HighlightsMixinTest { |
| 28 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 29 |
| 30 String packagePath1; |
| 31 String filePath1; |
| 32 ContextRoot contextRoot1; |
| 33 |
| 34 MockChannel channel; |
| 35 _TestServerPlugin plugin; |
| 36 |
| 37 void setUp() { |
| 38 Context pathContext = resourceProvider.pathContext; |
| 39 |
| 40 packagePath1 = resourceProvider.convertPath('/package1'); |
| 41 filePath1 = pathContext.join(packagePath1, 'lib', 'test.dart'); |
| 42 resourceProvider.newFile(filePath1, ''); |
| 43 contextRoot1 = new ContextRoot(packagePath1, <String>[]); |
| 44 |
| 45 channel = new MockChannel(); |
| 46 plugin = new _TestServerPlugin(resourceProvider); |
| 47 plugin.start(channel); |
| 48 } |
| 49 |
| 50 test_sendHighlightsNotification() async { |
| 51 await plugin.handleAnalysisSetContextRoots( |
| 52 new AnalysisSetContextRootsParams([contextRoot1])); |
| 53 |
| 54 Completer<Null> notificationReceived = new Completer<Null>(); |
| 55 channel.listen(null, onNotification: (Notification notification) { |
| 56 expect(notification, isNotNull); |
| 57 AnalysisHighlightsParams params = |
| 58 new AnalysisHighlightsParams.fromNotification(notification); |
| 59 expect(params.file, filePath1); |
| 60 expect(params.regions, hasLength(5)); |
| 61 notificationReceived.complete(); |
| 62 }); |
| 63 await plugin.sendHighlightsNotification(filePath1); |
| 64 await notificationReceived.future; |
| 65 } |
| 66 } |
| 67 |
| 68 class _TestHighlightsContributor implements HighlightsContributor { |
| 69 int elementCount; |
| 70 |
| 71 _TestHighlightsContributor(this.elementCount); |
| 72 |
| 73 @override |
| 74 void computeHighlights( |
| 75 HighlightsRequest request, HighlightsCollector collector) { |
| 76 for (int i = 0; i < elementCount; i++) { |
| 77 collector.addRegion(i, 20, HighlightRegionType.METHOD_DECLARATION); |
| 78 } |
| 79 } |
| 80 } |
| 81 |
| 82 class _TestServerPlugin extends MockServerPlugin with HighlightsMixin { |
| 83 _TestServerPlugin(ResourceProvider resourceProvider) |
| 84 : super(resourceProvider); |
| 85 |
| 86 @override |
| 87 List<HighlightsContributor> getHighlightsContributors(String path) { |
| 88 return <HighlightsContributor>[ |
| 89 new _TestHighlightsContributor(2), |
| 90 new _TestHighlightsContributor(3) |
| 91 ]; |
| 92 } |
| 93 |
| 94 @override |
| 95 Future<HighlightsRequest> getHighlightsRequest(String path) async { |
| 96 AnalysisResult result = new AnalysisResult( |
| 97 null, null, path, null, null, null, null, null, null, null, null); |
| 98 return new DartHighlightsRequestImpl(resourceProvider, result); |
| 99 } |
| 100 } |
OLD | NEW |