Debian Codegraph @

js/src/tests/non262/RegExp/octal-003.js

raw
1 /* -*- indent-tabs-mode: nil; js-indent-level: 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/. */
5
6
7 /**
8 * File Name: RegExp/octal-003.js
9 * ECMA Section: 15.7.1
10 * Description: Based on ECMA 2 Draft 7 February 1999
11 * Simple test cases for matching OctalEscapeSequences.
12 * Author: [email protected]
13 * Date: 19 February 1999
14 *
15 * Revised: 02 August 2002
16 * Author: [email protected]
17 *
18 * WHY: the original test expected the regexp /.\011/
19 * to match 'a' + String.fromCharCode(0) + '11'
20 *
21 * This is incorrect: the string is a 4-character string consisting of
22 * the characters <'a'>, <nul>, <'1'>, <'1'>. By contrast, the \011 in the
23 * regexp should be parsed as a single token: it is the octal escape sequence
24 * for the horizontal tab character '\t' === '\u0009' === '\x09' === '\011'.
25 *
26 * So the regexp consists of 2 characters: <any-character>, <'\t'>.
27 * There is no match between the regexp and the string.
28 *
29 * See the testcase non262/RegExp/octal-002.js for an elaboration.
30 *
31 */
32 var SECTION = "RegExp/octal-003.js";
33 var TITLE = "RegExp patterns that contain OctalEscapeSequences";
34 var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346132";
35
36 printBugNumber(BUGNUMBER);
37
38 AddRegExpCases( /.\011/, "/\\011/", "a" + String.fromCharCode(0) + "11", "a\\011", 0, null );
39
40 test();
41
42 function AddRegExpCases(
43 regexp, str_regexp, pattern, str_pattern, index, matches_array ) {
44
45 // prevent a runtime error
46
47 if ( regexp.exec(pattern) == null || matches_array == null ) {
48 AddTestCase(
49 regexp + ".exec(" + str_pattern +")",
50 matches_array,
51 regexp.exec(pattern) );
52
53 return;
54 }
55 AddTestCase(
56 str_regexp + ".exec(" + str_pattern +").length",
57 matches_array.length,
58 regexp.exec(pattern).length );
59
60 AddTestCase(
61 str_regexp + ".exec(" + str_pattern +").index",
62 index,
63 regexp.exec(pattern).index );
64
65 AddTestCase(
66 str_regexp + ".exec(" + str_pattern +").input",
67 escape(pattern),
68 escape(regexp.exec(pattern).input) );
69
70 AddTestCase(
71 str_regexp + ".exec(" + str_pattern +").toString()",
72 matches_array.toString(),
73 escape(regexp.exec(pattern).toString()) );
74
75 var limit = matches_array.length > regexp.exec(pattern).length
76 ? matches_array.length
77 : regexp.exec(pattern).length;
78
79 for ( var matches = 0; matches < limit; matches++ ) {
80 AddTestCase(
81 str_regexp + ".exec(" + str_pattern +")[" + matches +"]",
82 matches_array[matches],
83 escape(regexp.exec(pattern)[matches]) );
84 }
85
86 }