OLD | NEW |
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/plugin/protocol/protocol.dart' as protocol | 7 import 'package:analysis_server/plugin/protocol/protocol.dart' as protocol |
8 show Element, ElementKind; | 8 show Element, ElementKind; |
9 import 'package:analysis_server/plugin/protocol/protocol.dart' | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' |
10 hide Element, ElementKind; | 10 hide Element, ElementKind; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 void main() { | 167 void main() { |
168 foo: while (true) { | 168 foo: while (true) { |
169 var f = () { | 169 var f = () { |
170 bar: while (true) { break ^ } | 170 bar: while (true) { break ^ } |
171 }; | 171 }; |
172 } | 172 } |
173 } | 173 } |
174 '''); | 174 '''); |
175 expect(computeFast(), isTrue); | 175 expect(computeFast(), isTrue); |
176 // Labels in outer functions are never accessible. | 176 // Labels in outer functions are never accessible. |
177 assertSuggestLabel('bar'); | 177 assertNotSuggested('bar'); |
178 assertNotSuggested('foo'); | 178 assertNotSuggested('foo'); |
179 } | 179 } |
180 | 180 |
181 test_break_ignores_outer_functions_using_local_function() { | 181 test_break_ignores_outer_functions_using_local_function() { |
182 addTestSource(''' | 182 addTestSource(''' |
183 void main() { | 183 void main() { |
184 foo: while (true) { | 184 foo: while (true) { |
185 void f() { | 185 void f() { |
186 bar: while (true) { break ^ } | 186 bar: while (true) { break ^ } |
187 }; | 187 }; |
188 } | 188 } |
189 } | 189 } |
190 '''); | 190 '''); |
191 expect(computeFast(), isTrue); | 191 expect(computeFast(), isTrue); |
192 // Labels in outer functions are never accessible. | 192 // Labels in outer functions are never accessible. |
193 assertSuggestLabel('bar'); | 193 assertNotSuggested('bar'); |
194 assertNotSuggested('foo'); | 194 assertNotSuggested('foo'); |
195 } | 195 } |
196 | 196 |
197 test_break_ignores_toplevel_variables() { | 197 test_break_ignores_toplevel_variables() { |
198 addTestSource(''' | 198 addTestSource(''' |
199 int x; | 199 int x; |
200 void main() { | 200 void main() { |
201 while (true) { | 201 while (true) { |
202 break ^ | 202 break ^ |
203 } | 203 } |
(...skipping 23 matching lines...) Expand all Loading... |
227 addTestSource(''' | 227 addTestSource(''' |
228 void main() { | 228 void main() { |
229 foo: while (true) { | 229 foo: while (true) { |
230 bar: while (true) { | 230 bar: while (true) { |
231 break ^ | 231 break ^ |
232 } | 232 } |
233 } | 233 } |
234 } | 234 } |
235 '''); | 235 '''); |
236 expect(computeFast(), isTrue); | 236 expect(computeFast(), isTrue); |
237 assertSuggestLabel('foo'); | 237 assertNotSuggested('foo'); |
238 assertSuggestLabel('bar'); | 238 assertNotSuggested('bar'); |
239 } | 239 } |
240 | 240 |
241 test_constructor_parameters_mixed_required_and_named() { | 241 test_constructor_parameters_mixed_required_and_named() { |
242 addTestSource('class A {A(x, {int y}) {^}}'); | 242 addTestSource('class A {A(x, {int y}) {^}}'); |
243 expect(computeFast(), isTrue); | 243 expect(computeFast(), isTrue); |
244 assertSuggestParameter('x', null); | 244 assertSuggestParameter('x', null); |
245 assertSuggestParameter('y', 'int'); | 245 assertSuggestParameter('y', 'int'); |
246 } | 246 } |
247 | 247 |
248 test_constructor_parameters_mixed_required_and_positional() { | 248 test_constructor_parameters_mixed_required_and_positional() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 while (true) { | 283 while (true) { |
284 continue ^; | 284 continue ^; |
285 } | 285 } |
286 break; | 286 break; |
287 baz: case 3: | 287 baz: case 3: |
288 break; | 288 break; |
289 } | 289 } |
290 } | 290 } |
291 '''); | 291 '''); |
292 expect(computeFast(), isTrue); | 292 expect(computeFast(), isTrue); |
293 assertSuggestLabel('foo'); | 293 assertNotSuggested('foo'); |
294 assertSuggestLabel('bar'); | 294 assertNotSuggested('bar'); |
295 assertSuggestLabel('baz'); | 295 assertNotSuggested('baz'); |
296 } | 296 } |
297 | 297 |
298 test_continue_from_switch_to_loop() { | 298 test_continue_from_switch_to_loop() { |
299 addTestSource(''' | 299 addTestSource(''' |
300 void main() { | 300 void main() { |
301 foo: while (true) { | 301 foo: while (true) { |
302 switch (x) { | 302 switch (x) { |
303 case 1: | 303 case 1: |
304 continue ^; | 304 continue ^; |
305 } | 305 } |
306 } | 306 } |
307 } | 307 } |
308 '''); | 308 '''); |
309 expect(computeFast(), isTrue); | 309 expect(computeFast(), isTrue); |
310 assertSuggestLabel('foo'); | 310 assertNotSuggested('foo'); |
311 } | 311 } |
312 | 312 |
313 test_continue_ignores_outer_functions_using_closure_with_loop() { | 313 test_continue_ignores_outer_functions_using_closure_with_loop() { |
314 addTestSource(''' | 314 addTestSource(''' |
315 void main() { | 315 void main() { |
316 foo: while (true) { | 316 foo: while (true) { |
317 var f = () { | 317 var f = () { |
318 bar: while (true) { continue ^ } | 318 bar: while (true) { continue ^ } |
319 }; | 319 }; |
320 } | 320 } |
321 } | 321 } |
322 '''); | 322 '''); |
323 expect(computeFast(), isTrue); | 323 expect(computeFast(), isTrue); |
324 // Labels in outer functions are never accessible. | 324 // Labels in outer functions are never accessible. |
325 assertSuggestLabel('bar'); | 325 assertNotSuggested('bar'); |
326 assertNotSuggested('foo'); | 326 assertNotSuggested('foo'); |
327 } | 327 } |
328 | 328 |
329 test_continue_ignores_outer_functions_using_closure_with_switch() { | 329 test_continue_ignores_outer_functions_using_closure_with_switch() { |
330 addTestSource(''' | 330 addTestSource(''' |
331 void main() { | 331 void main() { |
332 switch (x) { | 332 switch (x) { |
333 foo: case 1: | 333 foo: case 1: |
334 var f = () { | 334 var f = () { |
335 bar: while (true) { continue ^ } | 335 bar: while (true) { continue ^ } |
336 }; | 336 }; |
337 } | 337 } |
338 } | 338 } |
339 '''); | 339 '''); |
340 expect(computeFast(), isTrue); | 340 expect(computeFast(), isTrue); |
341 // Labels in outer functions are never accessible. | 341 // Labels in outer functions are never accessible. |
342 assertSuggestLabel('bar'); | 342 assertNotSuggested('bar'); |
343 assertNotSuggested('foo'); | 343 assertNotSuggested('foo'); |
344 } | 344 } |
345 | 345 |
346 test_continue_ignores_outer_functions_using_local_function_with_loop() { | 346 test_continue_ignores_outer_functions_using_local_function_with_loop() { |
347 addTestSource(''' | 347 addTestSource(''' |
348 void main() { | 348 void main() { |
349 foo: while (true) { | 349 foo: while (true) { |
350 void f() { | 350 void f() { |
351 bar: while (true) { continue ^ } | 351 bar: while (true) { continue ^ } |
352 }; | 352 }; |
353 } | 353 } |
354 } | 354 } |
355 '''); | 355 '''); |
356 expect(computeFast(), isTrue); | 356 expect(computeFast(), isTrue); |
357 // Labels in outer functions are never accessible. | 357 // Labels in outer functions are never accessible. |
358 assertSuggestLabel('bar'); | 358 assertNotSuggested('bar'); |
359 assertNotSuggested('foo'); | 359 assertNotSuggested('foo'); |
360 } | 360 } |
361 | 361 |
362 test_continue_ignores_outer_functions_using_local_function_with_switch() { | 362 test_continue_ignores_outer_functions_using_local_function_with_switch() { |
363 addTestSource(''' | 363 addTestSource(''' |
364 void main() { | 364 void main() { |
365 switch (x) { | 365 switch (x) { |
366 foo: case 1: | 366 foo: case 1: |
367 void f() { | 367 void f() { |
368 bar: while (true) { continue ^ } | 368 bar: while (true) { continue ^ } |
369 }; | 369 }; |
370 } | 370 } |
371 } | 371 } |
372 '''); | 372 '''); |
373 expect(computeFast(), isTrue); | 373 expect(computeFast(), isTrue); |
374 // Labels in outer functions are never accessible. | 374 // Labels in outer functions are never accessible. |
375 assertSuggestLabel('bar'); | 375 assertNotSuggested('bar'); |
376 assertNotSuggested('foo'); | 376 assertNotSuggested('foo'); |
377 } | 377 } |
378 | 378 |
379 test_continue_ignores_unrelated_statements() { | 379 test_continue_ignores_unrelated_statements() { |
380 addTestSource(''' | 380 addTestSource(''' |
381 void main() { | 381 void main() { |
382 foo: while (true) {} | 382 foo: while (true) {} |
383 while (true) { continue ^ } | 383 while (true) { continue ^ } |
384 bar: while (true) {} | 384 bar: while (true) {} |
385 } | 385 } |
(...skipping 11 matching lines...) Expand all Loading... |
397 void main() { | 397 void main() { |
398 switch (x) { | 398 switch (x) { |
399 foo: case 1: | 399 foo: case 1: |
400 break; | 400 break; |
401 case 2: | 401 case 2: |
402 continue ^; | 402 continue ^; |
403 case 3: | 403 case 3: |
404 break; | 404 break; |
405 '''); | 405 '''); |
406 expect(computeFast(), isTrue); | 406 expect(computeFast(), isTrue); |
407 assertSuggestLabel('foo'); | 407 assertNotSuggested('foo'); |
408 } | 408 } |
409 | 409 |
410 test_continue_to_enclosing_loop() { | 410 test_continue_to_enclosing_loop() { |
411 addTestSource(''' | 411 addTestSource(''' |
412 void main() { | 412 void main() { |
413 foo: while (true) { | 413 foo: while (true) { |
414 bar: while (true) { | 414 bar: while (true) { |
415 continue ^ | 415 continue ^ |
416 } | 416 } |
417 } | 417 } |
418 } | 418 } |
419 '''); | 419 '''); |
420 expect(computeFast(), isTrue); | 420 expect(computeFast(), isTrue); |
421 assertSuggestLabel('foo'); | 421 assertNotSuggested('foo'); |
422 assertSuggestLabel('bar'); | 422 assertNotSuggested('bar'); |
423 } | 423 } |
424 | 424 |
425 test_continue_to_enclosing_switch() { | 425 test_continue_to_enclosing_switch() { |
426 addTestSource(''' | 426 addTestSource(''' |
427 void main() { | 427 void main() { |
428 switch (x) { | 428 switch (x) { |
429 foo: case 1: | 429 foo: case 1: |
430 break; | 430 break; |
431 bar: case 2: | 431 bar: case 2: |
432 switch (y) { | 432 switch (y) { |
433 case 1: | 433 case 1: |
434 continue ^; | 434 continue ^; |
435 } | 435 } |
436 break; | 436 break; |
437 baz: case 3: | 437 baz: case 3: |
438 break; | 438 break; |
439 } | 439 } |
440 } | 440 } |
441 '''); | 441 '''); |
442 expect(computeFast(), isTrue); | 442 expect(computeFast(), isTrue); |
443 assertSuggestLabel('foo'); | 443 assertNotSuggested('foo'); |
444 assertSuggestLabel('bar'); | 444 assertNotSuggested('bar'); |
445 assertSuggestLabel('baz'); | 445 assertNotSuggested('baz'); |
446 } | 446 } |
447 | 447 |
448 test_continue_to_later_case() { | 448 test_continue_to_later_case() { |
449 addTestSource(''' | 449 addTestSource(''' |
450 void main() { | 450 void main() { |
451 switch (x) { | 451 switch (x) { |
452 case 1: | 452 case 1: |
453 break; | 453 break; |
454 case 2: | 454 case 2: |
455 continue ^; | 455 continue ^; |
456 foo: case 3: | 456 foo: case 3: |
457 break; | 457 break; |
458 '''); | 458 '''); |
459 expect(computeFast(), isTrue); | 459 expect(computeFast(), isTrue); |
460 assertSuggestLabel('foo'); | 460 assertNotSuggested('foo'); |
461 } | 461 } |
462 | 462 |
463 test_continue_to_same_case() { | 463 test_continue_to_same_case() { |
464 addTestSource(''' | 464 addTestSource(''' |
465 void main() { | 465 void main() { |
466 switch (x) { | 466 switch (x) { |
467 case 1: | 467 case 1: |
468 break; | 468 break; |
469 foo: case 2: | 469 foo: case 2: |
470 continue ^; | 470 continue ^; |
471 case 3: | 471 case 3: |
472 break; | 472 break; |
473 '''); | 473 '''); |
474 expect(computeFast(), isTrue); | 474 expect(computeFast(), isTrue); |
475 assertSuggestLabel('foo'); | 475 assertNotSuggested('foo'); |
476 } | 476 } |
477 | 477 |
478 test_enum() { | 478 test_enum() { |
479 addTestSource('enum E { one, two } main() {^}'); | 479 addTestSource('enum E { one, two } main() {^}'); |
480 expect(computeFast(), isTrue); | 480 expect(computeFast(), isTrue); |
481 assertSuggestEnum('E'); | 481 assertSuggestEnum('E'); |
482 assertNotSuggested('one'); | 482 assertNotSuggested('one'); |
483 assertNotSuggested('two'); | 483 assertNotSuggested('two'); |
484 } | 484 } |
485 | 485 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 assertSuggestLocalVariable('ab', null); | 839 assertSuggestLocalVariable('ab', null); |
840 assertSuggestLocalVariable('_ab', null, relevance: DART_RELEVANCE_DEFAULT); | 840 assertSuggestLocalVariable('_ab', null, relevance: DART_RELEVANCE_DEFAULT); |
841 } | 841 } |
842 | 842 |
843 test_shadowed_name() { | 843 test_shadowed_name() { |
844 addTestSource('var a; class A { var a; m() { ^ } }'); | 844 addTestSource('var a; class A { var a; m() { ^ } }'); |
845 expect(computeFast(), isTrue); | 845 expect(computeFast(), isTrue); |
846 assertSuggestLocalField('a', null); | 846 assertSuggestLocalField('a', null); |
847 } | 847 } |
848 } | 848 } |
OLD | NEW |