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

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

Issue 806473007: Add support for completion of case labels. (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.dart.local; 5 library test.services.completion.dart.local;
6 6
7 import 'package:analysis_server/src/services/completion/local_computer.dart'; 7 import 'package:analysis_server/src/services/completion/local_computer.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import '../../reflective_tests.dart'; 10 import '../../reflective_tests.dart';
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 break ^ 92 break ^
93 } 93 }
94 } 94 }
95 } 95 }
96 '''); 96 ''');
97 expect(computeFast(), isTrue); 97 expect(computeFast(), isTrue);
98 assertSuggestLabel('foo'); 98 assertSuggestLabel('foo');
99 assertSuggestLabel('bar'); 99 assertSuggestLabel('bar');
100 } 100 }
101 101
102 test_continue_ignores_outer_functions_using_closure() { 102 test_continue_from_loop_to_switch() {
103 addTestSource('''
104 void main() {
105 switch (x) {
106 foo: case 1:
107 break;
108 bar: case 2:
109 while (true) {
110 continue ^;
111 }
112 break;
113 baz: case 3:
114 break;
115 }
116 }
117 ''');
118 expect(computeFast(), isTrue);
119 assertSuggestLabel('foo');
120 assertSuggestLabel('bar');
121 assertSuggestLabel('baz');
122 }
123
124 test_continue_from_switch_to_loop() {
103 addTestSource(''' 125 addTestSource('''
104 void main() { 126 void main() {
105 foo: while (true) { 127 foo: while (true) {
128 switch (x) {
129 case 1:
130 continue ^;
131 }
132 }
133 }
134 ''');
135 expect(computeFast(), isTrue);
136 assertSuggestLabel('foo');
137 }
138
139 test_continue_ignores_outer_functions_using_closure_with_loop() {
140 addTestSource('''
141 void main() {
142 foo: while (true) {
106 var f = () { 143 var f = () {
107 bar: while (true) { continue ^ } 144 bar: while (true) { continue ^ }
108 }; 145 };
109 } 146 }
110 } 147 }
111 '''); 148 ''');
112 expect(computeFast(), isTrue); 149 expect(computeFast(), isTrue);
113 // Labels in outer functions are never accessible. 150 // Labels in outer functions are never accessible.
114 assertSuggestLabel('bar'); 151 assertSuggestLabel('bar');
115 assertNotSuggested('foo'); 152 assertNotSuggested('foo');
116 } 153 }
117 154
118 test_continue_ignores_outer_functions_using_local_function() { 155 test_continue_ignores_outer_functions_using_closure_with_switch() {
156 addTestSource('''
157 void main() {
158 switch (x) {
159 foo: case 1:
160 var f = () {
161 bar: while (true) { continue ^ }
162 };
163 }
164 }
165 ''');
166 expect(computeFast(), isTrue);
167 // Labels in outer functions are never accessible.
168 assertSuggestLabel('bar');
169 assertNotSuggested('foo');
170 }
171
172 test_continue_ignores_outer_functions_using_local_function_with_loop() {
119 addTestSource(''' 173 addTestSource('''
120 void main() { 174 void main() {
121 foo: while (true) { 175 foo: while (true) {
122 void f() { 176 void f() {
123 bar: while (true) { continue ^ } 177 bar: while (true) { continue ^ }
124 }; 178 };
125 } 179 }
126 } 180 }
127 '''); 181 ''');
128 expect(computeFast(), isTrue); 182 expect(computeFast(), isTrue);
129 // Labels in outer functions are never accessible. 183 // Labels in outer functions are never accessible.
130 assertSuggestLabel('bar'); 184 assertSuggestLabel('bar');
131 assertNotSuggested('foo'); 185 assertNotSuggested('foo');
132 } 186 }
133 187
188 test_continue_ignores_outer_functions_using_local_function_with_switch() {
189 addTestSource('''
190 void main() {
191 switch (x) {
192 foo: case 1:
193 void f() {
194 bar: while (true) { continue ^ }
195 };
196 }
197 }
198 ''');
199 expect(computeFast(), isTrue);
200 // Labels in outer functions are never accessible.
201 assertSuggestLabel('bar');
202 assertNotSuggested('foo');
203 }
204
134 test_continue_ignores_unrelated_statements() { 205 test_continue_ignores_unrelated_statements() {
135 addTestSource(''' 206 addTestSource('''
136 void main() { 207 void main() {
137 foo: while (true) {} 208 foo: while (true) {}
138 while (true) { continue ^ } 209 while (true) { continue ^ }
139 bar: while (true) {} 210 bar: while (true) {}
140 } 211 }
141 '''); 212 ''');
142 expect(computeFast(), isTrue); 213 expect(computeFast(), isTrue);
143 // The scope of the label defined by a labeled statement is just the 214 // The scope of the label defined by a labeled statement is just the
144 // statement itself, so neither "foo" nor "bar" are in scope at the caret 215 // statement itself, so neither "foo" nor "bar" are in scope at the caret
145 // position. 216 // position.
146 assertNotSuggested('foo'); 217 assertNotSuggested('foo');
147 assertNotSuggested('bar'); 218 assertNotSuggested('bar');
148 } 219 }
149 220
221 test_continue_to_earlier_case() {
222 addTestSource('''
223 void main() {
224 switch (x) {
225 foo: case 1:
226 break;
227 case 2:
228 continue ^;
229 case 3:
230 break;
231 ''');
232 expect(computeFast(), isTrue);
233 assertSuggestLabel('foo');
234 }
235
150 test_continue_to_enclosing_loop() { 236 test_continue_to_enclosing_loop() {
151 addTestSource(''' 237 addTestSource('''
152 void main() { 238 void main() {
153 foo: while (true) { 239 foo: while (true) {
154 bar: while (true) { 240 bar: while (true) {
155 continue ^ 241 continue ^
156 } 242 }
157 } 243 }
158 } 244 }
159 '''); 245 ''');
160 expect(computeFast(), isTrue); 246 expect(computeFast(), isTrue);
161 assertSuggestLabel('foo'); 247 assertSuggestLabel('foo');
162 assertSuggestLabel('bar'); 248 assertSuggestLabel('bar');
163 } 249 }
250
251 test_continue_to_enclosing_switch() {
252 addTestSource('''
253 void main() {
254 switch (x) {
255 foo: case 1:
256 break;
257 bar: case 2:
258 switch (y) {
259 case 1:
260 continue ^;
261 }
262 break;
263 baz: case 3:
264 break;
265 }
164 } 266 }
267 ''');
268 expect(computeFast(), isTrue);
269 assertSuggestLabel('foo');
270 assertSuggestLabel('bar');
271 assertSuggestLabel('baz');
272 }
273
274 test_continue_to_later_case() {
275 addTestSource('''
276 void main() {
277 switch (x) {
278 case 1:
279 break;
280 case 2:
281 continue ^;
282 foo: case 3:
283 break;
284 ''');
285 expect(computeFast(), isTrue);
286 assertSuggestLabel('foo');
287 }
288
289 test_continue_to_same_case() {
290 addTestSource('''
291 void main() {
292 switch (x) {
293 case 1:
294 break;
295 foo: case 2:
296 continue ^;
297 case 3:
298 break;
299 ''');
300 expect(computeFast(), isTrue);
301 assertSuggestLabel('foo');
302 }
303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698