Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_2 / RegExp / octal-003.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is JavaScript Engine testing utilities.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communication Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38
39 /**
40  *  File Name:          RegExp/octal-003.js
41  *  ECMA Section:       15.7.1
42  *  Description:        Based on ECMA 2 Draft 7 February 1999
43  *  Simple test cases for matching OctalEscapeSequences.
44  *  Author:             christine@netscape.com
45  *  Date:               19 February 1999
46  *
47  *  Revised:            02 August 2002
48  *  Author:             pschwartau@netscape.com
49  *
50  *  WHY:  the original test expected the regexp /.\011/
51  *        to match 'a' + String.fromCharCode(0) + '11'
52  *
53  *  This is incorrect: the string is a 4-character string consisting of
54  *  the characters <'a'>, <nul>, <'1'>, <'1'>. By contrast, the \011 in the
55  *  regexp should be parsed as a single token: it is the octal escape sequence
56  *  for the horizontal tab character '\t' === '\u0009' === '\x09' === '\011'.
57  *
58  *  So the regexp consists of 2 characters: <any-character>, <'\t'>.
59  *  There is no match between the regexp and the string.
60  *
61  *  See the testcase ecma_3/RegExp/octal-002.js for an elaboration.
62  *
63  */
64 var SECTION = "RegExp/octal-003.js";
65 var VERSION = "ECMA_2";
66 var TITLE   = "RegExp patterns that contain OctalEscapeSequences";
67 var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346132";
68
69 startTest();
70
71 AddRegExpCases( /.\011/, "/\\011/", "a" + String.fromCharCode(0) + "11", "a\\011", 0, null );
72
73 test();
74
75 function AddRegExpCases(
76   regexp, str_regexp, pattern, str_pattern, index, matches_array ) {
77
78   // prevent a runtime error
79
80   if ( regexp.exec(pattern) == null || matches_array == null ) {
81     AddTestCase(
82       regexp + ".exec(" + str_pattern +")",
83       matches_array,
84       regexp.exec(pattern) );
85
86     return;
87   }
88   AddTestCase(
89     str_regexp + ".exec(" + str_pattern +").length",
90     matches_array.length,
91     regexp.exec(pattern).length );
92
93   AddTestCase(
94     str_regexp + ".exec(" + str_pattern +").index",
95     index,
96     regexp.exec(pattern).index );
97
98   AddTestCase(
99     str_regexp + ".exec(" + str_pattern +").input",
100     escape(pattern),
101     escape(regexp.exec(pattern).input) );
102
103   AddTestCase(
104     str_regexp + ".exec(" + str_pattern +").toString()",
105     matches_array.toString(),
106     escape(regexp.exec(pattern).toString()) );
107
108   var limit = matches_array.length > regexp.exec(pattern).length
109     ? matches_array.length
110     : regexp.exec(pattern).length;
111
112   for ( var matches = 0; matches < limit; matches++ ) {
113     AddTestCase(
114       str_regexp + ".exec(" + str_pattern +")[" + matches +"]",
115       matches_array[matches],
116       escape(regexp.exec(pattern)[matches]) );
117   }
118
119 }