|
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 |
|
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)"; |
|
20 |
|
21 startTest(); |
|
22 |
|
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 */ |
|
32 |
|
33 AddRegExpCases( |
|
34 /(a|d|q|)x/i, |
|
35 "bcaDxqy", |
|
36 3, |
|
37 ["Dx", "D"] ); |
|
38 |
|
39 AddRegExpCases( |
|
40 /(a|(e|q))(x|y)/, |
|
41 "bcaddxqy", |
|
42 6, |
|
43 ["qy","q","q","y"] ); |
|
44 |
|
45 |
|
46 AddRegExpCases( |
|
47 /a+b+d/, |
|
48 "aabbeeaabbs", |
|
49 0, |
|
50 null ); |
|
51 |
|
52 AddRegExpCases( |
|
53 /a*b/, |
|
54 "aaadaabaaa", |
|
55 4, |
|
56 ["aab"] ); |
|
57 |
|
58 AddRegExpCases( |
|
59 /a*b/, |
|
60 "dddb", |
|
61 3, |
|
62 ["b"] ); |
|
63 |
|
64 AddRegExpCases( |
|
65 /a*b/, |
|
66 "xxx", |
|
67 0, |
|
68 null ); |
|
69 |
|
70 AddRegExpCases( |
|
71 /x\d\dy/, |
|
72 "abcx45ysss235", |
|
73 3, |
|
74 ["x45y"] ); |
|
75 |
|
76 AddRegExpCases( |
|
77 /[^abc]def[abc]+/, |
|
78 "abxdefbb", |
|
79 2, |
|
80 ["xdefbb"] ); |
|
81 |
|
82 AddRegExpCases( |
|
83 /(a*)baa/, |
|
84 "ccdaaabaxaabaa", |
|
85 9, |
|
86 ["aabaa", "aa"] ); |
|
87 |
|
88 AddRegExpCases( |
|
89 /(a*)baa/, |
|
90 "aabaa", |
|
91 0, |
|
92 ["aabaa", "aa"] ); |
|
93 |
|
94 AddRegExpCases( |
|
95 /q(a|b)*q/, |
|
96 "xxqababqyy", |
|
97 2, |
|
98 ["qababq", "b"] ); |
|
99 |
|
100 AddRegExpCases( |
|
101 /(a(.|[^d])c)*/, |
|
102 "adcaxc", |
|
103 0, |
|
104 ["adcaxc", "axc", "x"] ); |
|
105 |
|
106 AddRegExpCases( |
|
107 /(a*)b\1/, |
|
108 "abaaaxaabaayy", |
|
109 0, |
|
110 ["aba", "a"] ); |
|
111 |
|
112 AddRegExpCases( |
|
113 /(a*)b\1/, |
|
114 "abaaaxaabaayy", |
|
115 0, |
|
116 ["aba", "a"] ); |
|
117 |
|
118 AddRegExpCases( |
|
119 /(a*)b\1/, |
|
120 "cccdaaabaxaabaayy", |
|
121 6, |
|
122 ["aba", "a"] ); |
|
123 |
|
124 AddRegExpCases( |
|
125 /(a*)b\1/, |
|
126 "cccdaaabqxaabaayy", |
|
127 7, |
|
128 ["b", ""] ); |
|
129 |
|
130 AddRegExpCases( |
|
131 /"(.|[^"\\\\])*"/, |
|
132 'xx\"makudonarudo\"yy', |
|
133 2, |
|
134 ["\"makudonarudo\"", "o"] ); |
|
135 |
|
136 AddRegExpCases( |
|
137 /"(.|[^"\\\\])*"/, |
|
138 "xx\"ma\"yy", |
|
139 2, |
|
140 ["\"ma\"", "a"] ); |
|
141 |
|
142 test(); |
|
143 |
|
144 function AddRegExpCases( |
|
145 regexp, pattern, index, matches_array ) { |
|
146 |
|
147 // prevent a runtime error |
|
148 |
|
149 if ( regexp.exec(pattern) == null || matches_array == null ) { |
|
150 AddTestCase( |
|
151 regexp + ".exec(" + pattern +")", |
|
152 matches_array, |
|
153 regexp.exec(pattern) ); |
|
154 |
|
155 return; |
|
156 } |
|
157 AddTestCase( |
|
158 regexp + ".exec(" + pattern +").length", |
|
159 matches_array.length, |
|
160 regexp.exec(pattern).length ); |
|
161 |
|
162 AddTestCase( |
|
163 regexp + ".exec(" + pattern +").index", |
|
164 index, |
|
165 regexp.exec(pattern).index ); |
|
166 |
|
167 AddTestCase( |
|
168 regexp + ".exec(" + pattern +").input", |
|
169 pattern, |
|
170 regexp.exec(pattern).input ); |
|
171 |
|
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; |
|
180 |
|
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 } |