Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_3 / RegExp / regress-191479.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is JavaScript Engine testing utilities.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corp.
19  * Portions created by the Initial Developer are Copyright (C) 2003
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   flying@dom.natm.ru, pschwartau@netscape.com
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /*
40  *
41  * Date:    31 January 2003
42  * SUMMARY: Testing regular expressions of form /(x|y){n,}/
43  *
44  * See http://bugzilla.mozilla.org/show_bug.cgi?id=191479
45  *
46  */
47 //-----------------------------------------------------------------------------
48 var i = 0;
49 var BUGNUMBER = 191479;
50 var summary = 'Testing regular expressions of form /(x|y){n,}/';
51 var status = '';
52 var statusmessages = new Array();
53 var pattern = '';
54 var patterns = new Array();
55 var string = '';
56 var strings = new Array();
57 var actualmatch = '';
58 var actualmatches = new Array();
59 var expectedmatch = '';
60 var expectedmatches = new Array();
61
62
63 status = inSection(1);
64 string = '12 3 45';
65 pattern = /(\d|\d\s){2,}/;
66 actualmatch = string.match(pattern);
67 expectedmatch = Array('12', '2');
68 addThis();
69
70 status = inSection(2);
71 string = '12 3 45';
72 pattern = /(\d|\d\s){4,}/;
73 actualmatch = string.match(pattern);
74 expectedmatch = Array(string, '5');
75 addThis();
76
77 status = inSection(3);
78 string = '12 3 45';
79 pattern = /(\d|\d\s)+/;
80 actualmatch = string.match(pattern);
81 expectedmatch = Array('12', '2');
82 addThis();
83
84 status = inSection(4);
85 string = '12 3 45';
86 pattern = /(\d\s?){4,}/;
87 actualmatch = string.match(pattern);
88 expectedmatch = Array(string, '5');
89 addThis();
90
91 /*
92  * Let's reverse the operands in Sections 1-3 above -
93  */
94 status = inSection(5);
95 string = '12 3 45';
96 pattern = /(\d\s|\d){2,}/;
97 actualmatch = string.match(pattern);
98 expectedmatch = Array(string, '5');
99 addThis();
100
101 status = inSection(6);
102 string = '12 3 45';
103 pattern = /(\d\s|\d){4,}/;
104 actualmatch = string.match(pattern);
105 expectedmatch = Array(string, '5');
106 addThis();
107
108 status = inSection(7);
109 string = '12 3 45';
110 pattern = /(\d\s|\d)+/;
111 actualmatch = string.match(pattern);
112 expectedmatch = Array(string, '5');
113 addThis();
114
115
116 /*
117  * Let's take all 7 sections above and make each quantifer non-greedy.
118  *
119  * This is done by appending ? to it. It doesn't change the meaning of
120  * the quantifier, but makes it non-greedy, which affects the results -
121  */
122 status = inSection(8);
123 string = '12 3 45';
124 pattern = /(\d|\d\s){2,}?/;
125 actualmatch = string.match(pattern);
126 expectedmatch = Array('12', '2');
127 addThis();
128
129 status = inSection(9);
130 string = '12 3 45';
131 pattern = /(\d|\d\s){4,}?/;
132 actualmatch = string.match(pattern);
133 expectedmatch = Array('12 3 4', '4');
134 addThis();
135
136 status = inSection(10);
137 string = '12 3 45';
138 pattern = /(\d|\d\s)+?/;
139 actualmatch = string.match(pattern);
140 expectedmatch = Array('1', '1');
141 addThis();
142
143 status = inSection(11);
144 string = '12 3 45';
145 pattern = /(\d\s?){4,}?/;
146 actualmatch = string.match(pattern);
147 expectedmatch = Array('12 3 4', '4');
148 addThis();
149
150 status = inSection(12);
151 string = '12 3 45';
152 pattern = /(\d\s|\d){2,}?/;
153 actualmatch = string.match(pattern);
154 expectedmatch = Array('12 ', '2 ');
155 addThis();
156
157 status = inSection(13);
158 string = '12 3 45';
159 pattern = /(\d\s|\d){4,}?/;
160 actualmatch = string.match(pattern);
161 expectedmatch = Array('12 3 4', '4');
162 addThis();
163
164 status = inSection(14);
165 string = '12 3 45';
166 pattern = /(\d\s|\d)+?/;
167 actualmatch = string.match(pattern);
168 expectedmatch = Array('1', '1');
169 addThis();
170
171
172
173 //-----------------------------------------------------------------------------
174 test();
175 //-----------------------------------------------------------------------------
176
177
178
179 function addThis()
180 {
181   statusmessages[i] = status;
182   patterns[i] = pattern;
183   strings[i] = string;
184   actualmatches[i] = actualmatch;
185   expectedmatches[i] = expectedmatch;
186   i++;
187 }
188
189
190 function test()
191 {
192   enterFunc ('test');
193   printBugNumber(BUGNUMBER);
194   printStatus (summary);
195   testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
196   exitFunc ('test');
197 }