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
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/
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
15 * The Original Code is JavaScript Engine testing utilities.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corp.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
23 * pschwartau@netscape.com
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.
37 * ***** END LICENSE BLOCK ***** */
42 * SUMMARY: Testing regexps containing octal escape sequences
43 * This is an elaboration of mozilla/js/tests/ecma_2/RegExp/octal-003.js
45 * See http://bugzilla.mozilla.org/show_bug.cgi?id=141078
46 * for a reference on octal escape sequences in regexps.
49 * We will use the identities '\011' === '\u0009' === '\x09' === '\t'
51 * The first is an octal escape sequence (\(0-3)OO; O an octal digit).
52 * See ECMA-262 Edition 2, Section 7.7.4 "String Literals". These were
53 * dropped in Edition 3 but we support them for backward compatibility.
55 * The second is a Unicode escape sequence (\uHHHH; H a hex digit).
56 * Since octal 11 = hex 9, the two escapes define the same character.
58 * The third is a hex escape sequence (\xHH; H a hex digit).
59 * Since hex 09 = hex 0009, this defines the same character.
61 * The fourth is the familiar escape sequence for a horizontal tab,
62 * defined in the ECMA spec as having Unicode value \u0009.
64 //-----------------------------------------------------------------------------
66 var BUGNUMBER = 141078;
67 var summary = 'Testing regexps containing octal escape sequences';
69 var statusmessages = new Array();
71 var patterns = new Array();
73 var strings = new Array();
75 var actualmatches = new Array();
76 var expectedmatch = '';
77 var expectedmatches = new Array();
81 * Test a string containing the null character '\0' followed by the string '11'
83 * 'a' + String.fromCharCode(0) + '11';
85 * Note we can't simply write 'a\011', because '\011' would be interpreted
86 * as the octal escape sequence for the tab character (see above).
88 * We should get no match from the regexp /.\011/, because it should be
89 * looking for the octal escape sequence \011, i.e. the tab character -
92 status = inSection(1);
94 string = 'a' + String.fromCharCode(0) + '11';
95 actualmatch = string.match(pattern);
101 * Try same thing with 'xx' in place of '11'.
103 * Should get a match now, because the octal escape sequence in the regexp
104 * has been reduced from \011 to \0, and '\0' is present in the string -
106 status = inSection(2);
108 string = 'a' + String.fromCharCode(0) + 'xx';
109 actualmatch = string.match(pattern);
110 expectedmatch = Array(string);
115 * Same thing; don't use |String.fromCharCode(0)| this time.
116 * There is no ambiguity in '\0xx': it is the null character
117 * followed by two x's, no other interpretation is possible.
119 status = inSection(3);
122 actualmatch = string.match(pattern);
123 expectedmatch = Array(string);
128 * This one should produce a match. The two-character string
129 * 'a' + '\011' is duplicated in the pattern and test string:
131 status = inSection(4);
134 actualmatch = string.match(pattern);
135 expectedmatch = Array(string);
140 * Same as above, only now, for the second character of the string,
141 * use the Unicode escape '\u0009' instead of the octal escape '\011'
143 status = inSection(5);
146 actualmatch = string.match(pattern);
147 expectedmatch = Array(string);
152 * Same as above, only now for the second character of the string,
153 * use the hex escape '\x09' instead of the octal escape '\011'
155 status = inSection(6);
158 actualmatch = string.match(pattern);
159 expectedmatch = Array(string);
164 * Same as above, only now for the second character of the string,
165 * use the escape '\t' instead of the octal escape '\011'
167 status = inSection(7);
170 actualmatch = string.match(pattern);
171 expectedmatch = Array(string);
176 * Return to the string from Section 1.
178 * Unlike Section 1, use the RegExp() function to create the
179 * regexp pattern: null character followed by the string '11'.
181 * Since this is exactly what the string is, we should get a match -
183 status = inSection(8);
184 string = 'a' + String.fromCharCode(0) + '11';
185 pattern = RegExp(string);
186 actualmatch = string.match(pattern);
187 expectedmatch = Array(string);
193 //-------------------------------------------------------------------------------------------------
195 //-------------------------------------------------------------------------------------------------
201 statusmessages[i] = status;
202 patterns[i] = pattern;
204 actualmatches[i] = actualmatch;
205 expectedmatches[i] = expectedmatch;
213 printBugNumber(BUGNUMBER);
214 printStatus (summary);
215 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);