tor-browser

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

regress-216591.js (2278B)


      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 August 2003
      9 * SUMMARY: Regexp conformance test
     10 *
     11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=216591
     12 *
     13 */
     14 //-----------------------------------------------------------------------------
     15 var i = 0;
     16 var BUGNUMBER = 216591;
     17 var summary = 'Regexp conformance test';
     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 status = inSection(1);
     31 string = 'a {result.data.DATA} b';
     32 pattern = /\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}/i;
     33 actualmatch = string.match(pattern);
     34 expectedmatch = Array('{result.data.DATA}', 'result.data.', 'data.', 'DATA');
     35 addThis();
     36 
     37 /*
     38 * Add a global flag to the regexp. In Perl 5, this gives the same results as above. Compare:
     39 *
     40 * [ ] perl -e '"a {result.data.DATA} b" =~ /\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}/i;  print("$&, $1, $2, $3");'
     41 * {result.data.DATA}, result.data., data., DATA
     42 *
     43 * [ ] perl -e '"a {result.data.DATA} b" =~ /\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}/gi; print("$&, $1, $2, $3");'
     44 * {result.data.DATA}, result.data., data., DATA
     45 *
     46 *
     47 * But in JavaScript, there will no longer be any sub-captures:
     48 */
     49 status = inSection(2);
     50 string = 'a {result.data.DATA} b';
     51 pattern = /\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}/gi;
     52 actualmatch = string.match(pattern);
     53 expectedmatch = Array('{result.data.DATA}');
     54 addThis();
     55 
     56 
     57 
     58 
     59 //-----------------------------------------------------------------------------
     60 test();
     61 //-----------------------------------------------------------------------------
     62 
     63 
     64 
     65 function addThis()
     66 {
     67  statusmessages[i] = status;
     68  patterns[i] = pattern;
     69  strings[i] = string;
     70  actualmatches[i] = actualmatch;
     71  expectedmatches[i] = expectedmatch;
     72  i++;
     73 }
     74 
     75 
     76 function test()
     77 {
     78  printBugNumber(BUGNUMBER);
     79  printStatus (summary);
     80  testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
     81 }