tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

regress-57572.js (3451B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
      5 
      6 /*
      7 * Date: 28 December 2000
      8 *
      9 * SUMMARY: Testing regular expressions containing the ? character.
     10 * Arose from Bugzilla bug 57572: "RegExp with ? matches incorrectly"
     11 *
     12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=57572
     13 *
     14 */
     15 //-----------------------------------------------------------------------------
     16 var i = 0;
     17 var BUGNUMBER = 57572;
     18 var summary = 'Testing regular expressions containing "?"';
     19 var cnEmptyString = ''; var cnSingleSpace = ' ';
     20 var status = '';
     21 var statusmessages = new Array();
     22 var pattern = '';
     23 var patterns = new Array();
     24 var string = '';
     25 var strings = new Array();
     26 var actualmatch = '';
     27 var actualmatches = new Array();
     28 var expectedmatch = '';
     29 var expectedmatches = new Array();
     30 
     31 
     32 status = inSection(1);
     33 pattern = /(\S+)?(.*)/;
     34 string = 'Test this';
     35 actualmatch = string.match(pattern);
     36 expectedmatch = Array(string, 'Test', ' this');  //single space in front of 'this'
     37 addThis();
     38 
     39 status = inSection(2);
     40 pattern = /(\S+)? ?(.*)/;  //single space between the ? characters
     41 string= 'Test this';
     42 actualmatch = string.match(pattern);
     43 expectedmatch = Array(string, 'Test', 'this');  //NO space in front of 'this'
     44 addThis();
     45 
     46 status = inSection(3);
     47 pattern = /(\S+)?(.*)/;
     48 string = 'Stupid phrase, with six - (short) words';
     49 actualmatch = string.match(pattern);
     50 expectedmatch = Array(string, 'Stupid', ' phrase, with six - (short) words');  //single space in front of 'phrase'
     51 addThis();
     52 
     53 status = inSection(4);
     54 pattern = /(\S+)? ?(.*)/;  //single space between the ? characters
     55 string = 'Stupid phrase, with six - (short) words';
     56 actualmatch = string.match(pattern);
     57 expectedmatch = Array(string, 'Stupid', 'phrase, with six - (short) words');  //NO space in front of 'phrase'
     58 addThis();
     59 
     60 
     61 // let's add an extra back-reference this time - three instead of two -
     62 status = inSection(5);
     63 pattern = /(\S+)?( ?)(.*)/;  //single space before second ? character
     64 string = 'Stupid phrase, with six - (short) words';
     65 actualmatch = string.match(pattern);
     66 expectedmatch = Array(string, 'Stupid', cnSingleSpace, 'phrase, with six - (short) words');
     67 addThis();
     68 
     69 status = inSection(6);
     70 pattern = /^(\S+)?( ?)(B+)$/;  //single space before second ? character
     71 string = 'AAABBB';
     72 actualmatch = string.match(pattern);
     73 expectedmatch = Array(string, 'AAABB', cnEmptyString, 'B');
     74 addThis();
     75 
     76 status = inSection(7);
     77 pattern = /(\S+)?(!?)(.*)/;
     78 string = 'WOW !!! !!!';
     79 actualmatch = string.match(pattern);
     80 expectedmatch = Array(string, 'WOW', cnEmptyString, ' !!! !!!');
     81 addThis();
     82 
     83 status = inSection(8);
     84 pattern = /(.+)?(!?)(!+)/;
     85 string = 'WOW !!! !!!';
     86 actualmatch = string.match(pattern);
     87 expectedmatch = Array(string, 'WOW !!! !!', cnEmptyString, '!');
     88 addThis();
     89 
     90 
     91 
     92 //-----------------------------------------------------------------------------
     93 test();
     94 //-----------------------------------------------------------------------------
     95 
     96 
     97 
     98 function addThis()
     99 {
    100  statusmessages[i] = status;
    101  patterns[i] = pattern;
    102  strings[i] = string;
    103  actualmatches[i] = actualmatch;
    104  expectedmatches[i] = expectedmatch;
    105  i++;
    106 }
    107 
    108 
    109 function test()
    110 {
    111  printBugNumber(BUGNUMBER);
    112  printStatus (summary);
    113  testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
    114 }