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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
     7 /**
     8  *  File Name:          RegExp/exec-002.js
     9  *  ECMA Section:       15.7.5.3
    10  *  Description:        Based on ECMA 2 Draft 7 February 1999
    11  *
    12  *  Test cases provided by rogerl@netscape.com
    13  *
    14  *  Author:             christine@netscape.com
    15  *  Date:               19 February 1999
    16  */
    17 var SECTION = "RegExp/exec-002";
    18 var VERSION = "ECMA_2";
    19 var TITLE   = "RegExp.prototype.exec(string)";
    21 startTest();
    23 /*
    24  * for each test case, verify:
    25  * - type of object returned
    26  * - length of the returned array
    27  * - value of lastIndex
    28  * - value of index
    29  * - value of input
    30  * - value of the array indices
    31  */
    33 AddRegExpCases(
    34   /(a|d|q|)x/i,
    35   "bcaDxqy",
    36   3,
    37   ["Dx", "D"] );
    39 AddRegExpCases(
    40   /(a|(e|q))(x|y)/,
    41   "bcaddxqy",
    42   6,
    43   ["qy","q","q","y"] );
    46 AddRegExpCases(
    47   /a+b+d/,
    48   "aabbeeaabbs",
    49   0,
    50   null );
    52 AddRegExpCases(
    53   /a*b/,
    54   "aaadaabaaa",
    55   4,
    56   ["aab"] );
    58 AddRegExpCases(
    59   /a*b/,
    60   "dddb",
    61   3,
    62   ["b"] );
    64 AddRegExpCases(
    65   /a*b/,
    66   "xxx",
    67   0,
    68   null );
    70 AddRegExpCases(
    71   /x\d\dy/,
    72   "abcx45ysss235",
    73   3,
    74   ["x45y"] );
    76 AddRegExpCases(
    77   /[^abc]def[abc]+/,
    78   "abxdefbb",
    79   2,
    80   ["xdefbb"] );
    82 AddRegExpCases(
    83   /(a*)baa/,
    84   "ccdaaabaxaabaa",
    85   9,
    86   ["aabaa", "aa"] );
    88 AddRegExpCases(
    89   /(a*)baa/,
    90   "aabaa",
    91   0,
    92   ["aabaa", "aa"] );
    94 AddRegExpCases(
    95   /q(a|b)*q/,
    96   "xxqababqyy",
    97   2,
    98   ["qababq", "b"] );
   100 AddRegExpCases(
   101   /(a(.|[^d])c)*/,
   102   "adcaxc",
   103   0,
   104   ["adcaxc", "axc", "x"] );
   106 AddRegExpCases(
   107   /(a*)b\1/,
   108   "abaaaxaabaayy",
   109   0,
   110   ["aba", "a"] );
   112 AddRegExpCases(
   113   /(a*)b\1/,
   114   "abaaaxaabaayy",
   115   0,
   116   ["aba", "a"] );
   118 AddRegExpCases(
   119   /(a*)b\1/,
   120   "cccdaaabaxaabaayy",
   121   6,
   122   ["aba", "a"] );
   124 AddRegExpCases(
   125   /(a*)b\1/,
   126   "cccdaaabqxaabaayy",
   127   7,
   128   ["b", ""] );
   130 AddRegExpCases(
   131   /"(.|[^"\\\\])*"/,
   132         'xx\"makudonarudo\"yy',
   133         2,
   134         ["\"makudonarudo\"", "o"] );
   136     AddRegExpCases(
   137         /"(.|[^"\\\\])*"/,
   138 	      "xx\"ma\"yy",
   139 	      2,
   140 	      ["\"ma\"", "a"] );
   142 	   test();
   144 	   function AddRegExpCases(
   145 	     regexp, pattern, index, matches_array ) {
   147 // prevent a runtime error
   149 	     if ( regexp.exec(pattern) == null || matches_array == null ) {
   150 	       AddTestCase(
   151 		 regexp + ".exec(" + pattern +")",
   152 		 matches_array,
   153 		 regexp.exec(pattern) );
   155 	       return;
   156 	     }
   157 	     AddTestCase(
   158 	       regexp + ".exec(" + pattern +").length",
   159 	       matches_array.length,
   160 	       regexp.exec(pattern).length );
   162 	     AddTestCase(
   163 	       regexp + ".exec(" + pattern +").index",
   164 	       index,
   165 	       regexp.exec(pattern).index );
   167 	     AddTestCase(
   168 	       regexp + ".exec(" + pattern +").input",
   169 	       pattern,
   170 	       regexp.exec(pattern).input );
   172 	     AddTestCase(
   173 	       regexp + ".exec(" + pattern +").toString()",
   174 	       matches_array.toString(),
   175 	       regexp.exec(pattern).toString() );
   176 /*
   177   var limit = matches_array.length > regexp.exec(pattern).length
   178   ? matches_array.length
   179   : regexp.exec(pattern).length;
   181   for ( var matches = 0; matches < limit; matches++ ) {
   182   AddTestCase(
   183   regexp + ".exec(" + pattern +")[" + matches +"]",
   184   matches_array[matches],
   185   regexp.exec(pattern)[matches] );
   186   }
   187 */
   188 	   }

mercurial