js/src/tests/ecma_3/RegExp/regress-57572.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-57572.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     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: 28 December 2000
    1.11 + *
    1.12 + * SUMMARY: Testing regular expressions containing the ? character.
    1.13 + * Arose from Bugzilla bug 57572: "RegExp with ? matches incorrectly"
    1.14 + *
    1.15 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=57572
    1.16 + *
    1.17 + */
    1.18 +//-----------------------------------------------------------------------------
    1.19 +var i = 0;
    1.20 +var BUGNUMBER = 57572;
    1.21 +var summary = 'Testing regular expressions containing "?"';
    1.22 +var cnEmptyString = ''; var cnSingleSpace = ' ';
    1.23 +var status = '';
    1.24 +var statusmessages = new Array();
    1.25 +var pattern = '';
    1.26 +var patterns = new Array();
    1.27 +var string = '';
    1.28 +var strings = new Array();
    1.29 +var actualmatch = '';
    1.30 +var actualmatches = new Array();
    1.31 +var expectedmatch = '';
    1.32 +var expectedmatches = new Array();
    1.33 +
    1.34 +
    1.35 +status = inSection(1);
    1.36 +pattern = /(\S+)?(.*)/;
    1.37 +string = 'Test this';
    1.38 +actualmatch = string.match(pattern);
    1.39 +expectedmatch = Array(string, 'Test', ' this');  //single space in front of 'this'
    1.40 +addThis();
    1.41 +
    1.42 +status = inSection(2);
    1.43 +pattern = /(\S+)? ?(.*)/;  //single space between the ? characters
    1.44 +string= 'Test this';
    1.45 +actualmatch = string.match(pattern);
    1.46 +expectedmatch = Array(string, 'Test', 'this');  //NO space in front of 'this'
    1.47 +addThis();
    1.48 +
    1.49 +status = inSection(3);
    1.50 +pattern = /(\S+)?(.*)/;
    1.51 +string = 'Stupid phrase, with six - (short) words';
    1.52 +actualmatch = string.match(pattern);
    1.53 +expectedmatch = Array(string, 'Stupid', ' phrase, with six - (short) words');  //single space in front of 'phrase'
    1.54 +addThis();
    1.55 +
    1.56 +status = inSection(4);
    1.57 +pattern = /(\S+)? ?(.*)/;  //single space between the ? characters
    1.58 +string = 'Stupid phrase, with six - (short) words';
    1.59 +actualmatch = string.match(pattern);
    1.60 +expectedmatch = Array(string, 'Stupid', 'phrase, with six - (short) words');  //NO space in front of 'phrase'
    1.61 +addThis();
    1.62 +
    1.63 +
    1.64 +// let's add an extra back-reference this time - three instead of two -
    1.65 +status = inSection(5);
    1.66 +pattern = /(\S+)?( ?)(.*)/;  //single space before second ? character
    1.67 +string = 'Stupid phrase, with six - (short) words';
    1.68 +actualmatch = string.match(pattern);
    1.69 +expectedmatch = Array(string, 'Stupid', cnSingleSpace, 'phrase, with six - (short) words');
    1.70 +addThis();
    1.71 +
    1.72 +status = inSection(6);
    1.73 +pattern = /^(\S+)?( ?)(B+)$/;  //single space before second ? character
    1.74 +string = 'AAABBB';
    1.75 +actualmatch = string.match(pattern);
    1.76 +expectedmatch = Array(string, 'AAABB', cnEmptyString, 'B');
    1.77 +addThis();
    1.78 +
    1.79 +status = inSection(7);
    1.80 +pattern = /(\S+)?(!?)(.*)/;
    1.81 +string = 'WOW !!! !!!';
    1.82 +actualmatch = string.match(pattern);
    1.83 +expectedmatch = Array(string, 'WOW', cnEmptyString, ' !!! !!!');
    1.84 +addThis();
    1.85 +
    1.86 +status = inSection(8);
    1.87 +pattern = /(.+)?(!?)(!+)/;
    1.88 +string = 'WOW !!! !!!';
    1.89 +actualmatch = string.match(pattern);
    1.90 +expectedmatch = Array(string, 'WOW !!! !!', cnEmptyString, '!');
    1.91 +addThis();
    1.92 +
    1.93 +
    1.94 +
    1.95 +//-----------------------------------------------------------------------------
    1.96 +test();
    1.97 +//-----------------------------------------------------------------------------
    1.98 +
    1.99 +
   1.100 +
   1.101 +function addThis()
   1.102 +{
   1.103 +  statusmessages[i] = status;
   1.104 +  patterns[i] = pattern;
   1.105 +  strings[i] = string;
   1.106 +  actualmatches[i] = actualmatch;
   1.107 +  expectedmatches[i] = expectedmatch;
   1.108 +  i++;
   1.109 +}
   1.110 +
   1.111 +
   1.112 +function test()
   1.113 +{
   1.114 +  enterFunc ('test');
   1.115 +  printBugNumber(BUGNUMBER);
   1.116 +  printStatus (summary);
   1.117 +  testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
   1.118 +  exitFunc ('test');
   1.119 +}

mercurial