1 /* 2 * The contents of this file are subject to the Netscape Public 3 * License Version 1.1 (the "License"); you may not use this file 4 * except in compliance with the License. You may obtain a copy of 5 * the License at http://www.mozilla.org/NPL/ 6 * 7 * Software distributed under the License is distributed on an "AS IS" 8 * basis, WITHOUT WARRANTY OF ANY KIND, either expressed 9 * or implied. See the License for the specific language governing 10 * rights and limitations under the License. 11 * 12 * The Original Code is mozilla.org code. 13 * 14 * The Initial Developer of the Original Code is Netscape 15 * Communications Corporation. Portions created by Netscape are 16 * Copyright (C) 1998 Netscape Communications Corporation. All 17 * Rights Reserved. 18 * 19 * Contributor(s): pschwartau (at) netscape.com 20 * Date: 01 May 2001 21 * 22 * SUMMARY: Regression test for Bugzilla bug 74474 23 *"switch() misbehaves with duplicated labels" 24 * 25 * See ECMA3 Section 12.11, "The switch Statement" 26 * See http://bugzilla.mozilla.org/show_bug.cgi?id=74474 27 */ 28 //------------------------------------------------------------------------------------------------- 29 var UBound = 0; 30 var bug = 74474; 31 var summary = 'Testing switch statements with duplicate labels'; 32 var status = ''; 33 var statusitems = [ ]; 34 var actual = ''; 35 var actualvalues = [ ]; 36 var expect= ''; 37 var expectedvalues = [ ]; 38 39 40 status = 'Section A of test: the string literal "1" as a duplicate label'; 41 actual = ''; 42 switch ('1') 43 { 44 case '1': 45 actual += 'a'; 46 case '1': 47 actual += 'b'; 48 } 49 expect = 'ab'; 50 addThis(); 51 52 53 status = 'Section B of test: the numeric literal 1 as a duplicate label'; 54 actual = ''; 55 switch (1) 56 { 57 case 1: 58 actual += 'a'; 59 case 1: 60 actual += 'b'; 61 } 62 expect = 'ab'; 63 addThis(); 64 65 66 status = 'Section C of test: the numeric literal 1 as a duplicate label, via a function parameter'; 67 tryThis(1); 68 function tryThis(x) 69 { 70 actual = ''; 71 72 switch (x) 73 { 74 case x: 75 actual += 'a'; 76 case x: 77 actual += 'b'; 78 } 79 } 80 expect = 'ab'; 81 addThis(); 82 83 84 85 //--------------------------------------------------------------------------------- 86 test(); 87 //--------------------------------------------------------------------------------- 88 89 90 91 function addThis() 92 { 93 statusitems[UBound] = status; 94 actualvalues[UBound] = actual; 95 expectedvalues[UBound] = expect; 96 UBound++; 97 } 98 99 100 function test() 101 { 102 enterFunc ('test'); 103 printBugNumber (bug); 104 printStatus (summary); 105 106 for (var i = 0; i < UBound; i++) 107 { 108 reportCompare(expectedvalues[i], actualvalues[i], getStatus(i)); 109 } 110 111 exitFunc ('test'); 112 } 113 114 115 function getStatus(i) 116 { 117 return statusitems[i]; 118 } 119