|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 * File Name: switch-002.js |
|
9 * ECMA Section: |
|
10 * Description: The switch Statement |
|
11 * |
|
12 * A simple switch test with no abrupt completions. |
|
13 * |
|
14 * Author: christine@netscape.com |
|
15 * Date: 11 August 1998 |
|
16 * |
|
17 */ |
|
18 var SECTION = "switch-002"; |
|
19 var VERSION = "ECMA_2"; |
|
20 var TITLE = "The switch statement"; |
|
21 |
|
22 startTest(); |
|
23 writeHeaderToLog( SECTION + " "+ TITLE); |
|
24 |
|
25 SwitchTest( 0, 6 ); |
|
26 SwitchTest( 1, 4 ); |
|
27 SwitchTest( 2, 56 ); |
|
28 SwitchTest( 3, 48 ); |
|
29 SwitchTest( 4, 64 ); |
|
30 SwitchTest( true, 32 ); |
|
31 SwitchTest( false, 32 ); |
|
32 SwitchTest( null, 32 ); |
|
33 SwitchTest( void 0, 32 ); |
|
34 SwitchTest( "0", 32 ); |
|
35 |
|
36 test(); |
|
37 |
|
38 function SwitchTest( input, expect ) { |
|
39 var result = 0; |
|
40 |
|
41 switch ( input ) { |
|
42 case 0: |
|
43 result += 2; |
|
44 case 1: |
|
45 result += 4; |
|
46 break; |
|
47 case 2: |
|
48 result += 8; |
|
49 case 3: |
|
50 result += 16; |
|
51 default: |
|
52 result += 32; |
|
53 break; |
|
54 case 4: |
|
55 result += 64; |
|
56 } |
|
57 |
|
58 new TestCase( |
|
59 SECTION, |
|
60 "switch with no breaks: input is " + input, |
|
61 expect, |
|
62 result ); |
|
63 } |