Debian Codegraph @

rhino/testsrc/tests/ecma_3/RegExp/15.10.3.1-2.js

raw symbols SCIP
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 * This test is identical to test 15.10.3.1-1.js, except here we do:
30 *
31 * RegExp(R, undefined);
32 *
33 * instead of:
34 *
35 * RegExp(R);
36 *
37 *
38 * We check that RegExp(R, undefined) returns R -
39 */
40 //-----------------------------------------------------------------------------
41 var gTestfile = '15.10.3.1-2.js';
42 var BUGNUMBER = '61266';
43 var summary = 'Passing (RegExp object,flag) to RegExp() function';
44 var statprefix = 'RegExp(new RegExp(';
45 var comma = ', '; var singlequote = "'"; var closeparens = '))';
46 var cnSUCCESS = 'RegExp() returned the supplied RegExp object';
47 var cnFAILURE = 'RegExp() did NOT return the supplied RegExp object';
48 var i = -1; var j = -1; var s = ''; var f = '';
49 var obj = {};
50 var status = ''; var actual = ''; var expect = '';
51 var patterns = new Array();
52 var flags = new Array();
53
54
55 // various regular expressions to try -
56 patterns[0] = '';
57 patterns[1] = 'abc';
58 patterns[2] = '(.*)(3-1)\s\w';
59 patterns[3] = '(.*)(...)\\s\\w';
60 patterns[4] = '[^A-Za-z0-9_]';
61 patterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)';
62
63 // various flags to try -
64 flags[0] = 'i';
65 flags[1] = 'g';
66 flags[2] = 'm';
67 flags[3] = undefined;
68
69
70
71 //-------------------------------------------------------------------------------------------------
72 test();
73 //-------------------------------------------------------------------------------------------------
74
75
76 function test()
77 {
78 enterFunc ('test');
79 printBugNumber(BUGNUMBER);
80 printStatus (summary);
81
82 for (i in patterns)
83 {
84 s = patterns[i];
85
86 for (j in flags)
87 {
88 f = flags[j];
89 status = getStatus(s, f);
90 obj = new RegExp(s, f);
91
92 actual = (obj == RegExp(obj, undefined))? cnSUCCESS : cnFAILURE ;
93 expect = cnSUCCESS;
94 reportCompare (expect, actual, status);
95 }
96 }
97
98 exitFunc ('test');
99 }
100
101
102 function getStatus(regexp, flag)
103 {
104 return (statprefix + quote(regexp) + comma + flag + closeparens);
105 }
106
107
108 function quote(text)
109 {
110 return (singlequote + text + singlequote);
111 }