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/kythe_mixin.dart'; |
| 11 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 12 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
| 13 import 'package:analyzer_plugin/src/utilities/kythe/entries.dart'; |
| 14 import 'package:analyzer_plugin/utilities/kythe/entries.dart'; |
| 15 import 'package:path/src/context.dart'; |
| 16 import 'package:test/test.dart'; |
| 17 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 18 |
| 19 import 'mocks.dart'; |
| 20 |
| 21 void main() { |
| 22 defineReflectiveTests(KytheMixinTest); |
| 23 } |
| 24 |
| 25 @reflectiveTest |
| 26 class KytheMixinTest { |
| 27 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 28 |
| 29 String packagePath1; |
| 30 String filePath1; |
| 31 ContextRoot contextRoot1; |
| 32 |
| 33 MockChannel channel; |
| 34 _TestServerPlugin plugin; |
| 35 |
| 36 void setUp() { |
| 37 Context pathContext = resourceProvider.pathContext; |
| 38 |
| 39 packagePath1 = resourceProvider.convertPath('/package1'); |
| 40 filePath1 = pathContext.join(packagePath1, 'lib', 'test.dart'); |
| 41 resourceProvider.newFile(filePath1, ''); |
| 42 contextRoot1 = new ContextRoot(packagePath1, <String>[]); |
| 43 |
| 44 channel = new MockChannel(); |
| 45 plugin = new _TestServerPlugin(resourceProvider); |
| 46 plugin.start(channel); |
| 47 } |
| 48 |
| 49 test_handleEditGetAssists() async { |
| 50 await plugin.handleAnalysisSetContextRoots( |
| 51 new AnalysisSetContextRootsParams([contextRoot1])); |
| 52 |
| 53 KytheGetKytheEntriesResult result = await plugin |
| 54 .handleKytheGetKytheEntries(new KytheGetKytheEntriesParams(filePath1)); |
| 55 expect(result, isNotNull); |
| 56 expect(result.entries, hasLength(3)); |
| 57 } |
| 58 } |
| 59 |
| 60 class _TestEntryContributor implements EntryContributor { |
| 61 List<KytheEntry> entries; |
| 62 |
| 63 _TestEntryContributor(this.entries); |
| 64 |
| 65 @override |
| 66 void computeEntries(EntryRequest request, EntryCollector collector) { |
| 67 for (KytheEntry entry in entries) { |
| 68 collector.addEntry(entry); |
| 69 } |
| 70 } |
| 71 } |
| 72 |
| 73 class _TestServerPlugin extends MockServerPlugin with EntryMixin { |
| 74 _TestServerPlugin(ResourceProvider resourceProvider) |
| 75 : super(resourceProvider); |
| 76 |
| 77 PrioritizedSourceChange createChange() { |
| 78 return new PrioritizedSourceChange(0, new SourceChange('')); |
| 79 } |
| 80 |
| 81 @override |
| 82 List<EntryContributor> getEntryContributors(String path) { |
| 83 KytheVName vName = new KytheVName('', '', '', '', ''); |
| 84 return <EntryContributor>[ |
| 85 new _TestEntryContributor(<KytheEntry>[ |
| 86 new KytheEntry(vName, '', vName, '', <int>[]), |
| 87 new KytheEntry(vName, '', vName, '', <int>[]) |
| 88 ]), |
| 89 new _TestEntryContributor( |
| 90 <KytheEntry>[new KytheEntry(vName, '', vName, '', <int>[])]) |
| 91 ]; |
| 92 } |
| 93 |
| 94 @override |
| 95 Future<EntryRequest> getEntryRequest( |
| 96 KytheGetKytheEntriesParams parameters) async { |
| 97 AnalysisResult result = new AnalysisResult( |
| 98 null, null, null, null, null, null, null, null, null, null, null); |
| 99 return new DartEntryRequestImpl(resourceProvider, result); |
| 100 } |
| 101 } |
OLD | NEW |