|
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-001.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-001"; |
|
19 var VERSION = "ECMA_2"; |
|
20 var TITLE = "The switch statement"; |
|
21 |
|
22 var BUGNUMBER="315767"; |
|
23 |
|
24 startTest(); |
|
25 writeHeaderToLog( SECTION + " "+ TITLE); |
|
26 |
|
27 SwitchTest( 0, 126 ); |
|
28 SwitchTest( 1, 124 ); |
|
29 SwitchTest( 2, 120 ); |
|
30 SwitchTest( 3, 112 ); |
|
31 SwitchTest( 4, 64 ); |
|
32 SwitchTest( 5, 96 ); |
|
33 SwitchTest( true, 96 ); |
|
34 SwitchTest( false, 96 ); |
|
35 SwitchTest( null, 96 ); |
|
36 SwitchTest( void 0, 96 ); |
|
37 SwitchTest( "0", 96 ); |
|
38 |
|
39 test(); |
|
40 |
|
41 function SwitchTest( input, expect ) { |
|
42 var result = 0; |
|
43 |
|
44 switch ( input ) { |
|
45 case 0: |
|
46 result += 2; |
|
47 case 1: |
|
48 result += 4; |
|
49 case 2: |
|
50 result += 8; |
|
51 case 3: |
|
52 result += 16; |
|
53 default: |
|
54 result += 32; |
|
55 case 4: |
|
56 result +=64; |
|
57 } |
|
58 |
|
59 new TestCase( |
|
60 SECTION, |
|
61 "switch with no breaks, case expressions are numbers. input is "+ |
|
62 input, |
|
63 expect, |
|
64 result ); |
|
65 } |