• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15var r;
16
17// Simple test cases
18r = new RegExp ("(?:)");
19assert (r.exec ("a") == "");
20
21r = new RegExp ("(?:a)");
22assert (r.exec ("a") == "a");
23
24r = new RegExp ("(?:(?:a)b)c");
25assert (r.exec ("abc") == "abc");
26
27r = new RegExp ("(?:a)*");
28assert (r.exec ("b") == "");
29assert (r.exec ("aaaa") == "aaaa");
30
31r = new RegExp ("(?:a)+");
32assert (r.exec ("aaaa") == "aaaa");
33
34r = new RegExp ("(?:a){4}");
35assert (r.exec ("aaaa") == "aaaa");
36
37r = new RegExp ("(?:a){1,2}");
38assert (r.exec ("a") == "a");
39assert (r.exec ("aa") == "aa");
40assert (r.exec ("aaaa") == "aa");
41
42r = new RegExp ("(?:a)?");
43assert (r.exec ("a") == "a");
44assert (r.exec ("b") == "");
45
46// Test greedy iterations
47r = new RegExp ("(?:a){1,3}a");
48assert (r.exec ("aa") == "aa");
49
50r = new RegExp ("(?:a){1,3}a");
51assert (r.exec ("aaa") == "aaa");
52
53r = new RegExp ("(?:a){1,3}");
54assert (r.exec ("a") == "a");
55
56r = new RegExp ("(?:a){1,3}");
57assert (r.exec ("aaa") == "aaa");
58
59r = new RegExp ("(?:a){1,3}");
60assert (r.exec ("aaaa") == "aaa");
61
62r = new RegExp ("(?:a){1,5}");
63assert (r.exec ("aaaa") == "aaaa");
64
65r = new RegExp ("(?:a|b){1,2}");
66assert (r.exec ("a") == "a");
67
68r = new RegExp ("(?:a|b){1,3}a");
69assert (r.exec ("aaa") == "aaa");
70
71r = new RegExp ("(?:a|b){1,3}a");
72assert (r.exec ("aba") == "aba");
73
74r = new RegExp ("(?:a|b){1,3}a");
75assert (r.exec ("b") == undefined);
76
77r = new RegExp ("(?:a|b){1,3}a");
78assert (r.exec ("bbb") == undefined);
79
80r = new RegExp ("(?:a|b){1,3}");
81assert (r.exec ("a") == "a");
82
83r = new RegExp ("(?:a|b){1,3}");
84assert (r.exec ("aa") == "aa");
85
86r = new RegExp ("(?:a|b){1,3}");
87assert (r.exec ("aaa") == "aaa");
88
89r = new RegExp ("(?:a|b){1,3}");
90assert (r.exec ("ab") == "ab");
91
92r = new RegExp ("(?:a|b){1,3}");
93assert (r.exec ("aba") == "aba");
94
95r = new RegExp ("(?:a|b){1,3}");
96assert (r.exec ("bab") == "bab");
97
98r = new RegExp ("(?:a|b){1,3}");
99assert (r.exec ("bbb") == "bbb");
100
101r = new RegExp ("(?:a|b){1,4}a");
102assert (r.exec ("bbb") == undefined);
103
104r = new RegExp ("(?:a|b){1,4}");
105assert (r.exec ("ab") == "ab");
106
107r = new RegExp ("(?:a|b){1,4}");
108assert (r.exec ("aba") == "aba");
109
110r = new RegExp ("(?:a|b){1,4}");
111assert (r.exec ("bbb") == "bbb");
112
113r = new RegExp ("(?:a|b){1,5}");
114assert (r.exec ("abab") == "abab");
115
116r = new RegExp ("(?:aba)*");
117assert (r.exec ("aaaa") == "");
118
119r = new RegExp ("(?:aba)+");
120assert (r.exec ("aaaa") == undefined);
121
122r = new RegExp ("(?:a|bb|c|d)");
123assert (r.exec ("a") == "a");
124
125r = new RegExp ("(?:a|b|c|d)");
126assert (r.exec ("") == undefined);
127
128r = new RegExp ("(?:a|b|c|d)");
129assert (r.exec ("a") == "a");
130
131r = new RegExp ("(?:a|b|c|d)");
132assert (r.exec ("b") == "b");
133
134r = new RegExp ("(?:a|b|c|d)");
135assert (r.exec ("c") == "c");
136
137r = new RegExp ("(?:a|b|c|d)");
138assert (r.exec ("d") == "d");
139
140r = new RegExp ("(?:a|b)+");
141assert (r.exec ("aba") == "aba");
142
143r = new RegExp ("(?:a|b)");
144assert (r.exec ("b") == "b");
145
146r = new RegExp ("(?:a)");
147assert (r.exec ("a") == "a");
148
149r = new RegExp ("(?:a)*");
150assert (r.exec ("a") == "a");
151
152r = new RegExp ("(?:a)*");
153assert (r.exec ("aaaa") == "aaaa");
154
155r = new RegExp ("(?:a)+");
156assert (r.exec ("aaaa") == "aaaa");
157
158r = new RegExp ("(?:a)?aa");
159assert (r.exec ("aaaa") == "aaa");
160
161r = new RegExp ("(?:a?){0,1}a");
162assert (r.exec ("aa") == "aa");
163
164r = new RegExp ("(?:a|aa){0,3}b");
165assert (r.exec ("aaaaaab") == "aaaaaab");
166
167r = new RegExp ("(?:(?:a){2,3}){4}b");
168assert (r.exec ("aaaaaaaab") == "aaaaaaaab");
169
170// Test non-greedy iterations
171r = new RegExp ("(?:a)+?");
172assert (r.exec ("aaaa") == "a");
173
174r = new RegExp ("(?:a)*?aa");
175assert (r.exec ("aaaa") == "aa");
176
177r = new RegExp ("(?:aaa|aa)*?aa");
178assert (r.exec ("aaaa") == "aa");
179
180r = new RegExp ("(?:a)??aa");
181assert (r.exec ("aaaa") == "aa");
182
183r = new RegExp ("(?:(?:)*?)*?a");
184assert (r.exec ("ba") == "a");
185
186r = new RegExp ("(?:(?:bb?)*)*a");
187assert (r.exec ("bbba") == "bbba");
188
189r = new RegExp ("(?:(?:bb?)*)*bbb\\Ba");
190assert (r.exec ("bbba") == "bbba");
191
192r = new RegExp ("(?:a??){0,1}a");
193assert (r.exec ("aa") == "aa");
194
195r = new RegExp ("(?:a{0,1}?){0,1}a");
196assert (r.exec ("aa") == "aa");
197