Debian Codegraph @

rhino/testsrc/tests/ecma_2/Statements/switch-002.js

raw symbols SCIP
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 gTestfile = 'switch-002.js';
7
8 /**
9 * File Name: switch-002.js
10 * ECMA Section:
11 * Description: The switch Statement
12 *
13 * A simple switch test with no abrupt completions.
14 *
15 * Author: [email protected]
16 * Date: 11 August 1998
17 *
18 */
19 var SECTION = "switch-002";
20 var VERSION = "ECMA_2";
21 var TITLE = "The switch statement";
22
23 startTest();
24 writeHeaderToLog( SECTION + " "+ TITLE);
25
26 SwitchTest( 0, 6 );
27 SwitchTest( 1, 4 );
28 SwitchTest( 2, 56 );
29 SwitchTest( 3, 48 );
30 SwitchTest( 4, 64 );
31 SwitchTest( true, 32 );
32 SwitchTest( false, 32 );
33 SwitchTest( null, 32 );
34 SwitchTest( void 0, 32 );
35 SwitchTest( "0", 32 );
36
37 test();
38
39 function SwitchTest( input, expect ) {
40 var result = 0;
41
42 switch ( input ) {
43 case 0:
44 result += 2;
45 case 1:
46 result += 4;
47 break;
48 case 2:
49 result += 8;
50 case 3:
51 result += 16;
52 default:
53 result += 32;
54 break;
55 case 4:
56 result += 64;
57 }
58
59 new TestCase(
60 SECTION,
61 "switch with no breaks: input is " + input,
62 expect,
63 result );
64 }