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