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

Side by Side Diff: pkg/analysis_services/test/completion/top_level_computer_test.dart

Issue 428313002: refactor code completion to allow for multiple suggestion computers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_services/test/completion/test_all.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.services.completion.toplevel; 5 library test.services.completion.toplevel;
6 6
7 import 'package:analysis_services/completion/completion_suggestion.dart'; 7 import 'package:analysis_services/completion/completion_suggestion.dart';
8 import 'package:analysis_services/completion/top_level_computer.dart'; 8 import 'package:analysis_services/src/completion/top_level_computer.dart';
9 import 'package:analysis_services/index/index.dart';
10 import 'package:analysis_services/index/local_memory_index.dart';
11 import 'package:analysis_services/src/search/search_engine.dart';
12 import 'package:analysis_testing/abstract_single_unit.dart';
13 import 'package:analysis_testing/reflective_tests.dart'; 9 import 'package:analysis_testing/reflective_tests.dart';
14 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
15 import 'dart:async'; 11
12 import 'completion_test_util.dart';
16 13
17 main() { 14 main() {
18 groupSep = ' | '; 15 groupSep = ' | ';
19 runReflectiveTests(TopLevelComputerTest); 16 runReflectiveTests(TopLevelComputerTest);
20 } 17 }
21 18
22 @ReflectiveTestCase() 19 @ReflectiveTestCase()
23 class TopLevelComputerTest extends AbstractSingleUnitTest { 20 class TopLevelComputerTest extends AbstractCompletionTest {
24 Index index;
25 SearchEngineImpl searchEngine;
26 TopLevelComputer computer;
27 List<CompletionSuggestion> suggestions;
28 21
29 test_class() { 22 test_class() {
30 addTestUnit('class B {boolean v;}'); 23 addTestUnit('class B {boolean v;}');
31 return compute().then((_) { 24 return compute().then((_) {
32 assertHasResult(CompletionSuggestionKind.CLASS, 'B'); 25 assertHasResult(CompletionSuggestionKind.CLASS, 'B');
33 assertNoResult('v'); 26 assertNoResult('v');
34 }); 27 });
35 } 28 }
36 29
37 void addTestUnit(String code) {
38 resolveTestUnit(code);
39 index.indexUnit(context, testUnit);
40 }
41
42 void assertHasResult(CompletionSuggestionKind kind, String completion,
43 [CompletionRelevance relevance = CompletionRelevance.DEFAULT,
44 bool isDeprecated = false, bool isPotential = false]) {
45 var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse: () {
46 var completions = suggestions.map((s) => s.completion).toList();
47 fail('expected "$completion" but found\n $completions');
48 });
49 expect(cs.kind, equals(kind));
50 expect(cs.relevance, equals(relevance));
51 expect(cs.selectionOffset, equals(completion.length));
52 expect(cs.selectionLength, equals(0));
53 expect(cs.isDeprecated, equals(isDeprecated));
54 expect(cs.isPotential, equals(isPotential));
55 }
56
57 void assertNoResult(String completion) {
58 if (suggestions.any((cs) => cs.completion == completion)) {
59 fail('did not expect completion: $completion');
60 }
61 }
62
63 Future compute() {
64 return computer.compute().then((List<CompletionSuggestion> results) {
65 this.suggestions = results;
66 });
67 }
68
69 @override 30 @override
70 void setUp() { 31 void setUp() {
71 super.setUp(); 32 super.setUp();
72 index = createLocalMemoryIndex();
73 searchEngine = new SearchEngineImpl(index);
74 computer = new TopLevelComputer(searchEngine); 33 computer = new TopLevelComputer(searchEngine);
75 verifyNoTestUnitErrors = false;
76 } 34 }
77 } 35 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/test/completion/test_all.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698