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

Unified Diff: pkg/analysis_server/test/services/completion/local_computer_test.dart

Issue 812593008: Completion support for loop labels. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix problems with toplevel variables. 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/services/completion/local_computer_test.dart
diff --git a/pkg/analysis_server/test/services/completion/local_computer_test.dart b/pkg/analysis_server/test/services/completion/local_computer_test.dart
index 17c1f377ca1d0ae0135ae5c7f1dbfab996de1110..0e629e13571985f0db413ff4cf158d1ba440a43e 100644
--- a/pkg/analysis_server/test/services/completion/local_computer_test.dart
+++ b/pkg/analysis_server/test/services/completion/local_computer_test.dart
@@ -22,4 +22,143 @@ class LocalComputerTest extends AbstractSelectorSuggestionTest {
void setUpComputer() {
computer = new LocalComputer();
}
+
+ test_break_ignores_outer_functions_using_closure() {
+ addTestSource('''
+void main() {
+ foo: while (true) {
+ var f = () {
+ bar: while (true) { break ^ }
+ };
+ }
+}
+''');
+ expect(computeFast(), isTrue);
+ // Labels in outer functions are never accessible.
+ assertSuggestLabel('bar');
+ assertNotSuggested('foo');
+ }
+
+ test_break_ignores_outer_functions_using_local_function() {
+ addTestSource('''
+void main() {
+ foo: while (true) {
+ void f() {
+ bar: while (true) { break ^ }
+ };
+ }
+}
+''');
+ expect(computeFast(), isTrue);
+ // Labels in outer functions are never accessible.
+ assertSuggestLabel('bar');
+ assertNotSuggested('foo');
+ }
+
+ test_break_ignores_toplevel_variables() {
+ addTestSource('''
+int x;
+void main() {
+ while (true) {
+ break ^
+ }
+}
+''');
+ expect(computeFast(), isTrue);
+ assertNotSuggested('x');
+ }
+
+ test_break_ignores_unrelated_statements() {
+ addTestSource('''
+void main() {
+ foo: while (true) {}
+ while (true) { break ^ }
+ bar: while (true) {}
+}
+''');
+ expect(computeFast(), isTrue);
+ // The scope of the label defined by a labeled statement is just the
+ // statement itself, so neither "foo" nor "bar" are in scope at the caret
+ // position.
+ assertNotSuggested('foo');
+ assertNotSuggested('bar');
+ }
+
+ test_break_to_enclosing_loop() {
+ addTestSource('''
+void main() {
+ foo: while (true) {
+ bar: while (true) {
+ break ^
+ }
+ }
+}
+''');
+ expect(computeFast(), isTrue);
+ assertSuggestLabel('foo');
+ assertSuggestLabel('bar');
+ }
+
+ test_continue_ignores_outer_functions_using_closure() {
+ addTestSource('''
+void main() {
+ foo: while (true) {
+ var f = () {
+ bar: while (true) { continue ^ }
+ };
+ }
+}
+''');
+ expect(computeFast(), isTrue);
+ // Labels in outer functions are never accessible.
+ assertSuggestLabel('bar');
+ assertNotSuggested('foo');
+ }
+
+ test_continue_ignores_outer_functions_using_local_function() {
+ addTestSource('''
+void main() {
+ foo: while (true) {
+ void f() {
+ bar: while (true) { continue ^ }
+ };
+ }
+}
+''');
+ expect(computeFast(), isTrue);
+ // Labels in outer functions are never accessible.
+ assertSuggestLabel('bar');
+ assertNotSuggested('foo');
+ }
+
+ test_continue_ignores_unrelated_statements() {
+ addTestSource('''
+void main() {
+ foo: while (true) {}
+ while (true) { continue ^ }
+ bar: while (true) {}
+}
+''');
+ expect(computeFast(), isTrue);
+ // The scope of the label defined by a labeled statement is just the
+ // statement itself, so neither "foo" nor "bar" are in scope at the caret
+ // position.
+ assertNotSuggested('foo');
+ assertNotSuggested('bar');
+ }
+
+ test_continue_to_enclosing_loop() {
+ addTestSource('''
+void main() {
+ foo: while (true) {
+ bar: while (true) {
+ continue ^
+ }
+ }
+}
+''');
+ expect(computeFast(), isTrue);
+ assertSuggestLabel('foo');
+ assertSuggestLabel('bar');
+ }
}

Powered by Google App Engine
This is Rietveld 408576698