Debian Codegraph @

rhino/testsrc/tests/ecma_2/RegExp/octal-003.js

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