js/src/tests/ecma_3/RegExp/15.10.2-1.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/15.10.2-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,147 @@
     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:    09 July 2002
    1.12 + * SUMMARY: RegExp conformance test
    1.13 + *
    1.14 + *   These testcases are derived from the examples in the ECMA-262 Ed.3 spec
    1.15 + *   scattered through section 15.10.2.
    1.16 + *
    1.17 + */
    1.18 +//-----------------------------------------------------------------------------
    1.19 +var i = 0;
    1.20 +var BUGNUMBER = '(none)';
    1.21 +var summary = 'RegExp conformance test';
    1.22 +var status = '';
    1.23 +var statusmessages = new Array();
    1.24 +var pattern = '';
    1.25 +var patterns = new Array();
    1.26 +var string = '';
    1.27 +var strings = new Array();
    1.28 +var actualmatch = '';
    1.29 +var actualmatches = new Array();
    1.30 +var expectedmatch = '';
    1.31 +var expectedmatches = new Array();
    1.32 +
    1.33 +
    1.34 +status = inSection(1);
    1.35 +pattern = /a|ab/;
    1.36 +string = 'abc';
    1.37 +actualmatch = string.match(pattern);
    1.38 +expectedmatch = Array('a');
    1.39 +addThis();
    1.40 +
    1.41 +status = inSection(2);
    1.42 +pattern = /((a)|(ab))((c)|(bc))/;
    1.43 +string = 'abc';
    1.44 +actualmatch = string.match(pattern);
    1.45 +expectedmatch = Array('abc', 'a', 'a', undefined, 'bc', undefined, 'bc');
    1.46 +addThis();
    1.47 +
    1.48 +status = inSection(3);
    1.49 +pattern = /a[a-z]{2,4}/;
    1.50 +string = 'abcdefghi';
    1.51 +actualmatch = string.match(pattern);
    1.52 +expectedmatch = Array('abcde');
    1.53 +addThis();
    1.54 +
    1.55 +status = inSection(4);
    1.56 +pattern = /a[a-z]{2,4}?/;
    1.57 +string = 'abcdefghi';
    1.58 +actualmatch = string.match(pattern);
    1.59 +expectedmatch = Array('abc');
    1.60 +addThis();
    1.61 +
    1.62 +status = inSection(5);
    1.63 +pattern = /(aa|aabaac|ba|b|c)*/;
    1.64 +string = 'aabaac';
    1.65 +actualmatch = string.match(pattern);
    1.66 +expectedmatch = Array('aaba', 'ba');
    1.67 +addThis();
    1.68 +
    1.69 +status = inSection(6);
    1.70 +pattern = /^(a+)\1*,\1+$/;
    1.71 +string = 'aaaaaaaaaa,aaaaaaaaaaaaaaa';
    1.72 +actualmatch = string.match(pattern);
    1.73 +expectedmatch = Array('aaaaaaaaaa,aaaaaaaaaaaaaaa', 'aaaaa');
    1.74 +addThis();
    1.75 +
    1.76 +status = inSection(7);
    1.77 +pattern = /(z)((a+)?(b+)?(c))*/;
    1.78 +string = 'zaacbbbcac';
    1.79 +actualmatch = string.match(pattern);
    1.80 +expectedmatch = Array('zaacbbbcac', 'z', 'ac', 'a', undefined, 'c');
    1.81 +addThis();
    1.82 +
    1.83 +status = inSection(8);
    1.84 +pattern = /(a*)*/;
    1.85 +string = 'b';
    1.86 +actualmatch = string.match(pattern);
    1.87 +expectedmatch = Array('', undefined);
    1.88 +addThis();
    1.89 +
    1.90 +status = inSection(9);
    1.91 +pattern = /(a*)b\1+/;
    1.92 +string = 'baaaac';
    1.93 +actualmatch = string.match(pattern);
    1.94 +expectedmatch = Array('b', '');
    1.95 +addThis();
    1.96 +
    1.97 +status = inSection(10);
    1.98 +pattern = /(?=(a+))/;
    1.99 +string = 'baaabac';
   1.100 +actualmatch = string.match(pattern);
   1.101 +expectedmatch = Array('', 'aaa');
   1.102 +addThis();
   1.103 +
   1.104 +status = inSection(11);
   1.105 +pattern = /(?=(a+))a*b\1/;
   1.106 +string = 'baaabac';
   1.107 +actualmatch = string.match(pattern);
   1.108 +expectedmatch = Array('aba', 'a');
   1.109 +addThis();
   1.110 +
   1.111 +status = inSection(12);
   1.112 +pattern = /(.*?)a(?!(a+)b\2c)\2(.*)/;
   1.113 +string = 'baaabaac';
   1.114 +actualmatch = string.match(pattern);
   1.115 +expectedmatch = Array('baaabaac', 'ba', undefined, 'abaac');
   1.116 +addThis();
   1.117 +
   1.118 +status = inSection(13);
   1.119 +pattern = /(?=(a+))/;
   1.120 +string = 'baaabac';
   1.121 +actualmatch = string.match(pattern);
   1.122 +expectedmatch = Array('', 'aaa');
   1.123 +addThis();
   1.124 +
   1.125 +
   1.126 +
   1.127 +//-------------------------------------------------------------------------------------------------
   1.128 +test();
   1.129 +//-------------------------------------------------------------------------------------------------
   1.130 +
   1.131 +
   1.132 +function addThis()
   1.133 +{
   1.134 +  statusmessages[i] = status;
   1.135 +  patterns[i] = pattern;
   1.136 +  strings[i] = string;
   1.137 +  actualmatches[i] = actualmatch;
   1.138 +  expectedmatches[i] = expectedmatch;
   1.139 +  i++;
   1.140 +}
   1.141 +
   1.142 +
   1.143 +function test()
   1.144 +{
   1.145 +  enterFunc ('test');
   1.146 +  printBugNumber(BUGNUMBER);
   1.147 +  printStatus (summary);
   1.148 +  testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
   1.149 +  exitFunc ('test');
   1.150 +}

mercurial