tor-browser

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

regress-209919.js (3607B)


      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 *
      8 * Date:    19 June 2003
      9 * SUMMARY: Testing regexp submatches with quantifiers
     10 *
     11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=209919
     12 *
     13 */
     14 //-----------------------------------------------------------------------------
     15 var i = 0;
     16 var BUGNUMBER = 209919;
     17 var summary = 'Testing regexp submatches with quantifiers';
     18 var status = '';
     19 var statusmessages = new Array();
     20 var pattern = '';
     21 var patterns = new Array();
     22 var string = '';
     23 var strings = new Array();
     24 var actualmatch = '';
     25 var actualmatches = new Array();
     26 var expectedmatch = '';
     27 var expectedmatches = new Array();
     28 
     29 
     30 /*
     31 * Waldemar: "ECMA-262 15.10.2.5, third algorithm, step 2.1 states that
     32 * once the minimum repeat count (which is 0 for *, 1 for +, etc.) has
     33 * been satisfied, an atom being repeated must not match the empty string."
     34 *
     35 * In this example, the minimum repeat count is 0, so the last thing the
     36 * capturing parens is permitted to contain is the 'a'. It may NOT go on
     37 * to capture the '' at the $ position of 'a', even though '' satifies
     38 * the condition b*
     39 *
     40 */
     41 status = inSection(1);
     42 string = 'a';
     43 pattern = /(a|b*)*/;
     44 actualmatch = string.match(pattern);
     45 expectedmatch = Array(string, 'a');
     46 addThis();
     47 
     48 
     49 /*
     50 * In this example, the minimum repeat count is 5, so the capturing parens
     51 * captures the 'a', then goes on to capture the '' at the $ position of 'a'
     52 * 4 times before it has to stop. Therefore the last thing it contains is ''.
     53 */
     54 status = inSection(2);
     55 string = 'a';
     56 pattern = /(a|b*){5,}/;
     57 actualmatch = string.match(pattern);
     58 expectedmatch = Array(string, '');
     59 addThis();
     60 
     61 
     62 /*
     63 * Reduction of the above examples to contain only the condition b*
     64 * inside the capturing parens. This can be even harder to grasp!
     65 *
     66 * The global match is the '' at the ^ position of 'a', but the parens
     67 * is NOT permitted to capture it since the minimum repeat count is 0!
     68 */
     69 status = inSection(3);
     70 string = 'a';
     71 pattern = /(b*)*/;
     72 actualmatch = string.match(pattern);
     73 expectedmatch = Array('', undefined);
     74 addThis();
     75 
     76 
     77 /*
     78 * Here we have used the + quantifier (repeat count 1) outside the parens.
     79 * Therefore the parens must capture at least once before stopping, so it
     80 * does capture the '' this time -
     81 */
     82 status = inSection(4);
     83 string = 'a';
     84 pattern = /(b*)+/;
     85 actualmatch = string.match(pattern);
     86 expectedmatch = Array('', '');
     87 addThis();
     88 
     89 
     90 /*
     91 * More complex examples -
     92 */
     93 pattern = /^\-?(\d{1,}|\.{0,})*(\,\d{1,})?$/;
     94 
     95 status = inSection(5);
     96 string = '100.00';
     97 actualmatch = string.match(pattern);
     98 expectedmatch = Array(string, '00', undefined);
     99 addThis();
    100 
    101 status = inSection(6);
    102 string = '100,00';
    103 actualmatch = string.match(pattern);
    104 expectedmatch = Array(string, '100', ',00');
    105 addThis();
    106 
    107 status = inSection(7);
    108 string = '1.000,00';
    109 actualmatch = string.match(pattern);
    110 expectedmatch = Array(string, '000', ',00');
    111 addThis();
    112 
    113 
    114 
    115 
    116 //-----------------------------------------------------------------------------
    117 test();
    118 //-----------------------------------------------------------------------------
    119 
    120 
    121 
    122 function addThis()
    123 {
    124  statusmessages[i] = status;
    125  patterns[i] = pattern;
    126  strings[i] = string;
    127  actualmatches[i] = actualmatch;
    128  expectedmatches[i] = expectedmatch;
    129  i++;
    130 }
    131 
    132 
    133 function test()
    134 {
    135  printBugNumber(BUGNUMBER);
    136  printStatus (summary);
    137  testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
    138 }