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

Side by Side Diff: pkg/analysis_server/test/completion_test.dart

Issue 402723003: first cut simple code completion results (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/domain_completion.dart ('k') | pkg/analysis_server/test/mocks.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.domain.completion;
6
7 import 'dart:async';
8
9 import 'package:analysis_server/src/constants.dart';
10 import 'package:analysis_server/src/domain_completion.dart';
11 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analysis_services/index/index.dart' show Index;
13 import 'package:analysis_services/index/local_memory_index.dart';
14 import 'package:analysis_testing/reflective_tests.dart';
15 import 'package:unittest/unittest.dart';
16
17 import 'analysis_abstract.dart';
18
19 main() {
20 group('completion', () {
21 runReflectiveTests(CompletionTest);
22 });
23 }
24
25 @ReflectiveTestCase()
26 class CompletionTest extends AbstractAnalysisTest {
27 String completionId;
28 List<CompletionSuggestion> suggestions = [];
29 bool suggestionsDone = false;
30
31 void assertHasResult(String completion) {
32 var cs = suggestions.firstWhere((cs) => cs.completion == completion, orElse: () {
33 var completions = suggestions.map((s) => s.completion).toList();
34 fail('expected "$completion" but found\n $completions');
35 });
36 }
37
38 void assertValidId(String id) {
39 expect(id, isNotNull);
40 expect(id.isNotEmpty, isTrue);
41 }
42
43 @override
44 Index createIndex() {
45 return createLocalMemoryIndex();
46 }
47
48 Future getSuggestions(String pattern, int offsetFromPatternStart) {
49 return waitForTasksFinished().then((_) {
50 int offset = testCode.indexOf(pattern) + offsetFromPatternStart;
51 Request request = new Request('0', COMPLETION_GET_SUGGESTIONS);
52 request.setParameter(FILE, testFile);
53 request.setParameter(OFFSET, offset);
54 Response response = handleSuccessfulRequest(request);
55 completionId = response.getResult(ID);
56 assertValidId(completionId);
57 return waitForSuggestions();
58 });
59 }
60
61 void processNotification(Notification notification) {
62 if (notification.event == COMPLETION_RESULTS) {
63 String id = notification.getParameter(ID);
64 assertValidId(id);
65 if (id == completionId) {
66 expect(suggestionsDone, isFalse);
67 suggestionsDone = notification.getParameter(LAST);
68 expect(suggestionsDone, isNotNull);
69 for (Map<String, Object> json in notification.getParameter(RESULTS)) {
70 expect(json, isNotNull);
71 suggestions.add(new CompletionSuggestion.fromJson(json));
72 }
73 }
74 }
75 }
76
77 @override
78 void setUp() {
79 super.setUp();
80 createProject();
81 handler = new CompletionDomainHandler(server);
82 }
83
84 Future waitForSuggestions() {
85 if (suggestionsDone) {
86 return new Future.value();
87 }
88 return new Future.delayed(Duration.ZERO, waitForSuggestions);
89 }
90
91 test_suggestions() {
92 addTestFile('''
93 import 'dart:html';
94 main() {}
95 ''');
96 return getSuggestions('}', 0).then((_) {
97 assertHasResult('Object');
98 assertHasResult('HtmlElement');
99 });
100 }
101 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/domain_completion.dart ('k') | pkg/analysis_server/test/mocks.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698