js/src/tests/ecma_3/String/regress-104375.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/String/regress-104375.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,82 @@
     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: 12 October 2001
    1.11 + *
    1.12 + * SUMMARY: Regression test for string.replace bug 104375
    1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=104375
    1.14 + */
    1.15 +//-----------------------------------------------------------------------------
    1.16 +var UBound = 0;
    1.17 +var BUGNUMBER = 104375;
    1.18 +var summary = 'Testing string.replace() with backreferences';
    1.19 +var status = '';
    1.20 +var statusitems = [];
    1.21 +var actual = '';
    1.22 +var actualvalues = [];
    1.23 +var expect= '';
    1.24 +var expectedvalues = [];
    1.25 +
    1.26 +
    1.27 +/*
    1.28 + * Use the regexp to replace 'uid=31' with 'uid=15'
    1.29 + *
    1.30 + * In the second parameter of string.replace() method,
    1.31 + * "$1" refers to the first backreference: 'uid='
    1.32 + */
    1.33 +var str = 'uid=31';
    1.34 +var re = /(uid=)(\d+)/;
    1.35 +
    1.36 +// try the numeric literal 15
    1.37 +status = inSection(1);
    1.38 +actual  = str.replace (re, "$1" + 15);
    1.39 +expect = 'uid=15';
    1.40 +addThis();
    1.41 +
    1.42 +// try the string literal '15'
    1.43 +status = inSection(2);
    1.44 +actual  = str.replace (re, "$1" + '15');
    1.45 +expect = 'uid=15';
    1.46 +addThis();
    1.47 +
    1.48 +// try a letter before the '15'
    1.49 +status = inSection(3);
    1.50 +actual  = str.replace (re, "$1" + 'A15');
    1.51 +expect = 'uid=A15';
    1.52 +addThis();
    1.53 +
    1.54 +
    1.55 +
    1.56 +//-----------------------------------------------------------------------------
    1.57 +test();
    1.58 +//-----------------------------------------------------------------------------
    1.59 +
    1.60 +
    1.61 +
    1.62 +function addThis()
    1.63 +{
    1.64 +  statusitems[UBound] = status;
    1.65 +  actualvalues[UBound] = actual;
    1.66 +  expectedvalues[UBound] = expect;
    1.67 +  UBound++;
    1.68 +}
    1.69 +
    1.70 +
    1.71 +function test()
    1.72 +{
    1.73 +  enterFunc ('test');
    1.74 +  printBugNumber(BUGNUMBER);
    1.75 +  printStatus (summary);
    1.76 +
    1.77 +  for (var i=0; i<UBound; i++)
    1.78 +  {
    1.79 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    1.80 +  }
    1.81 +
    1.82 +  exitFunc ('test');
    1.83 +}
    1.84 +
    1.85 +

mercurial