OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Test reporting a compile-time error if case expressions do not all have | 5 // Test reporting a compile-time error if case expressions do not all have |
6 // the same type or are of type double. | 6 // the same type or are of type double. |
7 | 7 |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 | 9 |
10 void main() { | 10 void main() { |
11 Expect.equals("IV", caesarSays(4)); | 11 Expect.equals("IV", caesarSays(4)); |
12 Expect.equals(null, caesarSays(2)); | 12 Expect.equals(null, caesarSays(2)); |
13 Expect.equals(null, archimedesSays(3.14)); | 13 Expect.equals(null, archimedesSays(3.14)); |
14 } | 14 } |
15 | 15 |
16 caesarSays(n) { | 16 caesarSays(n) { |
17 switch (n) { | 17 switch (n) { |
18 case 1: | 18 case 1: |
19 return "I"; | 19 return "I"; |
20 case 4: | 20 case 4: |
21 return "IV"; | 21 return "IV"; |
22 case "M": /// 01: compile-time error | 22 case "M": // /// 01: compile-time error |
23 return 1000; /// 01: continued | 23 return 1000; // /// 01: continued |
24 } | 24 } |
25 return null; | 25 return null; |
26 } | 26 } |
27 | 27 |
28 archimedesSays(n) { | 28 archimedesSays(n) { |
29 switch (n) { /// 02: continued | 29 switch (n) { // /// 02: continued |
30 case 3.14: /// 02: compile-time error | 30 case 3.14: // /// 02: compile-time error |
31 return "Pi"; /// 02: continued | 31 return "Pi"; // /// 02: continued |
32 case 2.71828: /// 02: continued | 32 case 2.71828: // /// 02: continued |
33 return "Huh?"; /// 02: continued | 33 return "Huh?"; // /// 02: continued |
34 } /// 02: continued | 34 } // /// 02: continued |
35 return null; | 35 return null; |
36 } | 36 } |
OLD | NEW |