regress-104375.js (1804B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /* 7 * Date: 12 October 2001 8 * 9 * SUMMARY: Regression test for string.replace bug 104375 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=104375 11 */ 12 //----------------------------------------------------------------------------- 13 var UBound = 0; 14 var BUGNUMBER = 104375; 15 var summary = 'Testing string.replace() with backreferences'; 16 var status = ''; 17 var statusitems = []; 18 var actual = ''; 19 var actualvalues = []; 20 var expect= ''; 21 var expectedvalues = []; 22 23 24 /* 25 * Use the regexp to replace 'uid=31' with 'uid=15' 26 * 27 * In the second parameter of string.replace() method, 28 * "$1" refers to the first backreference: 'uid=' 29 */ 30 var str = 'uid=31'; 31 var re = /(uid=)(\d+)/; 32 33 // try the numeric literal 15 34 status = inSection(1); 35 actual = str.replace (re, "$1" + 15); 36 expect = 'uid=15'; 37 addThis(); 38 39 // try the string literal '15' 40 status = inSection(2); 41 actual = str.replace (re, "$1" + '15'); 42 expect = 'uid=15'; 43 addThis(); 44 45 // try a letter before the '15' 46 status = inSection(3); 47 actual = str.replace (re, "$1" + 'A15'); 48 expect = 'uid=A15'; 49 addThis(); 50 51 52 53 //----------------------------------------------------------------------------- 54 test(); 55 //----------------------------------------------------------------------------- 56 57 58 59 function addThis() 60 { 61 statusitems[UBound] = status; 62 actualvalues[UBound] = actual; 63 expectedvalues[UBound] = expect; 64 UBound++; 65 } 66 67 68 function test() 69 { 70 printBugNumber(BUGNUMBER); 71 printStatus (summary); 72 73 for (var i=0; i<UBound; i++) 74 { 75 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 76 } 77 }