| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 switcher(val) { | 7 switcher(val) { |
| 8 var x = 0; | 8 var x = 0; |
| 9 switch (val) { | 9 switch (val) { |
| 10 case 1: | 10 case 1: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 break; | 51 break; |
| 52 } else { | 52 } else { |
| 53 // Enable when continue to switch-case is implemented. | 53 // Enable when continue to switch-case is implemented. |
| 54 continue hest; | 54 continue hest; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 return x; | 58 return x; |
| 59 } | 59 } |
| 60 | 60 |
| 61 var x = 0; |
| 62 |
| 63 @NoInline() |
| 64 switcher3(val) { |
| 65 switch(val) { |
| 66 case 1: |
| 67 default: |
| 68 incrementX(); |
| 69 } |
| 70 } |
| 71 |
| 72 incrementX() { |
| 73 x++; |
| 74 } |
| 75 |
| 61 badswitches(val) { | 76 badswitches(val) { |
| 62 // Test some badly formed switch bodies. | 77 // Test some badly formed switch bodies. |
| 63 // 01 - a label/statement without a following case/default. | 78 // 01 - a label/statement without a following case/default. |
| 64 // 02 - a label without a following case/default or statement. | 79 // 02 - a label without a following case/default or statement. |
| 65 switch (val) { | 80 switch (val) { |
| 66 foo: break; // //# 01: compile-time error | 81 foo: break; // //# 01: compile-time error |
| 67 case 2: // //# 02: compile-time error | 82 case 2: // //# 02: compile-time error |
| 68 foo: // //# 02: continued | 83 foo: // //# 02: continued |
| 69 } | 84 } |
| 70 } | 85 } |
| 71 | 86 |
| 72 main() { | 87 main() { |
| 73 Expect.equals(100, switcher(1)); | 88 Expect.equals(100, switcher(1)); |
| 74 Expect.equals(200, switcher(2)); | 89 Expect.equals(200, switcher(2)); |
| 75 Expect.equals(300, switcher(3)); | 90 Expect.equals(300, switcher(3)); |
| 76 Expect.equals(400, switcher(4)); | 91 Expect.equals(400, switcher(4)); |
| 77 | 92 |
| 78 Expect.equals(100, switcher2(1)); | 93 Expect.equals(100, switcher2(1)); |
| 79 Expect.equals(100, switcher2(2)); | 94 Expect.equals(100, switcher2(2)); |
| 80 Expect.equals(200, switcher2(3)); | 95 Expect.equals(200, switcher2(3)); |
| 81 Expect.equals(200, switcher2(4)); | 96 Expect.equals(200, switcher2(4)); |
| 82 Expect.equals(200, switcher2(5)); | 97 Expect.equals(200, switcher2(5)); |
| 83 | 98 |
| 99 switcher3(1); |
| 100 Expect.equals(1, x); |
| 101 |
| 84 badswitches(42); | 102 badswitches(42); |
| 85 } | 103 } |
| OLD | NEW |