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/folding_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/folding/folding.dart'; |
| 15 import 'package:analyzer_plugin/utilities/folding/folding.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(FoldingMixinTest); |
| 24 } |
| 25 |
| 26 @reflectiveTest |
| 27 class FoldingMixinTest { |
| 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_sendFoldingNotification() 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 AnalysisFoldingParams params = |
| 58 new AnalysisFoldingParams.fromNotification(notification); |
| 59 expect(params.file, filePath1); |
| 60 List<FoldingRegion> regions = params.regions; |
| 61 expect(regions, hasLength(7)); |
| 62 notificationReceived.complete(); |
| 63 }); |
| 64 await plugin.sendFoldingNotification(filePath1); |
| 65 await notificationReceived.future; |
| 66 } |
| 67 } |
| 68 |
| 69 class _TestFoldingContributor implements FoldingContributor { |
| 70 int regionCount; |
| 71 |
| 72 _TestFoldingContributor(this.regionCount); |
| 73 |
| 74 @override |
| 75 void computeFolding(FoldingRequest request, FoldingCollector collector) { |
| 76 for (int i = 0; i < regionCount; i++) { |
| 77 collector.addRegion(i * 20, 10, FoldingKind.COMMENT); |
| 78 } |
| 79 } |
| 80 } |
| 81 |
| 82 class _TestServerPlugin extends MockServerPlugin with FoldingMixin { |
| 83 _TestServerPlugin(ResourceProvider resourceProvider) |
| 84 : super(resourceProvider); |
| 85 |
| 86 @override |
| 87 List<FoldingContributor> getFoldingContributors(String path) { |
| 88 return <FoldingContributor>[ |
| 89 new _TestFoldingContributor(3), |
| 90 new _TestFoldingContributor(4) |
| 91 ]; |
| 92 } |
| 93 |
| 94 @override |
| 95 Future<FoldingRequest> getFoldingRequest(String path) async { |
| 96 AnalysisResult result = new AnalysisResult( |
| 97 null, null, path, null, null, null, null, null, null, null, null); |
| 98 return new DartFoldingRequestImpl(resourceProvider, result); |
| 99 } |
| 100 } |
OLD | NEW |