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

Side by Side Diff: tests/language/switch_test.dart

Issue 10540114: Issue 3528. Additional checks for 'case expressions' (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
Brian Wilkerson 2012/06/12 14:58:50 nit: copyright year
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 // Test switch statement. 4 // Test switch statement.
5 5
6 class Switcher { 6 class Switcher {
7 7
8 Switcher() { } 8 Switcher() { }
9 9
10 test1 (val) { 10 test1 (val) {
11 var x = 0; 11 var x = 0;
12 switch (val) { 12 switch (val) {
13 case 1: 13 case 1:
14 x = 100; break; 14 x = 100; break;
15 case 2: 15 case 2:
16 case 3: 16 case 3:
17 x = 200; break; 17 x = 200; break;
18 case "mister string":
19 return 300;
20 case 4: 18 case 4:
21 default: { 19 default: {
22 x = 400; break; 20 x = 400; break;
23 } 21 }
24 } 22 }
25 return x; 23 return x;
26 } 24 }
27 25
28 test2 (val) { 26 test2 (val) {
29 switch (val) { 27 switch (val) {
30 case true: return 100;
31 case 1: return 200; 28 case 1: return 200;
32 case "1": return 300;
33 default: return 400; 29 default: return 400;
34 } 30 }
35 } 31 }
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 } 32 }
46 33
47 34
48 class SwitchTest { 35 class SwitchTest {
49 static testMain() { 36 static testMain() {
50 Switcher s = new Switcher(); 37 Switcher s = new Switcher();
51 Expect.equals(100, s.test1(1)); 38 Expect.equals(100, s.test1(1));
52 Expect.equals(200, s.test1(2)); 39 Expect.equals(200, s.test1(2));
53 Expect.equals(200, s.test1(3)); 40 Expect.equals(200, s.test1(3));
54 Expect.equals(300, s.test1("mister string"));
55 Expect.equals(400, s.test1(4)); 41 Expect.equals(400, s.test1(4));
56 Expect.equals(400, s.test1(5)); 42 Expect.equals(400, s.test1(5));
57 43
58 Expect.equals(200, s.test2(1)); 44 Expect.equals(200, s.test2(1));
59 Expect.equals(300, s.test2("1")); 45 Expect.equals(400, s.test2(2));
60
61 Expect.equals(true, s.test3(5));
62 Expect.equals(false, s.test3(6));
63 } 46 }
64 } 47 }
65 48
66 main() { 49 main() {
67 SwitchTest.testMain(); 50 SwitchTest.testMain();
68 } 51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698