1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
* License, v. 2.0. If a copy of the MPL was not distributed with this
4
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9
* SUMMARY: Testing regexps containing octal escape sequences
10
* This is an elaboration of mozilla/js/tests/ecma_2/RegExp/octal-003.js
12
* See http://bugzilla.mozilla.org/show_bug.cgi?id=141078
13
* for a reference on octal escape sequences in regexps.
16
* We will use the identities '\011' === '\u0009' === '\x09' === '\t'
18
* The first is an octal escape sequence (\(0-3)OO; O an octal digit).
19
* See ECMA-262 Edition 2, Section 7.7.4 "String Literals". These were
20
* dropped in Edition 3 but we support them for backward compatibility.
22
* The second is a Unicode escape sequence (\uHHHH; H a hex digit).
23
* Since octal 11 = hex 9, the two escapes define the same character.
25
* The third is a hex escape sequence (\xHH; H a hex digit).
26
* Since hex 09 = hex 0009, this defines the same character.
28
* The fourth is the familiar escape sequence for a horizontal tab,
29
* defined in the ECMA spec as having Unicode value \u0009.
31
//-----------------------------------------------------------------------------
33
var BUGNUMBER = 141078;
34
var summary = 'Testing regexps containing octal escape sequences';
36
var statusmessages = new Array();
38
var patterns = new Array();
40
var strings = new Array();
42
var actualmatches = new Array();
43
var expectedmatch = '';
44
var expectedmatches = new Array();
48
* Test a string containing the null character '\0' followed by the string '11'
50
* 'a' + String.fromCharCode(0) + '11';
52
* Note we can't simply write 'a\011', because '\011' would be interpreted
53
* as the octal escape sequence for the tab character (see above).
55
* We should get no match from the regexp /.\011/, because it should be
56
* looking for the octal escape sequence \011, i.e. the tab character -
59
status = inSection(1);
61
string = 'a' + String.fromCharCode(0) + '11';
62
actualmatch = string.match(pattern);
68
* Try same thing with 'xx' in place of '11'.
70
* Should get a match now, because the octal escape sequence in the regexp
71
* has been reduced from \011 to \0, and '\0' is present in the string -
73
status = inSection(2);
75
string = 'a' + String.fromCharCode(0) + 'xx';
76
actualmatch = string.match(pattern);
77
expectedmatch = Array(string);
82
* Same thing; don't use |String.fromCharCode(0)| this time.
83
* There is no ambiguity in '\0xx': it is the null character
84
* followed by two x's, no other interpretation is possible.
86
status = inSection(3);
89
actualmatch = string.match(pattern);
90
expectedmatch = Array(string);
95
* This one should produce a match. The two-character string
96
* 'a' + '\011' is duplicated in the pattern and test string:
98
status = inSection(4);
101
actualmatch = string.match(pattern);
102
expectedmatch = Array(string);
107
* Same as above, only now, for the second character of the string,
108
* use the Unicode escape '\u0009' instead of the octal escape '\011'
110
status = inSection(5);
113
actualmatch = string.match(pattern);
114
expectedmatch = Array(string);
119
* Same as above, only now for the second character of the string,
120
* use the hex escape '\x09' instead of the octal escape '\011'
122
status = inSection(6);
125
actualmatch = string.match(pattern);
126
expectedmatch = Array(string);
131
* Same as above, only now for the second character of the string,
132
* use the escape '\t' instead of the octal escape '\011'
134
status = inSection(7);
137
actualmatch = string.match(pattern);
138
expectedmatch = Array(string);
143
* Return to the string from Section 1.
145
* Unlike Section 1, use the RegExp() function to create the
146
* regexp pattern: null character followed by the string '11'.
148
* Since this is exactly what the string is, we should get a match -
150
status = inSection(8);
151
string = 'a' + String.fromCharCode(0) + '11';
152
pattern = RegExp(string);
153
actualmatch = string.match(pattern);
154
expectedmatch = Array(string);
160
//-------------------------------------------------------------------------------------------------
162
//-------------------------------------------------------------------------------------------------
168
statusmessages[i] = status;
169
patterns[i] = pattern;
171
actualmatches[i] = actualmatch;
172
expectedmatches[i] = expectedmatch;
180
printBugNumber(BUGNUMBER);
181
printStatus (summary);
182
testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);