michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: * File Name: switch-003.js michael@0: * ECMA Section: michael@0: * Description: The switch Statement michael@0: * michael@0: * This uses variables and objects as case expressions in switch statements. michael@0: * This verifies a bunch of bugs: michael@0: * michael@0: * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315988 michael@0: * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315975 michael@0: * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315954 michael@0: * michael@0: * Author: christine@netscape.com michael@0: * Date: 11 August 1998 michael@0: * michael@0: */ michael@0: var SECTION = "switch-003"; michael@0: var VERSION = "ECMA_2"; michael@0: var TITLE = "The switch statement"; michael@0: var BUGNUMBER= "315988"; michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: ONE = new Number(1); michael@0: ZERO = new Number(0); michael@0: var A = new String("A"); michael@0: var B = new String("B"); michael@0: TRUE = new Boolean( true ); michael@0: FALSE = new Boolean( false ); michael@0: UNDEFINED = void 0; michael@0: NULL = null; michael@0: michael@0: SwitchTest( ZERO, "ZERO" ); michael@0: SwitchTest( NULL, "NULL" ); michael@0: SwitchTest( UNDEFINED, "UNDEFINED" ); michael@0: SwitchTest( FALSE, "FALSE" ); michael@0: SwitchTest( false, "false" ); michael@0: SwitchTest( 0, "0" ); michael@0: michael@0: SwitchTest ( TRUE, "TRUE" ); michael@0: SwitchTest( 1, "1" ); michael@0: SwitchTest( ONE, "ONE" ); michael@0: SwitchTest( true, "true" ); michael@0: michael@0: SwitchTest( "a", "a" ); michael@0: SwitchTest( A, "A" ); michael@0: SwitchTest( "b", "b" ); michael@0: SwitchTest( B, "B" ); michael@0: michael@0: SwitchTest( new Boolean( true ), "default" ); michael@0: SwitchTest( new Boolean(false ), "default" ); michael@0: SwitchTest( new String( "A" ), "default" ); michael@0: SwitchTest( new Number( 0 ), "default" ); michael@0: michael@0: test(); michael@0: michael@0: function SwitchTest( input, expect ) { michael@0: var result = ""; michael@0: michael@0: switch ( input ) { michael@0: default: result += "default"; break; michael@0: case "a": result += "a"; break; michael@0: case "b": result += "b"; break; michael@0: case A: result += "A"; break; michael@0: case B: result += "B"; break; michael@0: case new Boolean(true): result += "new TRUE"; break; michael@0: case new Boolean(false): result += "new FALSE"; break; michael@0: case NULL: result += "NULL"; break; michael@0: case UNDEFINED: result += "UNDEFINED"; break; michael@0: case true: result += "true"; break; michael@0: case false: result += "false"; break; michael@0: case TRUE: result += "TRUE"; break; michael@0: case FALSE: result += "FALSE"; break; michael@0: case 0: result += "0"; break; michael@0: case 1: result += "1"; break; michael@0: case new Number(0) : result += "new ZERO"; break; michael@0: case new Number(1) : result += "new ONE"; break; michael@0: case ONE: result += "ONE"; break; michael@0: case ZERO: result += "ZERO"; break; michael@0: } michael@0: michael@0: new TestCase( michael@0: SECTION, michael@0: "switch with no breaks: input is " + input, michael@0: expect, michael@0: result ); michael@0: }