1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/Statements/regress-74474-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 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 + * Date: 01 May 2001 1.11 + * 1.12 + * SUMMARY: Regression test for Bugzilla bug 74474 1.13 + *"switch() misbehaves with duplicated labels" 1.14 + * 1.15 + * See ECMA3 Section 12.11, "The switch Statement" 1.16 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=74474 1.17 + */ 1.18 +//----------------------------------------------------------------------------- 1.19 +var UBound = 0; 1.20 +var BUGNUMBER = 74474; 1.21 +var summary = 'Testing switch statements with duplicate labels'; 1.22 +var status = ''; 1.23 +var statusitems = [ ]; 1.24 +var actual = ''; 1.25 +var actualvalues = [ ]; 1.26 +var expect= ''; 1.27 +var expectedvalues = [ ]; 1.28 + 1.29 + 1.30 +status = 'Section A of test: the string literal "1" as a duplicate label'; 1.31 +actual = ''; 1.32 +switch ('1') 1.33 +{ 1.34 +case '1': 1.35 + actual += 'a'; 1.36 +case '1': 1.37 + actual += 'b'; 1.38 +} 1.39 +expect = 'ab'; 1.40 +addThis(); 1.41 + 1.42 + 1.43 +status = 'Section B of test: the numeric literal 1 as a duplicate label'; 1.44 +actual = ''; 1.45 +switch (1) 1.46 +{ 1.47 +case 1: 1.48 + actual += 'a'; 1.49 +case 1: 1.50 + actual += 'b'; 1.51 +} 1.52 +expect = 'ab'; 1.53 +addThis(); 1.54 + 1.55 + 1.56 +status = 'Section C of test: the numeric literal 1 as a duplicate label, via a function parameter'; 1.57 +tryThis(1); 1.58 +function tryThis(x) 1.59 +{ 1.60 + actual = ''; 1.61 + 1.62 + switch (x) 1.63 + { 1.64 + case x: 1.65 + actual += 'a'; 1.66 + case x: 1.67 + actual += 'b'; 1.68 + } 1.69 +} 1.70 +expect = 'ab'; 1.71 +addThis(); 1.72 + 1.73 + 1.74 + 1.75 +//--------------------------------------------------------------------------------- 1.76 +test(); 1.77 +//--------------------------------------------------------------------------------- 1.78 + 1.79 + 1.80 + 1.81 +function addThis() 1.82 +{ 1.83 + statusitems[UBound] = status; 1.84 + actualvalues[UBound] = actual; 1.85 + expectedvalues[UBound] = expect; 1.86 + UBound++; 1.87 +} 1.88 + 1.89 + 1.90 +function test() 1.91 +{ 1.92 + enterFunc ('test'); 1.93 + printBugNumber(BUGNUMBER); 1.94 + printStatus (summary); 1.95 + 1.96 + for (var i = 0; i < UBound; i++) 1.97 + { 1.98 + reportCompare(expectedvalues[i], actualvalues[i], getStatus(i)); 1.99 + } 1.100 + 1.101 + exitFunc ('test'); 1.102 +} 1.103 + 1.104 + 1.105 +function getStatus(i) 1.106 +{ 1.107 + return statusitems[i]; 1.108 +}