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

Unified Diff: pkg/analyzer_plugin/test/plugin/completion_mixin_test.dart

Issue 2932553004: Add tests for recently added mixins and improve plugin tests (Closed)
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer_plugin/test/plugin/completion_mixin_test.dart
diff --git a/pkg/analyzer_plugin/test/plugin/completion_mixin_test.dart b/pkg/analyzer_plugin/test/plugin/completion_mixin_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..caab246f504643d725f632041cc8d8af0c0ad0d7
--- /dev/null
+++ b/pkg/analyzer_plugin/test/plugin/completion_mixin_test.dart
@@ -0,0 +1,106 @@
+// 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 'dart:async';
+
+import 'package:analyzer/dart/analysis/results.dart' hide AnalysisResult;
+import 'package:analyzer/file_system/file_system.dart';
+import 'package:analyzer/file_system/memory_file_system.dart';
+import 'package:analyzer/src/dart/analysis/driver.dart';
+import 'package:analyzer_plugin/plugin/completion_mixin.dart';
+import 'package:analyzer_plugin/protocol/protocol_common.dart';
+import 'package:analyzer_plugin/protocol/protocol_generated.dart';
+import 'package:analyzer_plugin/src/utilities/completion/completion_core.dart';
+import 'package:analyzer_plugin/utilities/completion/completion_core.dart';
+import 'package:path/src/context.dart';
+import 'package:test/test.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+import 'mocks.dart';
+
+void main() {
+ defineReflectiveTests(CompletionMixinTest);
+}
+
+@reflectiveTest
+class CompletionMixinTest {
+ MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
+
+ String packagePath1;
+ String filePath1;
+ ContextRoot contextRoot1;
+
+ MockChannel channel;
+ _TestServerPlugin plugin;
+
+ void setUp() {
+ Context pathContext = resourceProvider.pathContext;
+
+ packagePath1 = resourceProvider.convertPath('/package1');
+ filePath1 = pathContext.join(packagePath1, 'lib', 'test.dart');
+ resourceProvider.newFile(filePath1, 'int foo = bar;');
+ contextRoot1 = new ContextRoot(packagePath1, <String>[]);
+
+ channel = new MockChannel();
+ plugin = new _TestServerPlugin(resourceProvider);
+ plugin.start(channel);
+ }
+
+ test_handleCompletionGetSuggestions() async {
+ await plugin.handleAnalysisSetContextRoots(
+ new AnalysisSetContextRootsParams([contextRoot1]));
+
+ CompletionGetSuggestionsResult result =
+ await plugin.handleCompletionGetSuggestions(
+ new CompletionGetSuggestionsParams(filePath1, 13));
+ expect(result, isNotNull);
+ expect(result.results, hasLength(3));
+ }
+}
+
+class _TestCompletionContributor implements CompletionContributor {
+ List<CompletionSuggestion> suggestions;
+
+ _TestCompletionContributor(this.suggestions);
+
+ @override
+ Future<Null> computeSuggestions(
+ CompletionRequest request, CompletionCollector collector) async {
+ if ((collector as CompletionCollectorImpl).offset == null) {
+ collector.offset = 1;
+ collector.length = 2;
+ }
+ for (CompletionSuggestion suggestion in suggestions) {
+ collector.addSuggestion(suggestion);
+ }
+ }
+}
+
+class _TestServerPlugin extends MockServerPlugin with CompletionMixin {
+ _TestServerPlugin(ResourceProvider resourceProvider)
+ : super(resourceProvider);
+
+ CompletionSuggestion createSuggestion() {
+ return new CompletionSuggestion(
+ CompletionSuggestionKind.IDENTIFIER, 1, '', 0, 0, false, false);
+ }
+
+ @override
+ List<CompletionContributor> getCompletionContributors(
+ AnalysisDriverGeneric driver) {
+ return <CompletionContributor>[
+ new _TestCompletionContributor(
+ <CompletionSuggestion>[createSuggestion(), createSuggestion()]),
+ new _TestCompletionContributor(
+ <CompletionSuggestion>[createSuggestion()]),
+ ];
+ }
+
+ @override
+ Future<ResolveResult> getResolveResultForCompletion(
+ AnalysisDriverGeneric driver, String path) async {
+ return new AnalysisResult(
+ null, null, null, null, null, null, null, null, null, null, null);
+ }
+}
« no previous file with comments | « pkg/analyzer_plugin/test/plugin/assist_mixin_test.dart ('k') | pkg/analyzer_plugin/test/plugin/fix_mixin_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698