// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/file_system/file_system.dart'; import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart'; import 'package:analyzer_plugin/plugin/kythe_mixin.dart'; import 'package:analyzer_plugin/protocol/protocol_common.dart'; import 'package:analyzer_plugin/protocol/protocol_generated.dart'; import 'package:analyzer_plugin/src/utilities/kythe/entries.dart'; import 'package:analyzer_plugin/utilities/kythe/entries.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import 'mocks.dart'; void main() { defineReflectiveTests(KytheMixinTest); } @reflectiveTest class KytheMixinTest with ResourceProviderMixin { late String packagePath1; late String filePath1; late ContextRoot contextRoot1; late MockChannel channel; late _TestServerPlugin plugin; void setUp() { packagePath1 = convertPath('/package1'); filePath1 = join(packagePath1, 'lib', 'test.dart'); newFile(filePath1); contextRoot1 = ContextRoot(packagePath1, []); channel = MockChannel(); plugin = _TestServerPlugin(resourceProvider); plugin.start(channel); } Future test_handleEditGetAssists() async { await plugin.handleAnalysisSetContextRoots( AnalysisSetContextRootsParams([contextRoot1])); var result = await plugin .handleKytheGetKytheEntries(KytheGetKytheEntriesParams(filePath1)); expect(result, isNotNull); expect(result.entries, hasLength(3)); } } class _TestEntryContributor implements EntryContributor { List entries; _TestEntryContributor(this.entries); @override void computeEntries(EntryRequest request, EntryCollector collector) { for (var entry in entries) { collector.addEntry(entry); } } } class _TestServerPlugin extends MockServerPlugin with EntryMixin { _TestServerPlugin(ResourceProvider resourceProvider) : super(resourceProvider); PrioritizedSourceChange createChange() { return PrioritizedSourceChange(0, SourceChange('')); } @override List getEntryContributors(String path) { var vName = KytheVName('', '', '', '', ''); return [ _TestEntryContributor([ KytheEntry(vName, '', target: vName), KytheEntry(vName, '', target: vName) ]), _TestEntryContributor([KytheEntry(vName, '', target: vName)]) ]; } @override Future getEntryRequest( KytheGetKytheEntriesParams parameters) async { var result = MockResolvedUnitResult(); return DartEntryRequestImpl(resourceProvider, result); } }