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 8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 9 * 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. 17 * All Rights Reserved. 18 * 19 * Contributor(s): k.mike (at) gmx.net, pschwartau (at) netscape.com 20 * Date: 12 October 2001 21 * 22 * SUMMARY: Regression test for string.replace bug 104375 23 * See http://bugzilla.mozilla.org/show_bug.cgi?id=104375 24 */ 25 //----------------------------------------------------------------------------- 26 var UBound = 0; 27 var bug = 104375; 28 var summary = 'Testing string.replace() with backreferences'; 29 var status = ''; 30 var statusitems = []; 31 var actual = ''; 32 var actualvalues = []; 33 var expect= ''; 34 var expectedvalues = []; 35 36 37 /* 38 * Use the regexp to replace 'uid=31' with 'uid=15' 39 * 40 * In the second parameter of string.replace() method, 41 * "$1" refers to the first backreference: 'uid=' 42 */ 43 var str = 'uid=31'; 44 var re = /(uid=)(\d+)/; 45 46 // try the numeric literal 15 47 status = inSection(1); 48 actual = str.replace (re, "$1" + 15); 49 expect = 'uid=15'; 50 addThis(); 51 52 // try the string literal '15' 53 status = inSection(2); 54 actual = str.replace (re, "$1" + '15'); 55 expect = 'uid=15'; 56 addThis(); 57 58 // try a letter before the '15' 59 status = inSection(3); 60 actual = str.replace (re, "$1" + 'A15'); 61 expect = 'uid=A15'; 62 addThis(); 63 64 65 66 //----------------------------------------------------------------------------- 67 test(); 68 //----------------------------------------------------------------------------- 69 70 71 72 function addThis() 73 { 74 statusitems[UBound] = status; 75 actualvalues[UBound] = actual; 76 expectedvalues[UBound] = expect; 77 UBound++; 78 } 79 80 81 function test() 82 { 83 enterFunc ('test'); 84 printBugNumber (bug); 85 printStatus (summary); 86 87 for (var i=0; i<UBound; i++) 88 { 89 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 90 } 91 92 exitFunc ('test'); 93 } 94 95 96