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

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

Issue 1514263004: extract LabelContributor from local reference contributor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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.services.completion.contributor.dart.local_ref;
6
7 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol
8 show Element, ElementKind;
9 import 'package:analysis_server/plugin/protocol/protocol.dart'
10 hide Element, ElementKind;
11 import 'package:analysis_server/src/protocol_server.dart';
12 import 'package:analysis_server/src/provisional/completion/dart/completion_dart. dart';
13 import 'package:analysis_server/src/services/completion/dart/label_contributor.d art';
14 import 'package:test_reflective_loader/test_reflective_loader.dart';
15 import 'package:unittest/unittest.dart';
16
17 import '../../../utils.dart';
18 import 'completion_contributor_util.dart';
19
20 main() {
21 initializeTestEnvironment();
22 defineReflectiveTests(LabelContributorTest);
23 }
24
25 @reflectiveTest
26 class LabelContributorTest extends DartCompletionContributorTest {
27 CompletionSuggestion assertSuggestLabel(String name,
28 {int relevance: DART_RELEVANCE_DEFAULT,
29 CompletionSuggestionKind kind: CompletionSuggestionKind.IDENTIFIER}) {
30 CompletionSuggestion cs =
31 assertSuggest(name, csKind: kind, relevance: relevance);
32 expect(cs.returnType, isNull);
33 protocol.Element element = cs.element;
34 expect(element, isNotNull);
35 expect(element.flags, 0);
36 expect(element.kind, equals(protocol.ElementKind.LABEL));
37 expect(element.name, equals(name));
38 expect(element.parameters, isNull);
39 expect(element.returnType, isNull);
40 assertHasNoParameterInfo(cs);
41 return cs;
42 }
43
44 @override
45 DartCompletionContributor createContributor() {
46 return new LabelContributor();
47 }
48
49 test_break_ignores_outer_functions_using_closure() async {
50 addTestSource('''
51 void main() {
52 foo: while (true) {
53 var f = () {
54 bar: while (true) { break ^ }
55 };
56 }
57 }
58 ''');
59 await computeSuggestions();
60 // Labels in outer functions are never accessible.
61 assertSuggestLabel('bar');
62 assertNotSuggested('foo');
63 }
64
65 test_break_ignores_outer_functions_using_local_function() async {
66 addTestSource('''
67 void main() {
68 foo: while (true) {
69 void f() {
70 bar: while (true) { break ^ }
71 };
72 }
73 }
74 ''');
75 await computeSuggestions();
76 // Labels in outer functions are never accessible.
77 assertSuggestLabel('bar');
78 assertNotSuggested('foo');
79 }
80
81 test_break_ignores_toplevel_variables() async {
82 addTestSource('''
83 int x;
84 void main() {
85 while (true) {
86 break ^
87 }
88 }
89 ''');
90 await computeSuggestions();
91 assertNotSuggested('x');
92 }
93
94 test_break_ignores_unrelated_statements() async {
95 addTestSource('''
96 void main() {
97 foo: while (true) {}
98 while (true) { break ^ }
99 bar: while (true) {}
100 }
101 ''');
102 await computeSuggestions();
103 // The scope of the label defined by a labeled statement is just the
104 // statement itself, so neither "foo" nor "bar" are in scope at the caret
105 // position.
106 assertNotSuggested('foo');
107 assertNotSuggested('bar');
108 }
109
110 test_break_to_enclosing_loop() async {
111 addTestSource('''
112 void main() {
113 foo: while (true) {
114 bar: while (true) {
115 break ^
116 }
117 }
118 }
119 ''');
120 await computeSuggestions();
121 assertSuggestLabel('foo');
122 assertSuggestLabel('bar');
123 }
124
125 test_continue_from_loop_to_switch() async {
126 addTestSource('''
127 void main() {
128 switch (x) {
129 foo: case 1:
130 break;
131 bar: case 2:
132 while (true) {
133 continue ^;
134 }
135 break;
136 baz: case 3:
137 break;
138 }
139 }
140 ''');
141 await computeSuggestions();
142 assertSuggestLabel('foo');
143 assertSuggestLabel('bar');
144 assertSuggestLabel('baz');
145 }
146
147 test_continue_from_switch_to_loop() async {
148 addTestSource('''
149 void main() {
150 foo: while (true) {
151 switch (x) {
152 case 1:
153 continue ^;
154 }
155 }
156 }
157 ''');
158 await computeSuggestions();
159 assertSuggestLabel('foo');
160 }
161
162 test_continue_ignores_outer_functions_using_closure_with_loop() async {
163 addTestSource('''
164 void main() {
165 foo: while (true) {
166 var f = () {
167 bar: while (true) { continue ^ }
168 };
169 }
170 }
171 ''');
172 await computeSuggestions();
173 // Labels in outer functions are never accessible.
174 assertSuggestLabel('bar');
175 assertNotSuggested('foo');
176 }
177
178 test_continue_ignores_outer_functions_using_closure_with_switch() async {
179 addTestSource('''
180 void main() {
181 switch (x) {
182 foo: case 1:
183 var f = () {
184 bar: while (true) { continue ^ }
185 };
186 }
187 }
188 ''');
189 await computeSuggestions();
190 // Labels in outer functions are never accessible.
191 assertSuggestLabel('bar');
192 assertNotSuggested('foo');
193 }
194
195 test_continue_ignores_outer_functions_using_local_function_with_loop() async {
196 addTestSource('''
197 void main() {
198 foo: while (true) {
199 void f() {
200 bar: while (true) { continue ^ }
201 };
202 }
203 }
204 ''');
205 await computeSuggestions();
206 // Labels in outer functions are never accessible.
207 assertSuggestLabel('bar');
208 assertNotSuggested('foo');
209 }
210
211 test_continue_ignores_outer_functions_using_local_function_with_switch() async {
212 addTestSource('''
213 void main() {
214 switch (x) {
215 foo: case 1:
216 void f() {
217 bar: while (true) { continue ^ }
218 };
219 }
220 }
221 ''');
222 await computeSuggestions();
223 // Labels in outer functions are never accessible.
224 assertSuggestLabel('bar');
225 assertNotSuggested('foo');
226 }
227
228 test_continue_ignores_unrelated_statements() async {
229 addTestSource('''
230 void main() {
231 foo: while (true) {}
232 while (true) { continue ^ }
233 bar: while (true) {}
234 }
235 ''');
236 await computeSuggestions();
237 // The scope of the label defined by a labeled statement is just the
238 // statement itself, so neither "foo" nor "bar" are in scope at the caret
239 // position.
240 assertNotSuggested('foo');
241 assertNotSuggested('bar');
242 }
243
244 test_continue_to_earlier_case() async {
245 addTestSource('''
246 void main() {
247 switch (x) {
248 foo: case 1:
249 break;
250 case 2:
251 continue ^;
252 case 3:
253 break;
254 ''');
255 await computeSuggestions();
256 assertSuggestLabel('foo');
257 }
258
259 test_continue_to_enclosing_loop() async {
260 addTestSource('''
261 void main() {
262 foo: while (true) {
263 bar: while (true) {
264 continue ^
265 }
266 }
267 }
268 ''');
269 await computeSuggestions();
270 assertSuggestLabel('foo');
271 assertSuggestLabel('bar');
272 }
273
274 test_continue_to_enclosing_switch() async {
275 addTestSource('''
276 void main() {
277 switch (x) {
278 foo: case 1:
279 break;
280 bar: case 2:
281 switch (y) {
282 case 1:
283 continue ^;
284 }
285 break;
286 baz: case 3:
287 break;
288 }
289 }
290 ''');
291 await computeSuggestions();
292 assertSuggestLabel('foo');
293 assertSuggestLabel('bar');
294 assertSuggestLabel('baz');
295 }
296
297 test_continue_to_later_case() async {
298 addTestSource('''
299 void main() {
300 switch (x) {
301 case 1:
302 break;
303 case 2:
304 continue ^;
305 foo: case 3:
306 break;
307 ''');
308 await computeSuggestions();
309 assertSuggestLabel('foo');
310 }
311
312 test_continue_to_same_case() async {
313 addTestSource('''
314 void main() {
315 switch (x) {
316 case 1:
317 break;
318 foo: case 2:
319 continue ^;
320 case 3:
321 break;
322 ''');
323 await computeSuggestions();
324 assertSuggestLabel('foo');
325 }
326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698