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

Unified Diff: pkg/analysis_services/test/completion/top_level_computer_test.dart

Issue 422423003: incremental step moving completion into services and adding tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 5 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
« no previous file with comments | « pkg/analysis_services/test/completion/test_all.dart ('k') | pkg/analysis_services/test/test_all.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_services/test/completion/top_level_computer_test.dart
diff --git a/pkg/analysis_services/test/completion/top_level_computer_test.dart b/pkg/analysis_services/test/completion/top_level_computer_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..113f5fd3c994e6e40febd91f18965d0529337118
--- /dev/null
+++ b/pkg/analysis_services/test/completion/top_level_computer_test.dart
@@ -0,0 +1,77 @@
+// Copyright (c) 2014, 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.
+
+library test.services.completion.toplevel;
+
+import 'package:analysis_services/completion/completion_suggestion.dart';
+import 'package:analysis_services/completion/top_level_computer.dart';
+import 'package:analysis_services/index/index.dart';
+import 'package:analysis_services/index/local_memory_index.dart';
+import 'package:analysis_services/src/search/search_engine.dart';
+import 'package:analysis_testing/abstract_single_unit.dart';
+import 'package:analysis_testing/reflective_tests.dart';
+import 'package:unittest/unittest.dart';
+import 'dart:async';
+
+main() {
+ groupSep = ' | ';
+ runReflectiveTests(TopLevelComputerTest);
+}
+
+@ReflectiveTestCase()
+class TopLevelComputerTest extends AbstractSingleUnitTest {
+ Index index;
+ SearchEngineImpl searchEngine;
+ TopLevelComputer computer;
+ List<CompletionSuggestion> suggestions;
+
+ test_class() {
+ addTestUnit('class B {boolean v;}');
+ return compute().then((_) {
+ assertHasResult(CompletionSuggestionKind.CLASS, 'B');
+ assertNoResult('v');
+ });
+ }
+
+ void addTestUnit(String code) {
+ resolveTestUnit(code);
+ index.indexUnit(context, testUnit);
+ }
+
+ void assertHasResult(CompletionSuggestionKind kind, String completion,
+ [CompletionRelevance relevance = CompletionRelevance.DEFAULT,
+ bool isDeprecated = false, bool isPotential = false]) {
+ var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse: () {
+ var completions = suggestions.map((s) => s.completion).toList();
+ fail('expected "$completion" but found\n $completions');
+ });
+ expect(cs.kind, equals(kind));
+ expect(cs.relevance, equals(relevance));
+ expect(cs.selectionOffset, equals(completion.length));
+ expect(cs.selectionLength, equals(0));
+ expect(cs.isDeprecated, equals(isDeprecated));
+ expect(cs.isPotential, equals(isPotential));
+ }
+
+ void assertNoResult(String completion) {
+ if (suggestions.any((cs) => cs.completion == completion)) {
+ fail('did not expect completion: $completion');
+ }
+ }
+
+ Future compute() {
+ return computer.compute().then((List<CompletionSuggestion> results) {
+ this.suggestions = results;
+ });
+ }
+
+ @override
+ void setUp() {
+ super.setUp();
+ index = createLocalMemoryIndex();
+ searchEngine = new SearchEngineImpl(index);
+ computer = new TopLevelComputer(searchEngine);
+ verifyNoTestUnitErrors = false;
+ }
+}
« no previous file with comments | « pkg/analysis_services/test/completion/test_all.dart ('k') | pkg/analysis_services/test/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698