js/src/tests/ecma_2/Statements/switch-004.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_2/Statements/switch-004.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     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-003.js
    1.12 + *  ECMA Section:
    1.13 + *  Description:        The switch Statement
    1.14 + *
    1.15 + *  This uses variables and objects as case expressions in switch statements.
    1.16 + * This verifies a bunch of bugs:
    1.17 + *
    1.18 + * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315988
    1.19 + * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315975
    1.20 + * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315954
    1.21 + *
    1.22 + *  Author:             christine@netscape.com
    1.23 + *  Date:               11 August 1998
    1.24 + *
    1.25 + */
    1.26 +var SECTION = "switch-003";
    1.27 +var VERSION = "ECMA_2";
    1.28 +var TITLE   = "The switch statement";
    1.29 +var BUGNUMBER= "315988";
    1.30 +
    1.31 +startTest();
    1.32 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.33 +
    1.34 +ONE = new Number(1);
    1.35 +ZERO = new Number(0);
    1.36 +var A = new String("A");
    1.37 +var B = new String("B");
    1.38 +TRUE = new Boolean( true );
    1.39 +FALSE = new Boolean( false );
    1.40 +UNDEFINED  = void 0;
    1.41 +NULL = null;
    1.42 +
    1.43 +SwitchTest( ZERO, "ZERO" );
    1.44 +SwitchTest( NULL, "NULL" );
    1.45 +SwitchTest( UNDEFINED, "UNDEFINED" );
    1.46 +SwitchTest( FALSE, "FALSE" );
    1.47 +SwitchTest( false,  "false" );
    1.48 +SwitchTest( 0,      "0" );
    1.49 +
    1.50 +SwitchTest ( TRUE, "TRUE" );
    1.51 +SwitchTest( 1,     "1" );
    1.52 +SwitchTest( ONE,   "ONE" );
    1.53 +SwitchTest( true,  "true" );
    1.54 +
    1.55 +SwitchTest( "a",   "a" );
    1.56 +SwitchTest( A,     "A" );
    1.57 +SwitchTest( "b",   "b" );
    1.58 +SwitchTest( B,     "B" );
    1.59 +
    1.60 +SwitchTest( new Boolean( true ), "default" );
    1.61 +SwitchTest( new Boolean(false ), "default" );
    1.62 +SwitchTest( new String( "A" ),   "default" );
    1.63 +SwitchTest( new Number( 0 ),     "default" );
    1.64 +
    1.65 +test();
    1.66 +
    1.67 +function SwitchTest( input, expect ) {
    1.68 +  var result = "";
    1.69 +
    1.70 +  switch ( input ) {
    1.71 +  default:   result += "default"; break;
    1.72 +  case "a":  result += "a";       break;
    1.73 +  case "b":  result += "b";       break;
    1.74 +  case A:    result += "A";       break;
    1.75 +  case B:    result += "B";       break;
    1.76 +  case new Boolean(true): result += "new TRUE";   break;
    1.77 +  case new Boolean(false): result += "new FALSE"; break;
    1.78 +  case NULL: result += "NULL";    break;
    1.79 +  case UNDEFINED: result += "UNDEFINED"; break;
    1.80 +  case true: result += "true";    break;
    1.81 +  case false: result += "false";  break;
    1.82 +  case TRUE:  result += "TRUE";   break;
    1.83 +  case FALSE: result += "FALSE";  break;
    1.84 +  case 0:    result += "0";       break;
    1.85 +  case 1:    result += "1";       break;
    1.86 +  case new Number(0) : result += "new ZERO";  break;
    1.87 +  case new Number(1) : result += "new ONE";   break;
    1.88 +  case ONE:  result += "ONE";     break;
    1.89 +  case ZERO: result += "ZERO";    break;
    1.90 +  }
    1.91 +
    1.92 +  new TestCase(
    1.93 +    SECTION,
    1.94 +    "switch with no breaks:  input is " + input,
    1.95 +    expect,
    1.96 +    result );
    1.97 +}

mercurial