1/*
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/
6*
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.
11*
12* The Original Code is mozilla.org code.
13*
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
17* Rights Reserved.
18*
19* Contributor(s): pschwartau@netscape.com
20* Date: 26 November 2000
21*
22*
23* SUMMARY: Passing (RegExp object, flag) to RegExp() function.
24* This test arose from Bugzilla bug 61266. The ECMA3 section is:
25*
26* 15.10.3 The RegExp Constructor Called as a Function
27*
28*   15.10.3.1 RegExp(pattern, flags)
29*
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.
35*
36*
37* The current test will check the first scenario outlined above:
38*
39*   "pattern" is itself a RegExp object R
40*   "flags" is undefined
41*
42* This test is identical to test 15.10.3.1-1.js, except here we do:
43*
44*                     RegExp(R, undefined);
45*
46* instead of:
47*
48*                     RegExp(R);
49*
50*
51* We check that RegExp(R, undefined) returns R  -
52*/
53//-------------------------------------------------------------------------------------------------
54var bug = '61266';
55var summary = 'Passing (RegExp object,flag) to RegExp() function';
56var statprefix = 'RegExp(new RegExp(';
57var comma =  ', '; var singlequote = "'"; var closeparens = '))';
58var cnSUCCESS = 'RegExp() returned the supplied RegExp object';
59var cnFAILURE =  'RegExp() did NOT return the supplied RegExp object';
60var i = -1; var j = -1; var s = ''; var f = '';
61var obj = {};
62var status = ''; var actual = ''; var expect = '';
63var patterns = new Array();
64var flags = new Array();
65
66
67// various regular expressions to try -
68patterns[0] = '';
69patterns[1] = 'abc';
70patterns[2] = '(.*)(3-1)\s\w';
71patterns[3] = '(.*)(...)\\s\\w';
72patterns[4] = '[^A-Za-z0-9_]';
73patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
74
75// various flags to try -
76flags[0] = 'i';
77flags[1] = 'g';
78flags[2] = 'm';
79flags[3] = undefined;
80
81
82
83//-------------------------------------------------------------------------------------------------
84test();
85//-------------------------------------------------------------------------------------------------
86
87
88function test()
89{
90  enterFunc ('test');
91  printBugNumber (bug);
92  printStatus (summary);
93
94  for (i in patterns)
95  {
96    s = patterns[i];
97
98    for (j in flags)
99    {
100      f = flags[j];
101      status = getStatus(s, f);
102      obj = new RegExp(s, f);
103
104      actual = (obj == RegExp(obj, undefined))? cnSUCCESS : cnFAILURE ;
105      expect = cnSUCCESS;
106      reportCompare (expect, actual, status);
107    }
108  }
109
110  exitFunc ('test');
111}
112
113
114function getStatus(regexp, flag)
115{
116  return (statprefix  +  quote(regexp) +  comma  +   flag  +  closeparens);
117}
118
119
120function quote(text)
121{
122  return (singlequote  +  text  + singlequote);
123}