1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
18 * Netscape Communication Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 gTestfile = 'switch-004.js';
41 * File Name: switch-003.js
43 * Description: The switch Statement
45 * This uses variables and objects as case expressions in switch statements.
46 * This verifies a bunch of bugs:
48 * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315988
49 * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315975
50 * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315954
52 * Author: christine@netscape.com
53 * Date: 11 August 1998
56 var SECTION = "switch-003";
57 var VERSION = "ECMA_2";
58 var TITLE = "The switch statement";
59 var BUGNUMBER= "315988";
62 writeHeaderToLog( SECTION + " "+ TITLE);
66 var A = new String("A");
67 var B = new String("B");
68 TRUE = new Boolean( true );
69 FALSE = new Boolean( false );
73 SwitchTest( ZERO, "ZERO" );
74 SwitchTest( NULL, "NULL" );
75 SwitchTest( UNDEFINED, "UNDEFINED" );
76 SwitchTest( FALSE, "FALSE" );
77 SwitchTest( false, "false" );
80 SwitchTest ( TRUE, "TRUE" );
82 SwitchTest( ONE, "ONE" );
83 SwitchTest( true, "true" );
85 SwitchTest( "a", "a" );
87 SwitchTest( "b", "b" );
90 SwitchTest( new Boolean( true ), "default" );
91 SwitchTest( new Boolean(false ), "default" );
92 SwitchTest( new String( "A" ), "default" );
93 SwitchTest( new Number( 0 ), "default" );
97 function SwitchTest( input, expect ) {
101 default: result += "default"; break;
102 case "a": result += "a"; break;
103 case "b": result += "b"; break;
104 case A: result += "A"; break;
105 case B: result += "B"; break;
106 case new Boolean(true): result += "new TRUE"; break;
107 case new Boolean(false): result += "new FALSE"; break;
108 case NULL: result += "NULL"; break;
109 case UNDEFINED: result += "UNDEFINED"; break;
110 case true: result += "true"; break;
111 case false: result += "false"; break;
112 case TRUE: result += "TRUE"; break;
113 case FALSE: result += "FALSE"; break;
114 case 0: result += "0"; break;
115 case 1: result += "1"; break;
116 case new Number(0) : result += "new ZERO"; break;
117 case new Number(1) : result += "new ONE"; break;
118 case ONE: result += "ONE"; break;
119 case ZERO: result += "ZERO"; break;
124 "switch with no breaks: input is " + input,