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

Unified Diff: tests/compiler/dart2js/kernel/switch_test.dart

Issue 2648443004: Implement complex switch statement (switch with continue). (Closed)
Patch Set: . Created 3 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
« no previous file with comments | « pkg/compiler/lib/src/ssa/switch_continue_analysis.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/kernel/switch_test.dart
diff --git a/tests/compiler/dart2js/kernel/switch_test.dart b/tests/compiler/dart2js/kernel/switch_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..10bfdbfd5fc6e1223d860cdfb600172b50d5526f
--- /dev/null
+++ b/tests/compiler/dart2js/kernel/switch_test.dart
@@ -0,0 +1,184 @@
+import 'package:test/test.dart';
+
+import 'helper.dart' show check;
+
+main() {
+ test('simple switch statement', () {
+ String code = '''
+main() {
+ int x = 2;
+ switch(x) {
+ case 1:
+ print('spider');
+ break;
+ case 2:
+ print('grasshopper');
+ break;
+ }
+}''';
+ return check(code);
+ });
+
+ test('switch with default', () {
+ String code = '''
+main() {
+ int x = 5;
+ switch(x) {
+ case 1:
+ print('spider');
+ break;
+ case 2:
+ print('grasshopper');
+ break;
+ default:
+ print('ladybug');
+
+ }
+}''';
+ return check(code);
+ });
+
+/*
+ // TODO(efortuna): Uncomment. Because of patch file weirdness, the original
+ // SSA vs the Kernel version is instantiating a subclass of the
+ // FallThroughError, so it produces slightly different code. Fix that.
+ test('switch with fall through error', () {
+ String code = '''
+main() {
+ int x = 2;
+ switch(x) {
+ case 1:
+ print('spider');
+ break;
+ case 2:
+ print('grasshopper');
+ case 3:
+ print('ant');
+ break;
+ default:
+ print('ladybug');
+ }
+}''';
+ return check(code);
+ });
+*/
+ test('switch with multi-case branch', () {
+ String code = '''
+main() {
+ int x = 3;
+ switch(x) {
+ case 1:
+ print('spider');
+ break;
+ case 2:
+ case 3:
+ case 4:
+ print('grasshopper');
+ print('ant');
+ break;
+ }
+}''';
+ return check(code);
+ });
+
+ test('switch with weird fall-through end case', () {
+ String code = '''
+main() {
+ int x = 6;
+ switch(x) {
+ case 1:
+ print('spider');
+ break;
+ case 5:
+ print('beetle');
+ break;
+ case 6:
+ }
+}''';
+ return check(code);
+ });
+
+ test('switch with labeled continue', () {
+ String code = '''
+main() {
+ int x = 1;
+ switch(x) {
+ case 1:
+ print('spider');
+ continue world;
+ case 5:
+ print('beetle');
+ break;
+ world:
+ case 6:
+ print('cricket');
+ break;
+ default:
+ print('bat');
+ }
+}''';
+ return check(code);
+ });
+
+ test('switch with continue to fall through', () {
+ String code = '''
+main() {
+ int x = 1;
+ switch(x) {
+ case 1:
+ print('spider');
+ continue world;
+ world:
+ case 5:
+ print('beetle');
+ break;
+ case 6:
+ print('cricket');
+ break;
+ default:
+ print('bat');
+ }
+}''';
+ return check(code);
+ });
+
+ test('switch with continue without default case', () {
+ String code = '''
+main() {
+ int x = 1;
+ switch(x) {
+ case 1:
+ print('spider');
+ continue world;
+ world:
+ case 5:
+ print('beetle');
+ break;
+ case 6:
+ print('cricket');
+ break;
+ }
+}''';
+ return check(code);
+ });
+
+ test('switch with continue without default case', () {
+ String code = '''
+main() {
+ int x = 8;
+ switch(x) {
+ case 1:
+ print('spider');
+ continue world;
+ world:
+ case 5:
+ print('beetle');
+ break;
+ case 6:
+ print('cricket');
+ break;
+ }
+}''';
+ return check(code);
+ });
+}
« no previous file with comments | « pkg/compiler/lib/src/ssa/switch_continue_analysis.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698