Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_3 / RegExp / regress-225289.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  *   PhilSchwartau@aol.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:    10 November 2003
42  * SUMMARY: Testing regexps with complementary alternatives
43  *
44  * See http://bugzilla.mozilla.org/show_bug.cgi?id=225289
45  *
46  */
47 //-----------------------------------------------------------------------------
48 var i = 0;
49 var BUGNUMBER = 225289;
50 var summary = 'Testing regexps with complementary alternatives';
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 // this pattern should match any string!
64 pattern = /a|[^a]/;
65
66 status = inSection(1);
67 string = 'a';
68 actualmatch = string.match(pattern);
69 expectedmatch = Array('a');
70 addThis();
71
72 status = inSection(2);
73 string = '';
74 actualmatch = string.match(pattern);
75 expectedmatch = null;
76 addThis();
77
78 status = inSection(3);
79 string = '()';
80 actualmatch = string.match(pattern);
81 expectedmatch = Array('(');
82 addThis();
83
84
85 pattern = /(a|[^a])/;
86
87 status = inSection(4);
88 string = 'a';
89 actualmatch = string.match(pattern);
90 expectedmatch = Array('a', 'a');
91 addThis();
92
93 status = inSection(5);
94 string = '';
95 actualmatch = string.match(pattern);
96 expectedmatch = null;
97 addThis();
98
99 status = inSection(6);
100 string = '()';
101 actualmatch = string.match(pattern);
102 expectedmatch = Array('(', '(');
103 addThis();
104
105
106 pattern = /(a)|([^a])/;
107
108 status = inSection(7);
109 string = 'a';
110 actualmatch = string.match(pattern);
111 expectedmatch = Array('a', 'a', undefined);
112 addThis();
113
114 status = inSection(8);
115 string = '';
116 actualmatch = string.match(pattern);
117 expectedmatch = null;
118 addThis();
119
120 status = inSection(9);
121 string = '()';
122 actualmatch = string.match(pattern);
123 expectedmatch = Array('(', undefined, '(');
124 addThis();
125
126
127 // note this pattern has one non-capturing parens
128 pattern = /((?:a|[^a])*)/g;
129
130 status = inSection(10);
131 string = 'a';
132 actualmatch = string.match(pattern);
133 expectedmatch = Array('a', ''); // see bug 225289 comment 6
134 addThis();
135
136 status = inSection(11);
137 string = '';
138 actualmatch = string.match(pattern);
139 expectedmatch = Array(''); // see bug 225289 comment 9
140 addThis();
141
142 status = inSection(12);
143 string = '()';
144 actualmatch = string.match(pattern);
145 expectedmatch = Array('()', ''); // see bug 225289 comment 6
146 addThis();
147
148
149
150
151 //-------------------------------------------------------------------------------------------------
152 test();
153 //-------------------------------------------------------------------------------------------------
154
155
156
157 function addThis()
158 {
159   statusmessages[i] = status;
160   patterns[i] = pattern;
161   strings[i] = string;
162   actualmatches[i] = actualmatch;
163   expectedmatches[i] = expectedmatch;
164   i++;
165 }
166
167
168 function test()
169 {
170   enterFunc ('test');
171   printBugNumber(BUGNUMBER);
172   printStatus (summary);
173   testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
174   exitFunc ('test');
175 }