]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/RegExp/15.10.3.1-1.js
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
19 * Contributor(s): pschwartau@netscape.com
20 * Date: 26 November 2000
23 * SUMMARY: Passing (RegExp object, flag) to RegExp() function.
24 * This test arose from Bugzilla bug 61266. The ECMA3 section is:
26 * 15.10.3 The RegExp Constructor Called as a Function
28 * 15.10.3.1 RegExp(pattern, flags)
30 * If pattern is an object R whose [[Class]] property is "RegExp"
31 * and flags is undefined, then return R unchanged. Otherwise
32 * call the RegExp constructor (section 15.10.4.1), passing it the
33 * pattern and flags arguments and return the object constructed
34 * by that constructor.
37 * The current test will check the first scenario outlined above:
39 * "pattern" is itself a RegExp object R
40 * "flags" is undefined
42 * The flags parameter will be undefined in the sense of not being
43 * provided. We check that RegExp(R) returns R -
45 //-------------------------------------------------------------------------------------------------
47 var summary
= 'Passing (RegExp object,flag) to RegExp() function';
48 var statprefix
= 'RegExp(new RegExp(';
49 var comma
= ', '; var singlequote
= "'"; var closeparens
= '))';
50 var cnSUCCESS
= 'RegExp() returned the supplied RegExp object';
51 var cnFAILURE
= 'RegExp() did NOT return the supplied RegExp object';
52 var i
= -1; var j
= -1; var s
= ''; var f
= '';
54 var status
= ''; var actual
= ''; var expect
= '';
55 var patterns
= new Array();
56 var flags
= new Array();
59 // various regular expressions to try -
62 patterns
[2] = '(.*)(3-1)\s\w';
63 patterns
[3] = '(.*)(...)\\s\\w';
64 patterns
[4] = '[^A-Za-z0-9_]';
65 patterns
[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
67 // various flags to try -
75 //-------------------------------------------------------------------------------------------------
77 //-------------------------------------------------------------------------------------------------
84 printStatus (summary
);
93 status
= getStatus(s
, f
);
94 obj
= new RegExp(s
, f
);
96 actual
= (obj
== RegExp(obj
))? cnSUCCESS : cnFAILURE
;
98 reportCompare (expect
, actual
, status
);
106 function getStatus(regexp
, flag
)
108 return (statprefix
+ quote(regexp
) + comma
+ flag
+ closeparens
);
114 return (singlequote
+ text
+ singlequote
);