Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: pkg/analyzer_plugin/test/plugin/folding_mixin_test.dart

Issue 3004733002: Add folding support for plugins and update the main tutorial page (Closed)
Patch Set: Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/lib/utilities/folding/folding.dart ('k') | pkg/analyzer_plugin/test/plugin/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698