|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * |
|
8 * Date: 26 November 2000 |
|
9 * |
|
10 * |
|
11 *SUMMARY: Passing a RegExp object to a RegExp() constructor. |
|
12 *This test arose from Bugzilla bug 61266. The ECMA3 section is: |
|
13 * |
|
14 * 15.10.4.1 new RegExp(pattern, flags) |
|
15 * |
|
16 * If pattern is an object R whose [[Class]] property is "RegExp" and |
|
17 * flags is undefined, then let P be the pattern used to construct R |
|
18 * and let F be the flags used to construct R. If pattern is an object R |
|
19 * whose [[Class]] property is "RegExp" and flags is not undefined, |
|
20 * then throw a TypeError exception. Otherwise, let P be the empty string |
|
21 * if pattern is undefined and ToString(pattern) otherwise, and let F be |
|
22 * the empty string if flags is undefined and ToString(flags) otherwise. |
|
23 * |
|
24 * |
|
25 *The current test will check the second scenario outlined above: |
|
26 * |
|
27 * "pattern" is itself a RegExp object R |
|
28 * "flags" is NOT undefined |
|
29 * |
|
30 * This should throw an exception ... we test for this. |
|
31 * |
|
32 */ |
|
33 |
|
34 //------------------------------------------------------------------------------------------------- |
|
35 var BUGNUMBER = '61266'; |
|
36 var summary = 'Negative test: Passing (RegExp object, flag) to RegExp() constructor'; |
|
37 var statprefix = 'Passing RegExp object on pattern '; |
|
38 var statsuffix = '; passing flag '; |
|
39 var cnFAILURE = 'Expected an exception to be thrown, but none was -'; |
|
40 var singlequote = "'"; |
|
41 var i = -1; var j = -1; var s = ''; var f = ''; |
|
42 var obj1 = {}; var obj2 = {}; |
|
43 var patterns = new Array(); |
|
44 var flags = new Array(); |
|
45 |
|
46 |
|
47 // various regular expressions to try - |
|
48 patterns[0] = ''; |
|
49 patterns[1] = 'abc'; |
|
50 patterns[2] = '(.*)(3-1)\s\w'; |
|
51 patterns[3] = '(.*)(...)\\s\\w'; |
|
52 patterns[4] = '[^A-Za-z0-9_]'; |
|
53 patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)'; |
|
54 |
|
55 // various flags to try - |
|
56 flags[0] = 'i'; |
|
57 flags[1] = 'g'; |
|
58 flags[2] = 'm'; |
|
59 |
|
60 |
|
61 DESCRIPTION = "Negative test: Passing (RegExp object, flag) to RegExp() constructor" |
|
62 EXPECTED = "error"; |
|
63 |
|
64 |
|
65 //------------------------------------------------------------------------------------------------- |
|
66 test(); |
|
67 //------------------------------------------------------------------------------------------------- |
|
68 |
|
69 |
|
70 function test() |
|
71 { |
|
72 enterFunc ('test'); |
|
73 printBugNumber(BUGNUMBER); |
|
74 printStatus (summary); |
|
75 |
|
76 for (i in patterns) |
|
77 { |
|
78 s = patterns[i]; |
|
79 |
|
80 for (j in flags) |
|
81 { |
|
82 f = flags[j]; |
|
83 printStatus(getStatus(s, f)); |
|
84 obj1 = new RegExp(s, f); |
|
85 obj2 = new RegExp(obj1, f); // this should cause an exception |
|
86 |
|
87 // WE SHOULD NEVER REACH THIS POINT - |
|
88 reportCompare('PASS', 'FAIL', cnFAILURE); |
|
89 } |
|
90 } |
|
91 |
|
92 exitFunc ('test'); |
|
93 } |
|
94 |
|
95 |
|
96 function getStatus(regexp, flag) |
|
97 { |
|
98 return (statprefix + quote(regexp) + statsuffix + flag); |
|
99 } |
|
100 |
|
101 |
|
102 function quote(text) |
|
103 { |
|
104 return (singlequote + text + singlequote); |
|
105 } |