Chromium Code Reviews| 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/outline_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/outline/outline.dart'; | |
| 15 import 'package:analyzer_plugin/utilities/outline/outline.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(OutlineMixinTest); | |
| 24 } | |
| 25 | |
| 26 @reflectiveTest | |
| 27 class OutlineMixinTest { | |
| 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_sendOutlineNotification() async { | |
| 51 await plugin.handleAnalysisSetContextRoots( | |
| 52 new AnalysisSetContextRootsParams([contextRoot1])); | |
| 53 | |
| 54 channel.listen(null, onNotification: (Notification notification) { | |
| 55 expect(notification, isNotNull); | |
| 56 AnalysisOutlineParams params = | |
| 57 new AnalysisOutlineParams.fromNotification(notification); | |
| 58 expect(params.file, filePath1); | |
| 59 expect(params.outline, hasLength(3)); | |
| 60 }); | |
| 61 await plugin.sendOutlineNotification(filePath1); | |
|
scheglov
2017/08/24 18:29:21
We don't actually verify that onNotification is in
Brian Wilkerson
2017/08/24 18:52:47
Good catch!
| |
| 62 } | |
| 63 } | |
| 64 | |
| 65 class _TestOutlineContributor implements OutlineContributor { | |
| 66 int elementCount; | |
| 67 | |
| 68 _TestOutlineContributor(this.elementCount); | |
| 69 | |
| 70 @override | |
| 71 void computeOutline(OutlineRequest request, OutlineCollector collector) { | |
| 72 for (int i = 0; i < elementCount; i++) { | |
| 73 collector.startElement( | |
| 74 new Element(ElementKind.METHOD, 'm$i', 0), 20 * i, 20); | |
| 75 collector.endElement(); | |
| 76 } | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 class _TestServerPlugin extends MockServerPlugin with OutlineMixin { | |
| 81 _TestServerPlugin(ResourceProvider resourceProvider) | |
| 82 : super(resourceProvider); | |
| 83 | |
| 84 @override | |
| 85 List<OutlineContributor> getOutlineContributors(String path) { | |
| 86 return <OutlineContributor>[ | |
| 87 new _TestOutlineContributor(2), | |
| 88 new _TestOutlineContributor(1) | |
| 89 ]; | |
| 90 } | |
| 91 | |
| 92 @override | |
| 93 Future<OutlineRequest> getOutlineRequest(String path) async { | |
| 94 AnalysisResult result = new AnalysisResult( | |
| 95 null, null, path, null, null, null, null, null, null, null, null); | |
| 96 return new DartOutlineRequestImpl(resourceProvider, result); | |
| 97 } | |
| 98 } | |
| OLD | NEW |