js/src/tests/ecma_3/RegExp/regress-216591.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-216591.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     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 + *
    1.11 + * Date:    19 August 2003
    1.12 + * SUMMARY: Regexp conformance test
    1.13 + *
    1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=216591
    1.15 + *
    1.16 + */
    1.17 +//-----------------------------------------------------------------------------
    1.18 +var i = 0;
    1.19 +var BUGNUMBER = 216591;
    1.20 +var summary = 'Regexp conformance test';
    1.21 +var status = '';
    1.22 +var statusmessages = new Array();
    1.23 +var pattern = '';
    1.24 +var patterns = new Array();
    1.25 +var string = '';
    1.26 +var strings = new Array();
    1.27 +var actualmatch = '';
    1.28 +var actualmatches = new Array();
    1.29 +var expectedmatch = '';
    1.30 +var expectedmatches = new Array();
    1.31 +
    1.32 +
    1.33 +status = inSection(1);
    1.34 +string = 'a {result.data.DATA} b';
    1.35 +pattern = /\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}/i;
    1.36 +actualmatch = string.match(pattern);
    1.37 +expectedmatch = Array('{result.data.DATA}', 'result.data.', 'data.', 'DATA');
    1.38 +addThis();
    1.39 +
    1.40 +/*
    1.41 + * Add a global flag to the regexp. In Perl 5, this gives the same results as above. Compare:
    1.42 + *
    1.43 + * [ ] perl -e '"a {result.data.DATA} b" =~ /\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}/i;  print("$&, $1, $2, $3");'
    1.44 + * {result.data.DATA}, result.data., data., DATA
    1.45 + *
    1.46 + * [ ] perl -e '"a {result.data.DATA} b" =~ /\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}/gi; print("$&, $1, $2, $3");'
    1.47 + * {result.data.DATA}, result.data., data., DATA
    1.48 + *
    1.49 + *
    1.50 + * But in JavaScript, there will no longer be any sub-captures:
    1.51 + */
    1.52 +status = inSection(2);
    1.53 +string = 'a {result.data.DATA} b';
    1.54 +pattern = /\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}/gi;
    1.55 +actualmatch = string.match(pattern);
    1.56 +expectedmatch = Array('{result.data.DATA}');
    1.57 +addThis();
    1.58 +
    1.59 +
    1.60 +
    1.61 +
    1.62 +//-----------------------------------------------------------------------------
    1.63 +test();
    1.64 +//-----------------------------------------------------------------------------
    1.65 +
    1.66 +
    1.67 +
    1.68 +function addThis()
    1.69 +{
    1.70 +  statusmessages[i] = status;
    1.71 +  patterns[i] = pattern;
    1.72 +  strings[i] = string;
    1.73 +  actualmatches[i] = actualmatch;
    1.74 +  expectedmatches[i] = expectedmatch;
    1.75 +  i++;
    1.76 +}
    1.77 +
    1.78 +
    1.79 +function test()
    1.80 +{
    1.81 +  enterFunc ('test');
    1.82 +  printBugNumber(BUGNUMBER);
    1.83 +  printStatus (summary);
    1.84 +  testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
    1.85 +  exitFunc ('test');
    1.86 +}

mercurial