js/src/tests/ecma_3/RegExp/regress-87231.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/RegExp/regress-87231.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     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: 22 June 2001
    1.11 + *
    1.12 + * SUMMARY:  Regression test for Bugzilla bug 87231:
    1.13 + * "Regular expression /(A)?(A.*)/ picks 'A' twice"
    1.14 + *
    1.15 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=87231
    1.16 + * Key case:
    1.17 + *
    1.18 + *            pattern = /^(A)?(A.*)$/;
    1.19 + *            string = 'A';
    1.20 + *            expectedmatch = Array('A', '', 'A');
    1.21 + *
    1.22 + *
    1.23 + * We expect the 1st subexpression (A)? NOT to consume the single 'A'.
    1.24 + * Recall that "?" means "match 0 or 1 times". Here, it should NOT do
    1.25 + * greedy matching: it should match 0 times instead of 1. This allows
    1.26 + * the 2nd subexpression to make the only match it can: the single 'A'.
    1.27 + * Such "altruism" is the only way there can be a successful global match...
    1.28 + */
    1.29 +//-----------------------------------------------------------------------------
    1.30 +var i = 0;
    1.31 +var BUGNUMBER = 87231;
    1.32 +var cnEmptyString = '';
    1.33 +var summary = 'Testing regular expression /(A)?(A.*)/';
    1.34 +var status = '';
    1.35 +var statusmessages = new Array();
    1.36 +var pattern = '';
    1.37 +var patterns = new Array();
    1.38 +var string = '';
    1.39 +var strings = new Array();
    1.40 +var actualmatch = '';
    1.41 +var actualmatches = new Array();
    1.42 +var expectedmatch = '';
    1.43 +var expectedmatches = new Array();
    1.44 +
    1.45 +
    1.46 +pattern = /^(A)?(A.*)$/;
    1.47 +status = inSection(1);
    1.48 +string = 'AAA';
    1.49 +actualmatch = string.match(pattern);
    1.50 +expectedmatch = Array('AAA', 'A', 'AA');
    1.51 +addThis();
    1.52 +
    1.53 +status = inSection(2);
    1.54 +string = 'AA';
    1.55 +actualmatch = string.match(pattern);
    1.56 +expectedmatch = Array('AA', 'A', 'A');
    1.57 +addThis();
    1.58 +
    1.59 +status = inSection(3);
    1.60 +string = 'A';
    1.61 +actualmatch = string.match(pattern);
    1.62 +expectedmatch = Array('A', undefined, 'A'); // 'altruistic' case: see above
    1.63 +addThis();
    1.64 +
    1.65 +
    1.66 +pattern = /(A)?(A.*)/;
    1.67 +var strL = 'zxcasd;fl\\\  ^';
    1.68 +var strR = 'aaAAaaaf;lrlrzs';
    1.69 +
    1.70 +status = inSection(4);
    1.71 +string =  strL + 'AAA' + strR;
    1.72 +actualmatch = string.match(pattern);
    1.73 +expectedmatch = Array('AAA' + strR, 'A', 'AA' + strR);
    1.74 +addThis();
    1.75 +
    1.76 +status = inSection(5);
    1.77 +string =  strL + 'AA' + strR;
    1.78 +actualmatch = string.match(pattern);
    1.79 +expectedmatch = Array('AA' + strR, 'A', 'A' + strR);
    1.80 +addThis();
    1.81 +
    1.82 +status = inSection(6);
    1.83 +string =  strL + 'A' + strR;
    1.84 +actualmatch = string.match(pattern);
    1.85 +expectedmatch = Array('A' + strR, undefined, 'A' + strR); // 'altruistic' case: see above
    1.86 +addThis();
    1.87 +
    1.88 +
    1.89 +
    1.90 +//-------------------------------------------------------------------------------------------------
    1.91 +test();
    1.92 +//-------------------------------------------------------------------------------------------------
    1.93 +
    1.94 +
    1.95 +
    1.96 +function addThis()
    1.97 +{
    1.98 +  statusmessages[i] = status;
    1.99 +  patterns[i] = pattern;
   1.100 +  strings[i] = string;
   1.101 +  actualmatches[i] = actualmatch;
   1.102 +  expectedmatches[i] = expectedmatch;
   1.103 +  i++;
   1.104 +}
   1.105 +
   1.106 +
   1.107 +function test()
   1.108 +{
   1.109 +  enterFunc ('test');
   1.110 +  printBugNumber(BUGNUMBER);
   1.111 +  printStatus (summary);
   1.112 +  testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
   1.113 +  exitFunc ('test');
   1.114 +}

mercurial