|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
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 * Date: 26 November 2000 |
|
8 * |
|
9 * |
|
10 * SUMMARY: Passing (RegExp object, flag) to RegExp() function. |
|
11 * This test arose from Bugzilla bug 61266. The ECMA3 section is: |
|
12 * |
|
13 * 15.10.3 The RegExp Constructor Called as a Function |
|
14 * |
|
15 * 15.10.3.1 RegExp(pattern, flags) |
|
16 * |
|
17 * If pattern is an object R whose [[Class]] property is "RegExp" |
|
18 * and flags is undefined, then return R unchanged. Otherwise |
|
19 * call the RegExp constructor (section 15.10.4.1), passing it the |
|
20 * pattern and flags arguments and return the object constructed |
|
21 * by that constructor. |
|
22 * |
|
23 * |
|
24 * The current test will check the first scenario outlined above: |
|
25 * |
|
26 * "pattern" is itself a RegExp object R |
|
27 * "flags" is undefined |
|
28 * |
|
29 * The flags parameter will be undefined in the sense of not being |
|
30 * provided. We check that RegExp(R) returns R - |
|
31 */ |
|
32 //----------------------------------------------------------------------------- |
|
33 var BUGNUMBER = '61266'; |
|
34 var summary = 'Passing (RegExp object,flag) to RegExp() function'; |
|
35 var statprefix = 'RegExp(new RegExp('; |
|
36 var comma = ', '; var singlequote = "'"; var closeparens = '))'; |
|
37 var cnSUCCESS = 'RegExp() returned the supplied RegExp object'; |
|
38 var cnFAILURE = 'RegExp() did NOT return the supplied RegExp object'; |
|
39 var i = -1; var j = -1; var s = ''; var f = ''; |
|
40 var obj = {}; |
|
41 var status = ''; var actual = ''; var expect = ''; |
|
42 var patterns = new Array(); |
|
43 var flags = new Array(); |
|
44 |
|
45 |
|
46 // various regular expressions to try - |
|
47 patterns[0] = ''; |
|
48 patterns[1] = 'abc'; |
|
49 patterns[2] = '(.*)(3-1)\s\w'; |
|
50 patterns[3] = '(.*)(...)\\s\\w'; |
|
51 patterns[4] = '[^A-Za-z0-9_]'; |
|
52 patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)'; |
|
53 |
|
54 // various flags to try - |
|
55 flags[0] = 'i'; |
|
56 flags[1] = 'g'; |
|
57 flags[2] = 'm'; |
|
58 flags[3] = undefined; |
|
59 |
|
60 |
|
61 |
|
62 //------------------------------------------------------------------------------------------------- |
|
63 test(); |
|
64 //------------------------------------------------------------------------------------------------- |
|
65 |
|
66 |
|
67 function test() |
|
68 { |
|
69 enterFunc ('test'); |
|
70 printBugNumber(BUGNUMBER); |
|
71 printStatus (summary); |
|
72 |
|
73 for (i in patterns) |
|
74 { |
|
75 s = patterns[i]; |
|
76 |
|
77 for (j in flags) |
|
78 { |
|
79 f = flags[j]; |
|
80 status = getStatus(s, f); |
|
81 obj = new RegExp(s, f); |
|
82 |
|
83 actual = (obj == RegExp(obj))? cnSUCCESS : cnFAILURE; |
|
84 expect = cnSUCCESS; |
|
85 reportCompare (expect, actual, status); |
|
86 } |
|
87 } |
|
88 |
|
89 exitFunc ('test'); |
|
90 } |
|
91 |
|
92 |
|
93 function getStatus(regexp, flag) |
|
94 { |
|
95 return (statprefix + quote(regexp) + comma + flag + closeparens); |
|
96 } |
|
97 |
|
98 |
|
99 function quote(text) |
|
100 { |
|
101 return (singlequote + text + singlequote); |
|
102 } |