Debian Codegraph @

rhino/testsrc/tests/ecma_2/RegExp/exec-002.js

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