]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/ecma_3/RegExp/15.10.4.1-5-n.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma_3 / RegExp / 15.10.4.1-5-n.js
CommitLineData
b37bf2e1
A
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 a RegExp object to a RegExp() constructor.
24*This test arose from Bugzilla bug 61266. The ECMA3 section is:
25*
26* 15.10.4.1 new RegExp(pattern, flags)
27*
28* If pattern is an object R whose [[Class]] property is "RegExp" and
29* flags is undefined, then let P be the pattern used to construct R
30* and let F be the flags used to construct R. If pattern is an object R
31* whose [[Class]] property is "RegExp" and flags is not undefined,
32* then throw a TypeError exception. Otherwise, let P be the empty string
33* if pattern is undefined and ToString(pattern) otherwise, and let F be
34* the empty string if flags is undefined and ToString(flags) otherwise.
35*
36*
37*The current test will check the second scenario outlined above:
38*
39* "pattern" is itself a RegExp object R
40* "flags" is NOT undefined
41*
42* This should throw an exception ... we test for this.
43*
44*/
45//-------------------------------------------------------------------------------------------------
46var bug = '61266';
47var summary = 'Negative test: Passing (RegExp object, flag) to RegExp() constructor';
48var statprefix = 'Passing RegExp object on pattern ';
49var statsuffix = '; passing flag ';
50var cnFAILURE = 'Expected an exception to be thrown, but none was -';
51var singlequote = "'";
52var i = -1; var j = -1; var s = ''; var f = '';
53var obj1 = {}; var obj2 = {};
54var patterns = new Array();
55var flags = new Array();
56
57
58// various regular expressions to try -
59patterns[0] = '';
60patterns[1] = 'abc';
61patterns[2] = '(.*)(3-1)\s\w';
62patterns[3] = '(.*)(...)\\s\\w';
63patterns[4] = '[^A-Za-z0-9_]';
64patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
65
66// various flags to try -
67flags[0] = 'i';
68flags[1] = 'g';
69flags[2] = 'm';
70
71
72
73//-------------------------------------------------------------------------------------------------
74test();
75//-------------------------------------------------------------------------------------------------
76
77
78function test()
79{
80 enterFunc ('test');
81 printBugNumber (bug);
82 printStatus (summary);
83
84 for (i in patterns)
85 {
86 s = patterns[i];
87
88 for (j in flags)
89 {
90 f = flags[j];
91 printStatus(getStatus(s, f));
92 obj1 = new RegExp(s, f);
93 obj2 = new RegExp(obj1, f); // this should cause an exception
94
95 // WE SHOULD NEVER REACH THIS POINT -
96 reportFailure(cnFAILURE);
97 }
98 }
99
100 exitFunc ('test');
101}
102
103
104function getStatus(regexp, flag)
105{
106 return (statprefix + quote(regexp) + statsuffix + flag);
107}
108
109
110function quote(text)
111{
112 return (singlequote + text + singlequote);
113}