OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, 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 // Test switch statement. | |
5 | |
6 class Switcher { | |
7 | |
8 Switcher() { } | |
9 | |
10 test1 (val) { | |
11 var x = 0; | |
12 switch (val) { | |
13 case 1: | |
14 x = 100; break; | |
15 case 2: | |
16 case 3: | |
17 x = 200; break; | |
18 case "mister string": | |
19 return 300; | |
20 case 4: | |
21 default: { | |
22 x = 400; break; | |
23 } | |
24 } | |
25 return x; | |
26 } | |
27 | |
28 test2 (val) { | |
29 switch (val) { | |
30 case true: return 100; | |
31 case 1: return 200; | |
32 case "1": return 300; | |
33 default: return 400; | |
34 } | |
35 } | |
36 | |
37 test3(val) { | |
38 final int temp = 5; | |
39 switch (true) { | |
40 case temp == val: | |
41 return true; | |
42 } | |
43 return false; | |
44 } | |
45 } | |
46 | |
47 | |
48 class SwitchTest { | |
49 static testMain() { | |
50 Switcher s = new Switcher(); | |
51 Expect.equals(100, s.test1(1)); | |
52 Expect.equals(200, s.test1(2)); | |
53 Expect.equals(200, s.test1(3)); | |
54 Expect.equals(300, s.test1("mister string")); | |
55 Expect.equals(400, s.test1(4)); | |
56 Expect.equals(400, s.test1(5)); | |
57 | |
58 Expect.equals(200, s.test2(1)); | |
59 Expect.equals(300, s.test2("1")); | |
60 | |
61 Expect.equals(true, s.test3(5)); | |
62 Expect.equals(false, s.test3(6)); | |
63 } | |
64 } | |
65 | |
66 main() { | |
67 SwitchTest.testMain(); | |
68 } | |
OLD | NEW |