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

Side by Side Diff: pkg/analysis_server/test/services/completion/invocation_computer_test.dart

Issue 837793003: Include required parameter names when completing a method call. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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
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.invocation; 5 library test.services.completion.invocation;
6 6
7 7
8 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/completion/invocation_computer.dart '; 9 import 'package:analysis_server/src/services/completion/invocation_computer.dart ';
9 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
10 11
11 import '../../reflective_tests.dart'; 12 import '../../reflective_tests.dart';
12 import 'completion_test_util.dart'; 13 import 'completion_test_util.dart';
13 14
14 main() { 15 main() {
15 groupSep = ' | '; 16 groupSep = ' | ';
16 runReflectiveTests(InvocationComputerTest); 17 runReflectiveTests(InvocationComputerTest);
17 } 18 }
18 19
19 @ReflectiveTestCase() 20 @ReflectiveTestCase()
20 class InvocationComputerTest extends AbstractSelectorSuggestionTest { 21 class InvocationComputerTest extends AbstractSelectorSuggestionTest {
21 22
23 void assertHasNoParameterInfo(CompletionSuggestion suggestion) {
24 expect(suggestion.parameterNames, isNull);
25 expect(suggestion.parameterTypes, isNull);
26 expect(suggestion.requiredParameterCount, isNull);
27 expect(suggestion.hasNamedParameters, isNull);
28 }
29
22 @override 30 @override
23 void setUpComputer() { 31 void setUpComputer() {
24 computer = new InvocationComputer(); 32 computer = new InvocationComputer();
25 } 33 }
34
35 test_method_parameters_mixed_required_and_named() {
36 addTestSource('''
37 class C {
danrubel 2015/01/06 23:49:36 I find this left justified target source very hard
Paul Berry 2015/01/07 15:39:14 Let's talk about this in the stand-up meeting. I
38 void m(x, {int y}) {}
26 } 39 }
40 void main() {new C().^}''');
41 return computeFull((bool result) {
42 CompletionSuggestion suggestion = assertSuggestMethod('m', 'C', 'void');
43 expect(suggestion.parameterNames, hasLength(2));
44 expect(suggestion.parameterNames[0], 'x');
45 expect(suggestion.parameterTypes[0], 'dynamic');
46 expect(suggestion.parameterNames[1], 'y');
47 expect(suggestion.parameterTypes[1], 'int');
48 expect(suggestion.requiredParameterCount, 1);
49 expect(suggestion.hasNamedParameters, true);
50 });
51 }
52
53 test_method_parameters_mixed_required_and_positional() {
54 addTestSource('''
55 class C {
56 void m(x, [int y]) {}
57 }
58 void main() {new C().^}''');
59 return computeFull((bool result) {
60 CompletionSuggestion suggestion = assertSuggestMethod('m', 'C', 'void');
61 expect(suggestion.parameterNames, hasLength(2));
62 expect(suggestion.parameterNames[0], 'x');
63 expect(suggestion.parameterTypes[0], 'dynamic');
64 expect(suggestion.parameterNames[1], 'y');
65 expect(suggestion.parameterTypes[1], 'int');
66 expect(suggestion.requiredParameterCount, 1);
67 expect(suggestion.hasNamedParameters, false);
68 });
69 }
70
71 test_method_parameters_named() {
72 addTestSource('''
73 class C {
74 void m({x, int y}) {}
75 }
76 void main() {new C().^}''');
77 return computeFull((bool result) {
78 CompletionSuggestion suggestion = assertSuggestMethod('m', 'C', 'void');
79 expect(suggestion.parameterNames, hasLength(2));
80 expect(suggestion.parameterNames[0], 'x');
81 expect(suggestion.parameterTypes[0], 'dynamic');
82 expect(suggestion.parameterNames[1], 'y');
83 expect(suggestion.parameterTypes[1], 'int');
84 expect(suggestion.requiredParameterCount, 0);
85 expect(suggestion.hasNamedParameters, true);
86 });
87 }
88
89 test_method_parameters_none() {
90 addTestSource('''
91 class C {
92 void m() {}
93 }
94 void main() {new C().^}''');
95 computeFast();
96 return computeFull((bool result) {
97 CompletionSuggestion suggestion = assertSuggestMethod('m', 'C', 'void');
98 expect(suggestion.parameterNames, isEmpty);
99 expect(suggestion.parameterTypes, isEmpty);
100 expect(suggestion.requiredParameterCount, 0);
101 expect(suggestion.hasNamedParameters, false);
102 });
103 }
104
105 test_method_parameters_positional() {
106 addTestSource('''
107 class C {
108 void m([x, int y]) {}
109 }
110 void main() {new C().^}''');
111 return computeFull((bool result) {
112 CompletionSuggestion suggestion = assertSuggestMethod('m', 'C', 'void');
113 expect(suggestion.parameterNames, hasLength(2));
114 expect(suggestion.parameterNames[0], 'x');
115 expect(suggestion.parameterTypes[0], 'dynamic');
116 expect(suggestion.parameterNames[1], 'y');
117 expect(suggestion.parameterTypes[1], 'int');
118 expect(suggestion.requiredParameterCount, 0);
119 expect(suggestion.hasNamedParameters, false);
120 });
121 }
122
123 test_method_parameters_required() {
124 addTestSource('''
125 class C {
126 void m(x, int y) {}
127 }
128 void main() {new C().^}''');
129 return computeFull((bool result) {
130 CompletionSuggestion suggestion = assertSuggestMethod('m', 'C', 'void');
131 expect(suggestion.parameterNames, hasLength(2));
132 expect(suggestion.parameterNames[0], 'x');
133 expect(suggestion.parameterTypes[0], 'dynamic');
134 expect(suggestion.parameterNames[1], 'y');
135 expect(suggestion.parameterTypes[1], 'int');
136 expect(suggestion.requiredParameterCount, 2);
137 expect(suggestion.hasNamedParameters, false);
138 });
139 }
140
141 test_no_parameters_field() {
142 addTestSource('''
143 class C {
144 int x;
145 }
146 void main() {new C().^}''');
147 return computeFull((bool result) {
148 CompletionSuggestion suggestion = assertSuggestGetter('x', 'int');
149 assertHasNoParameterInfo(suggestion);
150 });
151 }
152
153 test_no_parameters_getter() {
154 addTestSource('''
155 class C {
156 int get x => null;
157 }
158 void main() {int y = new C().^}''');
159 return computeFull((bool result) {
160 CompletionSuggestion suggestion = assertSuggestGetter('x', 'int');
161 assertHasNoParameterInfo(suggestion);
162 });
163 }
164
165 test_no_parameters_setter() {
166 addTestSource('''
167 class C {
168 set x(int value) {};
169 }
170 void main() {int y = new C().^}''');
171 return computeFull((bool result) {
172 CompletionSuggestion suggestion = assertSuggestSetter('x');
173 assertHasNoParameterInfo(suggestion);
174 });
175 }
176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698