Files
sdk/tests/language/switch/infinite_switch_label_test.dart
T
Robert Nystrom 5a27ea139e Migrate language_2/switch to NNBD.
Change-Id: Idbf338099414c78e1bb6ee2852c41495fb53f70b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151471
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
2020-06-17 02:17:36 +00:00

40 lines
946 B
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test nested switch statement using labels.
library nested_switch_label;
import "package:expect/expect.dart";
void main() {
Expect.throws(() => doSwitch(0), (list) {
Expect.listEquals([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], list as List);
return true;
});
Expect.throws(() => doSwitch(2), (list) {
Expect.listEquals([2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0], list as List);
return true;
});
}
void doSwitch(int target) {
List list = [];
switch (target) {
l0:
case 0:
if (list.length > 10) throw list;
list.add(0);
continue l1;
l1:
case 1:
if (list.length > 10) throw list;
list.add(1);
continue l0;
default:
list.add(2);
continue l1;
}
}