1 /* ***** BEGIN LICENSE BLOCK *****
\r
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
\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
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
14 * The Original Code is JavaScript Engine testing utilities.
\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
22 * pschwartau@netscape.com
\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
36 * ***** END LICENSE BLOCK *****
\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
43 * See http://bugzilla.mozilla.org/show_bug.cgi?id=141078
\r
44 * for a reference on octal escape sequences in regexps.
\r
47 * We will use the identities '\011' === '\u0009' === '\x09' === '\t'
\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
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
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
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
62 //-----------------------------------------------------------------------------
\r
65 var summary = 'Testing regexps containing octal escape sequences';
\r
67 var statusmessages = new Array();
\r
69 var patterns = new Array();
\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
79 * Test a string containing the null character '\0' followed by the string '11'
\r
81 * 'a' + String.fromCharCode(0) + '11';
\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
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
90 status = inSection(1);
\r
92 string = 'a' + String.fromCharCode(0) + '11';
\r
93 actualmatch = string.match(pattern);
\r
94 expectedmatch = null;
\r
99 * Try same thing with 'xx' in place of '11'.
\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
104 status = inSection(2);
\r
106 string = 'a' + String.fromCharCode(0) + 'xx';
\r
107 actualmatch = string.match(pattern);
\r
108 expectedmatch = Array(string);
\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
117 status = inSection(3);
\r
120 actualmatch = string.match(pattern);
\r
121 expectedmatch = Array(string);
\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
129 status = inSection(4);
\r
132 actualmatch = string.match(pattern);
\r
133 expectedmatch = Array(string);
\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
141 status = inSection(5);
\r
143 string = 'a\u0009';
\r
144 actualmatch = string.match(pattern);
\r
145 expectedmatch = Array(string);
\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
153 status = inSection(6);
\r
156 actualmatch = string.match(pattern);
\r
157 expectedmatch = Array(string);
\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
165 status = inSection(7);
\r
168 actualmatch = string.match(pattern);
\r
169 expectedmatch = Array(string);
\r
174 * Return to the string from Section 1.
\r
176 * Unlike Section 1, use the RegExp() function to create the
\r
177 * regexp pattern: null character followed by the string '11'.
\r
179 * Since this is exactly what the string is, we should get a match -
\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
191 //-------------------------------------------------------------------------------------------------
\r
193 //-------------------------------------------------------------------------------------------------
\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
210 enterFunc ('test');
\r
211 printBugNumber (bug);
\r
212 printStatus (summary);
\r
213 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
\r