1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/Statements/switch-002.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + * File Name: switch-002.js 1.12 + * ECMA Section: 1.13 + * Description: The switch Statement 1.14 + * 1.15 + * A simple switch test with no abrupt completions. 1.16 + * 1.17 + * Author: christine@netscape.com 1.18 + * Date: 11 August 1998 1.19 + * 1.20 + */ 1.21 +var SECTION = "switch-002"; 1.22 +var VERSION = "ECMA_2"; 1.23 +var TITLE = "The switch statement"; 1.24 + 1.25 +startTest(); 1.26 +writeHeaderToLog( SECTION + " "+ TITLE); 1.27 + 1.28 +SwitchTest( 0, 6 ); 1.29 +SwitchTest( 1, 4 ); 1.30 +SwitchTest( 2, 56 ); 1.31 +SwitchTest( 3, 48 ); 1.32 +SwitchTest( 4, 64 ); 1.33 +SwitchTest( true, 32 ); 1.34 +SwitchTest( false, 32 ); 1.35 +SwitchTest( null, 32 ); 1.36 +SwitchTest( void 0, 32 ); 1.37 +SwitchTest( "0", 32 ); 1.38 + 1.39 +test(); 1.40 + 1.41 +function SwitchTest( input, expect ) { 1.42 + var result = 0; 1.43 + 1.44 + switch ( input ) { 1.45 + case 0: 1.46 + result += 2; 1.47 + case 1: 1.48 + result += 4; 1.49 + break; 1.50 + case 2: 1.51 + result += 8; 1.52 + case 3: 1.53 + result += 16; 1.54 + default: 1.55 + result += 32; 1.56 + break; 1.57 + case 4: 1.58 + result += 64; 1.59 + } 1.60 + 1.61 + new TestCase( 1.62 + SECTION, 1.63 + "switch with no breaks: input is " + input, 1.64 + expect, 1.65 + result ); 1.66 +}