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@gmx.net, pschwartau@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//-----------------------------------------------------------------------------
26var UBound = 0;
27var bug = 104375;
28var summary = 'Testing string.replace() with backreferences';
29var status = '';
30var statusitems = [];
31var actual = '';
32var actualvalues = [];
33var expect= '';
34var 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 */
43var str = 'uid=31';
44var re = /(uid=)(\d+)/;
45
46// try the numeric literal 15
47status = inSection(1);
48actual  = str.replace (re, "$1" + 15);
49expect = 'uid=15';
50addThis();
51
52// try the string literal '15'
53status = inSection(2);
54actual  = str.replace (re, "$1" + '15');
55expect = 'uid=15';
56addThis();
57
58// try a letter before the '15'
59status = inSection(3);
60actual  = str.replace (re, "$1" + 'A15');
61expect = 'uid=A15';
62addThis();
63
64
65
66//-----------------------------------------------------------------------------
67test();
68//-----------------------------------------------------------------------------
69
70
71
72function addThis()
73{
74  statusitems[UBound] = status;
75  actualvalues[UBound] = actual;
76  expectedvalues[UBound] = expect;
77  UBound++;
78}
79
80
81function 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