Imported tests
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma_3 / RegExp / octal-002.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) 2002\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  *\r
39  * Date:    31 July 2002\r
40  * SUMMARY: Testing regexps containing octal escape sequences\r
41  * This is an elaboration of mozilla/js/tests/ecma_2/RegExp/octal-003.js\r
42  *\r
43  * See http://bugzilla.mozilla.org/show_bug.cgi?id=141078\r
44  * for a reference on octal escape sequences in regexps.\r
45  *\r
46  * NOTE:\r
47  * We will use the identities '\011' === '\u0009' === '\x09' === '\t'\r
48  *\r
49  * The first is an octal escape sequence (\(0-3)OO; O an octal digit).\r
50  * See ECMA-262 Edition 2, Section 7.7.4 "String Literals". These were\r
51  * dropped in Edition 3 but we support them for backward compatibility.\r
52  *\r
53  * The second is a Unicode escape sequence (\uHHHH; H a hex digit).\r
54  * Since octal 11 = hex 9, the two escapes define the same character.\r
55  *\r
56  * The third is a hex escape sequence (\xHH; H a hex digit).\r
57  * Since hex 09 = hex 0009, this defines the same character.\r
58  *\r
59  * The fourth is the familiar escape sequence for a horizontal tab,\r
60  * defined in the ECMA spec as having Unicode value \u0009.\r
61  */\r
62 //-----------------------------------------------------------------------------\r
63 var i = 0;\r
64 var bug = 141078;\r
65 var summary = 'Testing regexps containing octal escape sequences';\r
66 var status = '';\r
67 var statusmessages = new Array();\r
68 var pattern = '';\r
69 var patterns = new Array();\r
70 var string = '';\r
71 var strings = new Array();\r
72 var actualmatch = '';\r
73 var actualmatches = new Array();\r
74 var expectedmatch = '';\r
75 var expectedmatches = new Array();\r
76 \r
77 \r
78 /*\r
79  * Test a string containing the null character '\0' followed by the string '11'\r
80  *\r
81  *               'a' + String.fromCharCode(0) + '11';\r
82  *\r
83  * Note we can't simply write 'a\011', because '\011' would be interpreted\r
84  * as the octal escape sequence for the tab character (see above).\r
85  *\r
86  * We should get no match from the regexp /.\011/, because it should be\r
87  * looking for the octal escape sequence \011, i.e. the tab character -\r
88  *\r
89  */\r
90 status = inSection(1);\r
91 pattern = /.\011/;\r
92 string = 'a' + String.fromCharCode(0) + '11';\r
93 actualmatch = string.match(pattern);\r
94 expectedmatch = null;\r
95 addThis();\r
96 \r
97 \r
98 /*\r
99  * Try same thing with 'xx' in place of '11'.\r
100  *\r
101  * Should get a match now, because the octal escape sequence in the regexp\r
102  * has been reduced from \011 to \0, and '\0' is present in the string -\r
103  */\r
104 status = inSection(2);\r
105 pattern = /.\0xx/;\r
106 string = 'a' + String.fromCharCode(0) + 'xx';\r
107 actualmatch = string.match(pattern);\r
108 expectedmatch = Array(string);\r
109 addThis();\r
110 \r
111 \r
112 /*\r
113  * Same thing; don't use |String.fromCharCode(0)| this time.\r
114  * There is no ambiguity in '\0xx': it is the null character\r
115  * followed by two x's, no other interpretation is possible.\r
116  */\r
117 status = inSection(3);\r
118 pattern = /.\0xx/;\r
119 string = 'a\0xx';\r
120 actualmatch = string.match(pattern);\r
121 expectedmatch = Array(string);\r
122 addThis();\r
123 \r
124 \r
125 /*\r
126  * This one should produce a match. The two-character string\r
127  * 'a' + '\011' is duplicated in the pattern and test string:\r
128  */\r
129 status = inSection(4);\r
130 pattern = /.\011/;\r
131 string = 'a\011';\r
132 actualmatch = string.match(pattern);\r
133 expectedmatch = Array(string);\r
134 addThis();\r
135 \r
136 \r
137 /*\r
138  * Same as above, only now, for the second character of the string,\r
139  * use the Unicode escape '\u0009' instead of the octal escape '\011'\r
140  */\r
141 status = inSection(5);\r
142 pattern = /.\011/;\r
143 string = 'a\u0009';\r
144 actualmatch = string.match(pattern);\r
145 expectedmatch = Array(string);\r
146 addThis();\r
147 \r
148 \r
149 /*\r
150  * Same as above, only now  for the second character of the string,\r
151  * use the hex escape '\x09' instead of the octal escape '\011'\r
152  */\r
153 status = inSection(6);\r
154 pattern = /.\011/;\r
155 string = 'a\x09';\r
156 actualmatch = string.match(pattern);\r
157 expectedmatch = Array(string);\r
158 addThis();\r
159 \r
160 \r
161 /*\r
162  * Same as above, only now  for the second character of the string,\r
163  * use the escape '\t' instead of the octal escape '\011'\r
164  */\r
165 status = inSection(7);\r
166 pattern = /.\011/;\r
167 string = 'a\t';\r
168 actualmatch = string.match(pattern);\r
169 expectedmatch = Array(string);\r
170 addThis();\r
171 \r
172 \r
173 /*\r
174  * Return to the string from Section 1.\r
175  *\r
176  * Unlike Section 1, use the RegExp() function to create the\r
177  * regexp pattern: null character followed by the string '11'.\r
178  *\r
179  * Since this is exactly what the string is, we should get a match -\r
180  */\r
181 status = inSection(8);\r
182 string = 'a' + String.fromCharCode(0) + '11';\r
183 pattern = RegExp(string);\r
184 actualmatch = string.match(pattern);\r
185 expectedmatch = Array(string);\r
186 addThis();\r
187 \r
188 \r
189 \r
190 \r
191 //-------------------------------------------------------------------------------------------------\r
192 test();\r
193 //-------------------------------------------------------------------------------------------------\r
194 \r
195 \r
196 \r
197 function addThis()\r
198 {\r
199   statusmessages[i] = status;\r
200   patterns[i] = pattern;\r
201   strings[i] = string;\r
202   actualmatches[i] = actualmatch;\r
203   expectedmatches[i] = expectedmatch;\r
204   i++;\r
205 }\r
206 \r
207 \r
208 function test()\r
209 {\r
210   enterFunc ('test');\r
211   printBugNumber (bug);\r
212   printStatus (summary);\r
213   testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);\r
214   exitFunc ('test');\r
215 }\r