1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/Statements/switch-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 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-001.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-001"; 1.22 +var VERSION = "ECMA_2"; 1.23 +var TITLE = "The switch statement"; 1.24 + 1.25 +var BUGNUMBER="315767"; 1.26 + 1.27 +startTest(); 1.28 +writeHeaderToLog( SECTION + " "+ TITLE); 1.29 + 1.30 +SwitchTest( 0, 126 ); 1.31 +SwitchTest( 1, 124 ); 1.32 +SwitchTest( 2, 120 ); 1.33 +SwitchTest( 3, 112 ); 1.34 +SwitchTest( 4, 64 ); 1.35 +SwitchTest( 5, 96 ); 1.36 +SwitchTest( true, 96 ); 1.37 +SwitchTest( false, 96 ); 1.38 +SwitchTest( null, 96 ); 1.39 +SwitchTest( void 0, 96 ); 1.40 +SwitchTest( "0", 96 ); 1.41 + 1.42 +test(); 1.43 + 1.44 +function SwitchTest( input, expect ) { 1.45 + var result = 0; 1.46 + 1.47 + switch ( input ) { 1.48 + case 0: 1.49 + result += 2; 1.50 + case 1: 1.51 + result += 4; 1.52 + case 2: 1.53 + result += 8; 1.54 + case 3: 1.55 + result += 16; 1.56 + default: 1.57 + result += 32; 1.58 + case 4: 1.59 + result +=64; 1.60 + } 1.61 + 1.62 + new TestCase( 1.63 + SECTION, 1.64 + "switch with no breaks, case expressions are numbers. input is "+ 1.65 + input, 1.66 + expect, 1.67 + result ); 1.68 +}