js/src/tests/ecma_2/RegExp/exec-002.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_2/RegExp/exec-002.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,188 @@
     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 + *  File Name:          RegExp/exec-002.js
    1.12 + *  ECMA Section:       15.7.5.3
    1.13 + *  Description:        Based on ECMA 2 Draft 7 February 1999
    1.14 + *
    1.15 + *  Test cases provided by rogerl@netscape.com
    1.16 + *
    1.17 + *  Author:             christine@netscape.com
    1.18 + *  Date:               19 February 1999
    1.19 + */
    1.20 +var SECTION = "RegExp/exec-002";
    1.21 +var VERSION = "ECMA_2";
    1.22 +var TITLE   = "RegExp.prototype.exec(string)";
    1.23 +
    1.24 +startTest();
    1.25 +
    1.26 +/*
    1.27 + * for each test case, verify:
    1.28 + * - type of object returned
    1.29 + * - length of the returned array
    1.30 + * - value of lastIndex
    1.31 + * - value of index
    1.32 + * - value of input
    1.33 + * - value of the array indices
    1.34 + */
    1.35 +
    1.36 +AddRegExpCases(
    1.37 +  /(a|d|q|)x/i,
    1.38 +  "bcaDxqy",
    1.39 +  3,
    1.40 +  ["Dx", "D"] );
    1.41 +
    1.42 +AddRegExpCases(
    1.43 +  /(a|(e|q))(x|y)/,
    1.44 +  "bcaddxqy",
    1.45 +  6,
    1.46 +  ["qy","q","q","y"] );
    1.47 +
    1.48 +
    1.49 +AddRegExpCases(
    1.50 +  /a+b+d/,
    1.51 +  "aabbeeaabbs",
    1.52 +  0,
    1.53 +  null );
    1.54 +
    1.55 +AddRegExpCases(
    1.56 +  /a*b/,
    1.57 +  "aaadaabaaa",
    1.58 +  4,
    1.59 +  ["aab"] );
    1.60 +
    1.61 +AddRegExpCases(
    1.62 +  /a*b/,
    1.63 +  "dddb",
    1.64 +  3,
    1.65 +  ["b"] );
    1.66 +
    1.67 +AddRegExpCases(
    1.68 +  /a*b/,
    1.69 +  "xxx",
    1.70 +  0,
    1.71 +  null );
    1.72 +
    1.73 +AddRegExpCases(
    1.74 +  /x\d\dy/,
    1.75 +  "abcx45ysss235",
    1.76 +  3,
    1.77 +  ["x45y"] );
    1.78 +
    1.79 +AddRegExpCases(
    1.80 +  /[^abc]def[abc]+/,
    1.81 +  "abxdefbb",
    1.82 +  2,
    1.83 +  ["xdefbb"] );
    1.84 +
    1.85 +AddRegExpCases(
    1.86 +  /(a*)baa/,
    1.87 +  "ccdaaabaxaabaa",
    1.88 +  9,
    1.89 +  ["aabaa", "aa"] );
    1.90 +
    1.91 +AddRegExpCases(
    1.92 +  /(a*)baa/,
    1.93 +  "aabaa",
    1.94 +  0,
    1.95 +  ["aabaa", "aa"] );
    1.96 +
    1.97 +AddRegExpCases(
    1.98 +  /q(a|b)*q/,
    1.99 +  "xxqababqyy",
   1.100 +  2,
   1.101 +  ["qababq", "b"] );
   1.102 +
   1.103 +AddRegExpCases(
   1.104 +  /(a(.|[^d])c)*/,
   1.105 +  "adcaxc",
   1.106 +  0,
   1.107 +  ["adcaxc", "axc", "x"] );
   1.108 +
   1.109 +AddRegExpCases(
   1.110 +  /(a*)b\1/,
   1.111 +  "abaaaxaabaayy",
   1.112 +  0,
   1.113 +  ["aba", "a"] );
   1.114 +
   1.115 +AddRegExpCases(
   1.116 +  /(a*)b\1/,
   1.117 +  "abaaaxaabaayy",
   1.118 +  0,
   1.119 +  ["aba", "a"] );
   1.120 +
   1.121 +AddRegExpCases(
   1.122 +  /(a*)b\1/,
   1.123 +  "cccdaaabaxaabaayy",
   1.124 +  6,
   1.125 +  ["aba", "a"] );
   1.126 +
   1.127 +AddRegExpCases(
   1.128 +  /(a*)b\1/,
   1.129 +  "cccdaaabqxaabaayy",
   1.130 +  7,
   1.131 +  ["b", ""] );
   1.132 +
   1.133 +AddRegExpCases(
   1.134 +  /"(.|[^"\\\\])*"/,
   1.135 +        'xx\"makudonarudo\"yy',
   1.136 +        2,
   1.137 +        ["\"makudonarudo\"", "o"] );
   1.138 +
   1.139 +    AddRegExpCases(
   1.140 +        /"(.|[^"\\\\])*"/,
   1.141 +	      "xx\"ma\"yy",
   1.142 +	      2,
   1.143 +	      ["\"ma\"", "a"] );
   1.144 +
   1.145 +	   test();
   1.146 +
   1.147 +	   function AddRegExpCases(
   1.148 +	     regexp, pattern, index, matches_array ) {
   1.149 +
   1.150 +// prevent a runtime error
   1.151 +
   1.152 +	     if ( regexp.exec(pattern) == null || matches_array == null ) {
   1.153 +	       AddTestCase(
   1.154 +		 regexp + ".exec(" + pattern +")",
   1.155 +		 matches_array,
   1.156 +		 regexp.exec(pattern) );
   1.157 +
   1.158 +	       return;
   1.159 +	     }
   1.160 +	     AddTestCase(
   1.161 +	       regexp + ".exec(" + pattern +").length",
   1.162 +	       matches_array.length,
   1.163 +	       regexp.exec(pattern).length );
   1.164 +
   1.165 +	     AddTestCase(
   1.166 +	       regexp + ".exec(" + pattern +").index",
   1.167 +	       index,
   1.168 +	       regexp.exec(pattern).index );
   1.169 +
   1.170 +	     AddTestCase(
   1.171 +	       regexp + ".exec(" + pattern +").input",
   1.172 +	       pattern,
   1.173 +	       regexp.exec(pattern).input );
   1.174 +
   1.175 +	     AddTestCase(
   1.176 +	       regexp + ".exec(" + pattern +").toString()",
   1.177 +	       matches_array.toString(),
   1.178 +	       regexp.exec(pattern).toString() );
   1.179 +/*
   1.180 +  var limit = matches_array.length > regexp.exec(pattern).length
   1.181 +  ? matches_array.length
   1.182 +  : regexp.exec(pattern).length;
   1.183 +
   1.184 +  for ( var matches = 0; matches < limit; matches++ ) {
   1.185 +  AddTestCase(
   1.186 +  regexp + ".exec(" + pattern +")[" + matches +"]",
   1.187 +  matches_array[matches],
   1.188 +  regexp.exec(pattern)[matches] );
   1.189 +  }
   1.190 +*/
   1.191 +	   }

mercurial