]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/ecma_2/Statements/switch-001.js
JavaScriptCore-461.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma_2 / Statements / switch-001.js
CommitLineData
b37bf2e1
A
1/**
2 * File Name: switch-001.js
3 * ECMA Section:
4 * Description: The switch Statement
5 *
6 * A simple switch test with no abrupt completions.
7 *
8 * Author: christine@netscape.com
9 * Date: 11 August 1998
10 *
11 */
12 var SECTION = "switch-001";
13 var VERSION = "ECMA_2";
14 var TITLE = "The switch statement";
15
16 var BUGNUMBER="315767";
17
18
19
20 startTest();
21 writeHeaderToLog( SECTION + " "+ TITLE);
22
23 var tc = 0;
24 var testcases = new Array();
25
26 SwitchTest( 0, 126 );
27 SwitchTest( 1, 124 );
28 SwitchTest( 2, 120 );
29 SwitchTest( 3, 112 );
30 SwitchTest( 4, 64 );
31 SwitchTest( 5, 96 );
32 SwitchTest( true, 96 );
33 SwitchTest( false, 96 );
34 SwitchTest( null, 96 );
35 SwitchTest( void 0, 96 );
36 SwitchTest( "0", 96 );
37
38 test();
39
40 function SwitchTest( input, expect ) {
41 var result = 0;
42
43 switch ( input ) {
44 case 0:
45 result += 2;
46 case 1:
47 result += 4;
48 case 2:
49 result += 8;
50 case 3:
51 result += 16;
52 default:
53 result += 32;
54 case 4:
55 result +=64;
56 }
57
58 testcases[tc++] = new TestCase(
59 SECTION,
60 "switch with no breaks, case expressions are numbers. input is "+
61 input,
62 expect,
63 result );
64 }