Imported tests
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma_3 / RegExp / regress-87231.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 mozilla.org code.\r
15  *\r
16  * The Initial Developer of the Original Code is\r
17  * Netscape Communications Corporation.\r
18  * Portions created by the Initial Developer are Copyright (C) 1998\r
19  * the Initial Developer. All Rights Reserved.\r
20  *\r
21  * Contributor(s):\r
22  *   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  * Date: 22 June 2001\r
39  *\r
40  * SUMMARY:  Regression test for Bugzilla bug 87231:\r
41  * "Regular expression /(A)?(A.*)/ picks 'A' twice"\r
42  *\r
43  * See http://bugzilla.mozilla.org/show_bug.cgi?id=87231\r
44  * Key case:\r
45  *\r
46  *            pattern = /^(A)?(A.*)$/;\r
47  *            string = 'A';\r
48  *            expectedmatch = Array('A', '', 'A');\r
49  *\r
50  *\r
51  * We expect the 1st subexpression (A)? NOT to consume the single 'A'.\r
52  * Recall that "?" means "match 0 or 1 times". Here, it should NOT do\r
53  * greedy matching: it should match 0 times instead of 1. This allows\r
54  * the 2nd subexpression to make the only match it can: the single 'A'.\r
55  * Such "altruism" is the only way there can be a successful global match...\r
56  */\r
57 //-------------------------------------------------------------------------------------------------\r
58 var i = 0;\r
59 var bug = 87231;\r
60 var cnEmptyString = '';\r
61 var summary = 'Testing regular expression /(A)?(A.*)/';\r
62 var status = '';\r
63 var statusmessages = new Array();\r
64 var pattern = '';\r
65 var patterns = new Array();\r
66 var string = '';\r
67 var strings = new Array();\r
68 var actualmatch = '';\r
69 var actualmatches = new Array();\r
70 var expectedmatch = '';\r
71 var expectedmatches = new Array();\r
72 \r
73 \r
74 pattern = /^(A)?(A.*)$/;\r
75     status = inSection(1);\r
76     string = 'AAA';\r
77     actualmatch = string.match(pattern);\r
78     expectedmatch = Array('AAA', 'A', 'AA');\r
79     addThis();\r
80 \r
81     status = inSection(2);\r
82     string = 'AA';\r
83     actualmatch = string.match(pattern);\r
84     expectedmatch = Array('AA', 'A', 'A');\r
85     addThis();\r
86 \r
87     status = inSection(3);\r
88     string = 'A';\r
89     actualmatch = string.match(pattern);\r
90     expectedmatch = Array('A', undefined, 'A'); // 'altruistic' case: see above\r
91     addThis();\r
92 \r
93 \r
94 pattern = /(A)?(A.*)/;\r
95 var strL = 'zxcasd;fl\\\  ^';\r
96 var strR = 'aaAAaaaf;lrlrzs';\r
97 \r
98     status = inSection(4);\r
99     string =  strL + 'AAA' + strR;\r
100     actualmatch = string.match(pattern);\r
101     expectedmatch = Array('AAA' + strR, 'A', 'AA' + strR);\r
102     addThis();\r
103 \r
104     status = inSection(5);\r
105     string =  strL + 'AA' + strR;\r
106     actualmatch = string.match(pattern);\r
107     expectedmatch = Array('AA' + strR, 'A', 'A' + strR);\r
108     addThis();\r
109 \r
110     status = inSection(6);\r
111     string =  strL + 'A' + strR;\r
112     actualmatch = string.match(pattern);\r
113     expectedmatch = Array('A' + strR, undefined, 'A' + strR); // 'altruistic' case: see above\r
114     addThis();\r
115 \r
116 \r
117 \r
118 //-------------------------------------------------------------------------------------------------\r
119 test();\r
120 //-------------------------------------------------------------------------------------------------\r
121 \r
122 \r
123 \r
124 function addThis()\r
125 {\r
126   statusmessages[i] = status;\r
127   patterns[i] = pattern;\r
128   strings[i] = string;\r
129   actualmatches[i] = actualmatch;\r
130   expectedmatches[i] = expectedmatch;\r
131   i++;\r
132 }\r
133 \r
134 \r
135 function test()\r
136 {\r
137   enterFunc ('test');\r
138   printBugNumber (bug);\r
139   printStatus (summary);\r
140   testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);\r
141   exitFunc ('test');\r
142 }\r