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