| 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/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'; |
| 11 import 'completion_test_util.dart'; | 11 import 'completion_test_util.dart'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 groupSep = ' | '; | 14 groupSep = ' | '; |
| 15 runReflectiveTests(LocalComputerTest); | 15 runReflectiveTests(LocalComputerTest); |
| 16 } | 16 } |
| 17 | 17 |
| 18 @ReflectiveTestCase() | 18 @ReflectiveTestCase() |
| 19 class LocalComputerTest extends AbstractSelectorSuggestionTest { | 19 class LocalComputerTest extends AbstractSelectorSuggestionTest { |
| 20 | 20 |
| 21 @override | 21 @override |
| 22 void setUpComputer() { | 22 void setUpComputer() { |
| 23 computer = new LocalComputer(); | 23 computer = new LocalComputer(); |
| 24 } | 24 } |
| 25 |
| 26 test_break_ignores_outer_functions_using_closure() { |
| 27 addTestSource(''' |
| 28 void main() { |
| 29 foo: while (true) { |
| 30 var f = () { |
| 31 bar: while (true) { break ^ } |
| 32 }; |
| 33 } |
| 25 } | 34 } |
| 35 '''); |
| 36 expect(computeFast(), isTrue); |
| 37 // Labels in outer functions are never accessible. |
| 38 assertSuggestLabel('bar'); |
| 39 assertNotSuggested('foo'); |
| 40 } |
| 41 |
| 42 test_break_ignores_outer_functions_using_local_function() { |
| 43 addTestSource(''' |
| 44 void main() { |
| 45 foo: while (true) { |
| 46 void f() { |
| 47 bar: while (true) { break ^ } |
| 48 }; |
| 49 } |
| 50 } |
| 51 '''); |
| 52 expect(computeFast(), isTrue); |
| 53 // Labels in outer functions are never accessible. |
| 54 assertSuggestLabel('bar'); |
| 55 assertNotSuggested('foo'); |
| 56 } |
| 57 |
| 58 test_break_ignores_toplevel_variables() { |
| 59 addTestSource(''' |
| 60 int x; |
| 61 void main() { |
| 62 while (true) { |
| 63 break ^ |
| 64 } |
| 65 } |
| 66 '''); |
| 67 expect(computeFast(), isTrue); |
| 68 assertNotSuggested('x'); |
| 69 } |
| 70 |
| 71 test_break_ignores_unrelated_statements() { |
| 72 addTestSource(''' |
| 73 void main() { |
| 74 foo: while (true) {} |
| 75 while (true) { break ^ } |
| 76 bar: while (true) {} |
| 77 } |
| 78 '''); |
| 79 expect(computeFast(), isTrue); |
| 80 // The scope of the label defined by a labeled statement is just the |
| 81 // statement itself, so neither "foo" nor "bar" are in scope at the caret |
| 82 // position. |
| 83 assertNotSuggested('foo'); |
| 84 assertNotSuggested('bar'); |
| 85 } |
| 86 |
| 87 test_break_to_enclosing_loop() { |
| 88 addTestSource(''' |
| 89 void main() { |
| 90 foo: while (true) { |
| 91 bar: while (true) { |
| 92 break ^ |
| 93 } |
| 94 } |
| 95 } |
| 96 '''); |
| 97 expect(computeFast(), isTrue); |
| 98 assertSuggestLabel('foo'); |
| 99 assertSuggestLabel('bar'); |
| 100 } |
| 101 |
| 102 test_continue_ignores_outer_functions_using_closure() { |
| 103 addTestSource(''' |
| 104 void main() { |
| 105 foo: while (true) { |
| 106 var f = () { |
| 107 bar: while (true) { continue ^ } |
| 108 }; |
| 109 } |
| 110 } |
| 111 '''); |
| 112 expect(computeFast(), isTrue); |
| 113 // Labels in outer functions are never accessible. |
| 114 assertSuggestLabel('bar'); |
| 115 assertNotSuggested('foo'); |
| 116 } |
| 117 |
| 118 test_continue_ignores_outer_functions_using_local_function() { |
| 119 addTestSource(''' |
| 120 void main() { |
| 121 foo: while (true) { |
| 122 void f() { |
| 123 bar: while (true) { continue ^ } |
| 124 }; |
| 125 } |
| 126 } |
| 127 '''); |
| 128 expect(computeFast(), isTrue); |
| 129 // Labels in outer functions are never accessible. |
| 130 assertSuggestLabel('bar'); |
| 131 assertNotSuggested('foo'); |
| 132 } |
| 133 |
| 134 test_continue_ignores_unrelated_statements() { |
| 135 addTestSource(''' |
| 136 void main() { |
| 137 foo: while (true) {} |
| 138 while (true) { continue ^ } |
| 139 bar: while (true) {} |
| 140 } |
| 141 '''); |
| 142 expect(computeFast(), isTrue); |
| 143 // 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 |
| 145 // position. |
| 146 assertNotSuggested('foo'); |
| 147 assertNotSuggested('bar'); |
| 148 } |
| 149 |
| 150 test_continue_to_enclosing_loop() { |
| 151 addTestSource(''' |
| 152 void main() { |
| 153 foo: while (true) { |
| 154 bar: while (true) { |
| 155 continue ^ |
| 156 } |
| 157 } |
| 158 } |
| 159 '''); |
| 160 expect(computeFast(), isTrue); |
| 161 assertSuggestLabel('foo'); |
| 162 assertSuggestLabel('bar'); |
| 163 } |
| 164 } |
| OLD | NEW |