Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_2 / RegExp / properties-002.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/properties-002.js
41  *  ECMA Section:       15.7.6.js
42  *  Description:        Based on ECMA 2 Draft 7 February 1999
43  *
44  *  Author:             christine@netscape.com
45  *  Date:               19 February 1999
46  */
47 //-----------------------------------------------------------------------------
48 var SECTION = "RegExp/properties-002.js";
49 var VERSION = "ECMA_2";
50 var TITLE   = "Properties of RegExp Instances";
51 var BUGNUMBER ="124339";
52
53 startTest();
54
55 re_1 = /\cA?/g;
56 re_1.lastIndex = Math.pow(2,31);
57 AddRegExpCases( re_1, "\\cA?", true, false, false, Math.pow(2,31) );
58
59 re_2 = /\w*/i;
60 re_2.lastIndex = Math.pow(2,32) -1;
61 AddRegExpCases( re_2, "\\w*", false, true, false, Math.pow(2,32)-1 );
62
63 re_3 = /\*{0,80}/m;
64 re_3.lastIndex = Math.pow(2,31) -1;
65 AddRegExpCases( re_3, "\\*{0,80}", false, false, true, Math.pow(2,31) -1 );
66
67 re_4 = /^./gim;
68 re_4.lastIndex = Math.pow(2,30) -1;
69 AddRegExpCases( re_4, "^.", true, true, true, Math.pow(2,30) -1 );
70
71 re_5 = /\B/;
72 re_5.lastIndex = Math.pow(2,30);
73 AddRegExpCases( re_5, "\\B", false, false, false, Math.pow(2,30) );
74
75 /*
76  * Brendan: "need to test cases Math.pow(2,32) and greater to see
77  * whether they round-trip." Reason: thanks to the work done in
78  * http://bugzilla.mozilla.org/show_bug.cgi?id=124339, lastIndex
79  * is now stored as a double instead of a uint32 (unsigned integer).
80  *
81  * Note 2^32 -1 is the upper bound for uint32's, but doubles can go
82  * all the way up to Number.MAX_VALUE. So that's why we need cases
83  * between those two numbers.
84  *
85  */
86 re_6 = /\B/;
87 re_6.lastIndex = Math.pow(2,32);
88 AddRegExpCases( re_6, "\\B", false, false, false, Math.pow(2,32) );
89
90 re_7 = /\B/;
91 re_7.lastIndex = Math.pow(2,32) + 1;
92 AddRegExpCases( re_7, "\\B", false, false, false, Math.pow(2,32) + 1 );
93
94 re_8 = /\B/;
95 re_8.lastIndex = Math.pow(2,32) * 2;
96 AddRegExpCases( re_8, "\\B", false, false, false, Math.pow(2,32) * 2 );
97
98 re_9 = /\B/;
99 re_9.lastIndex = Math.pow(2,40);
100 AddRegExpCases( re_9, "\\B", false, false, false, Math.pow(2,40) );
101
102 re_10 = /\B/;
103 re_10.lastIndex = Number.MAX_VALUE;
104 AddRegExpCases( re_10, "\\B", false, false, false, Number.MAX_VALUE );
105
106
107
108 //-----------------------------------------------------------------------------
109 test();
110 //-----------------------------------------------------------------------------
111
112
113
114 function AddRegExpCases( re, s, g, i, m, l ){
115
116   AddTestCase( re + ".test == RegExp.prototype.test",
117                true,
118                re.test == RegExp.prototype.test );
119
120   AddTestCase( re + ".toString == RegExp.prototype.toString",
121                true,
122                re.toString == RegExp.prototype.toString );
123
124   AddTestCase( re + ".contructor == RegExp.prototype.constructor",
125                true,
126                re.constructor == RegExp.prototype.constructor );
127
128   AddTestCase( re + ".compile == RegExp.prototype.compile",
129                true,
130                re.compile == RegExp.prototype.compile );
131
132   AddTestCase( re + ".exec == RegExp.prototype.exec",
133                true,
134                re.exec == RegExp.prototype.exec );
135
136   // properties
137
138   AddTestCase( re + ".source",
139                s,
140                re.source );
141
142   AddTestCase( re + ".toString()",
143                "/" + s +"/" + (g?"g":"") + (i?"i":"") +(m?"m":""),
144                re.toString() );
145
146   AddTestCase( re + ".global",
147                g,
148                re.global );
149
150   AddTestCase( re + ".ignoreCase",
151                i,
152                re.ignoreCase );
153
154   AddTestCase( re + ".multiline",
155                m,
156                re.multiline);
157
158   AddTestCase( re + ".lastIndex",
159                l,
160                re.lastIndex  );
161 }