]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/RegExp/octal-002.js
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Netscape Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/NPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is JavaScript Engine testing utilities.
16 * The Initial Developer of the Original Code is Netscape Communications Corp.
17 * Portions created by the Initial Developer are Copyright (C) 2002
18 * the Initial Developer. All Rights Reserved.
20 * Contributor(s): pschwartau@netscape.com
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the NPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the NPL, the GPL or the LGPL.
34 * ***** END LICENSE BLOCK *****
38 * SUMMARY: Testing regexps containing octal escape sequences
39 * This is an elaboration of mozilla/js/tests/ecma_2/RegExp/octal-003.js
41 * See http://bugzilla.mozilla.org/show_bug.cgi?id=141078
42 * for a reference on octal escape sequences in regexps.
45 * We will use the identities '\011' === '\u0009' === '\x09' === '\t'
47 * The first is an octal escape sequence (\(0-3)OO; O an octal digit).
48 * See ECMA-262 Edition 2, Section 7.7.4 "String Literals". These were
49 * dropped in Edition 3 but we support them for backward compatibility.
51 * The second is a Unicode escape sequence (\uHHHH; H a hex digit).
52 * Since octal 11 = hex 9, the two escapes define the same character.
54 * The third is a hex escape sequence (\xHH; H a hex digit).
55 * Since hex 09 = hex 0009, this defines the same character.
57 * The fourth is the familiar escape sequence for a horizontal tab,
58 * defined in the ECMA spec as having Unicode value \u0009.
60 //-----------------------------------------------------------------------------
63 var summary
= 'Testing regexps containing octal escape sequences';
65 var statusmessages
= new Array();
67 var patterns
= new Array();
69 var strings
= new Array();
71 var actualmatches
= new Array();
72 var expectedmatch
= '';
73 var expectedmatches
= new Array();
77 * Test a string containing the null character '\0' followed by the string '11'
79 * 'a' + String.fromCharCode(0) + '11';
81 * Note we can't simply write 'a\011', because '\011' would be interpreted
82 * as the octal escape sequence for the tab character (see above).
84 * We should get no match from the regexp /.\011/, because it should be
85 * looking for the octal escape sequence \011, i.e. the tab character -
88 status
= inSection(1);
90 string
= 'a' + String
.fromCharCode(0) + '11';
91 actualmatch
= string
.match(pattern
);
97 * Try same thing with 'xx' in place of '11'.
99 * Should get a match now, because the octal escape sequence in the regexp
100 * has been reduced from \011 to \0, and '\0' is present in the string -
102 status
= inSection(2);
104 string
= 'a' + String
.fromCharCode(0) + 'xx';
105 actualmatch
= string
.match(pattern
);
106 expectedmatch
= Array(string
);
111 * Same thing; don't use |String.fromCharCode(0)| this time.
112 * There is no ambiguity in '\0xx': it is the null character
113 * followed by two x's, no other interpretation is possible.
115 status
= inSection(3);
118 actualmatch
= string
.match(pattern
);
119 expectedmatch
= Array(string
);
124 * This one should produce a match. The two-character string
125 * 'a' + '\011' is duplicated in the pattern and test string:
127 status
= inSection(4);
130 actualmatch
= string
.match(pattern
);
131 expectedmatch
= Array(string
);
136 * Same as above, only now, for the second character of the string,
137 * use the Unicode escape '\u0009' instead of the octal escape '\011'
139 status
= inSection(5);
142 actualmatch
= string
.match(pattern
);
143 expectedmatch
= Array(string
);
148 * Same as above, only now for the second character of the string,
149 * use the hex escape '\x09' instead of the octal escape '\011'
151 status
= inSection(6);
154 actualmatch
= string
.match(pattern
);
155 expectedmatch
= Array(string
);
160 * Same as above, only now for the second character of the string,
161 * use the escape '\t' instead of the octal escape '\011'
163 status
= inSection(7);
166 actualmatch
= string
.match(pattern
);
167 expectedmatch
= Array(string
);
172 * Return to the string from Section 1.
174 * Unlike Section 1, use the RegExp() function to create the
175 * regexp pattern: null character followed by the string '11'.
177 * Since this is exactly what the string is, we should get a match -
179 status
= inSection(8);
180 string
= 'a' + String
.fromCharCode(0) + '11';
181 pattern
= RegExp(string
);
182 actualmatch
= string
.match(pattern
);
183 expectedmatch
= Array(string
);
189 //-------------------------------------------------------------------------------------------------
191 //-------------------------------------------------------------------------------------------------
197 statusmessages
[i
] = status
;
198 patterns
[i
] = pattern
;
200 actualmatches
[i
] = actualmatch
;
201 expectedmatches
[i
] = expectedmatch
;
209 printBugNumber (bug
);
210 printStatus (summary
);
211 testRegExp(statusmessages
, patterns
, strings
, actualmatches
, expectedmatches
);