| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 switcher(val) { | |
| 6 var x = 0; | |
| 7 switch (val) { | |
| 8 case 1: | |
| 9 x = 100; | |
| 10 break; | |
| 11 case 2: | |
| 12 x = 200; | |
| 13 break; | |
| 14 case 3: | |
| 15 x = 300; | |
| 16 break; | |
| 17 default: | |
| 18 return 400; | |
| 19 break; // Intentional dead code (regression test for crash). | |
| 20 } | |
| 21 return x; | |
| 22 } | |
| 23 | |
| 24 | |
| 25 // Check unambiguated grammar allowing multiple lables per case/default. | |
| 26 switcher2(val) { | |
| 27 var x = 0; | |
| 28 switch (val) { | |
| 29 foo: | |
| 30 bar: | |
| 31 case 1: | |
| 32 baz: | |
| 33 case 2: | |
| 34 fez: { | |
| 35 x = 100; | |
| 36 break fez; | |
| 37 } | |
| 38 break; | |
| 39 hest: | |
| 40 fisk: | |
| 41 case 3: | |
| 42 case 4: | |
| 43 svin: | |
| 44 default: | |
| 45 barber: { | |
| 46 if (val > 2) { | |
| 47 x = 200; | |
| 48 break; | |
| 49 } else { | |
| 50 // Enable when continue to switch-case is implemented. | |
| 51 continue hest; /// 03: compile-time error | |
| 52 } | |
| 53 } | |
| 54 } | |
| 55 return x; | |
| 56 } | |
| 57 | |
| 58 | |
| 59 badswitches(val) { | |
| 60 // Test some badly formed switch bodies. | |
| 61 // 01 - a label/statement without a following case/default. | |
| 62 // 02 - a label without a following case/default or statement. | |
| 63 switch (val) { | |
| 64 foo: break; /// 01: compile-time error | |
| 65 case 2: /// 02: compile-time error | |
| 66 foo: /// 02: continued | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 main() { | |
| 71 Expect.equals(100, switcher(1)); | |
| 72 Expect.equals(200, switcher(2)); | |
| 73 Expect.equals(300, switcher(3)); | |
| 74 Expect.equals(400, switcher(4)); | |
| 75 | |
| 76 Expect.equals(100, switcher2(1)); | |
| 77 Expect.equals(100, switcher2(2)); | |
| 78 Expect.equals(200, switcher2(3)); | |
| 79 Expect.equals(200, switcher2(4)); | |
| 80 Expect.equals(200, switcher2(5)); | |
| 81 | |
| 82 badswitches(42); | |
| 83 } | |
| OLD | NEW |