Debian Codegraph @

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

raw
1 /* -*- tab-width: 2; 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 * 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 [email protected]
13 *
14 * Author: [email protected]
15 * Date: 19 February 1999
16 */
17 var SECTION = "RegExp/exec-002";
18 var TITLE = "RegExp.prototype.exec(string)";
19
20
21 /*
22 * for each test case, verify:
23 * - type of object returned
24 * - length of the returned array
25 * - value of lastIndex
26 * - value of index
27 * - value of input
28 * - value of the array indices
29 */
30
31 AddRegExpCases(
32 /(a|d|q|)x/i,
33 "bcaDxqy",
34 3,
35 ["Dx", "D"] );
36
37 AddRegExpCases(
38 /(a|(e|q))(x|y)/,
39 "bcaddxqy",
40 6,
41 ["qy","q","q","y"] );
42
43
44 AddRegExpCases(
45 /a+b+d/,
46 "aabbeeaabbs",
47 0,
48 null );
49
50 AddRegExpCases(
51 /a*b/,
52 "aaadaabaaa",
53 4,
54 ["aab"] );
55
56 AddRegExpCases(
57 /a*b/,
58 "dddb",
59 3,
60 ["b"] );
61
62 AddRegExpCases(
63 /a*b/,
64 "xxx",
65 0,
66 null );
67
68 AddRegExpCases(
69 /x\d\dy/,
70 "abcx45ysss235",
71 3,
72 ["x45y"] );
73
74 AddRegExpCases(
75 /[^abc]def[abc]+/,
76 "abxdefbb",
77 2,
78 ["xdefbb"] );
79
80 AddRegExpCases(
81 /(a*)baa/,
82 "ccdaaabaxaabaa",
83 9,
84 ["aabaa", "aa"] );
85
86 AddRegExpCases(
87 /(a*)baa/,
88 "aabaa",
89 0,
90 ["aabaa", "aa"] );
91
92 AddRegExpCases(
93 /q(a|b)*q/,
94 "xxqababqyy",
95 2,
96 ["qababq", "b"] );
97
98 AddRegExpCases(
99 /(a(.|[^d])c)*/,
100 "adcaxc",
101 0,
102 ["adcaxc", "axc", "x"] );
103
104 AddRegExpCases(
105 /(a*)b\1/,
106 "abaaaxaabaayy",
107 0,
108 ["aba", "a"] );
109
110 AddRegExpCases(
111 /(a*)b\1/,
112 "abaaaxaabaayy",
113 0,
114 ["aba", "a"] );
115
116 AddRegExpCases(
117 /(a*)b\1/,
118 "cccdaaabaxaabaayy",
119 6,
120 ["aba", "a"] );
121
122 AddRegExpCases(
123 /(a*)b\1/,
124 "cccdaaabqxaabaayy",
125 7,
126 ["b", ""] );
127
128 AddRegExpCases(
129 /"(.|[^"\\\\])*"/,
130 'xx\"makudonarudo\"yy',
131 2,
132 ["\"makudonarudo\"", "o"] );
133
134 AddRegExpCases(
135 /"(.|[^"\\\\])*"/,
136 "xx\"ma\"yy",
137 2,
138 ["\"ma\"", "a"] );
139
140 test();
141
142 function AddRegExpCases(
143 regexp, pattern, index, matches_array ) {
144
145 // prevent a runtime error
146
147 if ( regexp.exec(pattern) == null || matches_array == null ) {
148 AddTestCase(
149 regexp + ".exec(" + pattern +")",
150 matches_array,
151 regexp.exec(pattern) );
152
153 return;
154 }
155 AddTestCase(
156 regexp + ".exec(" + pattern +").length",
157 matches_array.length,
158 regexp.exec(pattern).length );
159
160 AddTestCase(
161 regexp + ".exec(" + pattern +").index",
162 index,
163 regexp.exec(pattern).index );
164
165 AddTestCase(
166 regexp + ".exec(" + pattern +").input",
167 pattern,
168 regexp.exec(pattern).input );
169
170 AddTestCase(
171 regexp + ".exec(" + pattern +").toString()",
172 matches_array.toString(),
173 regexp.exec(pattern).toString() );
174 /*
175 var limit = matches_array.length > regexp.exec(pattern).length
176 ? matches_array.length
177 : regexp.exec(pattern).length;
178
179 for ( var matches = 0; matches < limit; matches++ ) {
180 AddTestCase(
181 regexp + ".exec(" + pattern +")[" + matches +"]",
182 matches_array[matches],
183 regexp.exec(pattern)[matches] );
184 }
185 */
186 }