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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
     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 = [];
    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+)/;
    33 // try the numeric literal 15
    34 status = inSection(1);
    35 actual  = str.replace (re, "$1" + 15);
    36 expect = 'uid=15';
    37 addThis();
    39 // try the string literal '15'
    40 status = inSection(2);
    41 actual  = str.replace (re, "$1" + '15');
    42 expect = 'uid=15';
    43 addThis();
    45 // try a letter before the '15'
    46 status = inSection(3);
    47 actual  = str.replace (re, "$1" + 'A15');
    48 expect = 'uid=A15';
    49 addThis();
    53 //-----------------------------------------------------------------------------
    54 test();
    55 //-----------------------------------------------------------------------------
    59 function addThis()
    60 {
    61   statusitems[UBound] = status;
    62   actualvalues[UBound] = actual;
    63   expectedvalues[UBound] = expect;
    64   UBound++;
    65 }
    68 function test()
    69 {
    70   enterFunc ('test');
    71   printBugNumber(BUGNUMBER);
    72   printStatus (summary);
    74   for (var i=0; i<UBound; i++)
    75   {
    76     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
    77   }
    79   exitFunc ('test');
    80 }

mercurial