|
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 |
|
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: christine@netscape.com |
|
13 * Date: 19 February 1999 |
|
14 * |
|
15 * Revised: 02 August 2002 |
|
16 * Author: pschwartau@netscape.com |
|
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 ecma_3/RegExp/octal-002.js for an elaboration. |
|
30 * |
|
31 */ |
|
32 var SECTION = "RegExp/octal-003.js"; |
|
33 var VERSION = "ECMA_2"; |
|
34 var TITLE = "RegExp patterns that contain OctalEscapeSequences"; |
|
35 var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346132"; |
|
36 |
|
37 startTest(); |
|
38 |
|
39 AddRegExpCases( /.\011/, "/\\011/", "a" + String.fromCharCode(0) + "11", "a\\011", 0, null ); |
|
40 |
|
41 test(); |
|
42 |
|
43 function AddRegExpCases( |
|
44 regexp, str_regexp, pattern, str_pattern, index, matches_array ) { |
|
45 |
|
46 // prevent a runtime error |
|
47 |
|
48 if ( regexp.exec(pattern) == null || matches_array == null ) { |
|
49 AddTestCase( |
|
50 regexp + ".exec(" + str_pattern +")", |
|
51 matches_array, |
|
52 regexp.exec(pattern) ); |
|
53 |
|
54 return; |
|
55 } |
|
56 AddTestCase( |
|
57 str_regexp + ".exec(" + str_pattern +").length", |
|
58 matches_array.length, |
|
59 regexp.exec(pattern).length ); |
|
60 |
|
61 AddTestCase( |
|
62 str_regexp + ".exec(" + str_pattern +").index", |
|
63 index, |
|
64 regexp.exec(pattern).index ); |
|
65 |
|
66 AddTestCase( |
|
67 str_regexp + ".exec(" + str_pattern +").input", |
|
68 escape(pattern), |
|
69 escape(regexp.exec(pattern).input) ); |
|
70 |
|
71 AddTestCase( |
|
72 str_regexp + ".exec(" + str_pattern +").toString()", |
|
73 matches_array.toString(), |
|
74 escape(regexp.exec(pattern).toString()) ); |
|
75 |
|
76 var limit = matches_array.length > regexp.exec(pattern).length |
|
77 ? matches_array.length |
|
78 : regexp.exec(pattern).length; |
|
79 |
|
80 for ( var matches = 0; matches < limit; matches++ ) { |
|
81 AddTestCase( |
|
82 str_regexp + ".exec(" + str_pattern +")[" + matches +"]", |
|
83 matches_array[matches], |
|
84 escape(regexp.exec(pattern)[matches]) ); |
|
85 } |
|
86 |
|
87 } |