Debian Codegraph @

rhino/testsrc/tests/ecma_3/RegExp/15.10.3.1-1.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 * 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 gTestfile = '15.10.3.1-1.js';
34 var BUGNUMBER = '61266';
35 var summary = 'Passing (RegExp object,flag) to RegExp() function';
36 var statprefix = 'RegExp(new RegExp(';
37 var comma = ', '; var singlequote = "'"; var closeparens = '))';
38 var cnSUCCESS = 'RegExp() returned the supplied RegExp object';
39 var cnFAILURE = 'RegExp() did NOT return the supplied RegExp object';
40 var i = -1; var j = -1; var s = ''; var f = '';
41 var obj = {};
42 var status = ''; var actual = ''; var expect = '';
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 flags[3] = undefined;
60
61
62
63 //-------------------------------------------------------------------------------------------------
64 test();
65 //-------------------------------------------------------------------------------------------------
66
67
68 function test()
69 {
70 enterFunc ('test');
71 printBugNumber(BUGNUMBER);
72 printStatus (summary);
73
74 for (i in patterns)
75 {
76 s = patterns[i];
77
78 for (j in flags)
79 {
80 f = flags[j];
81 status = getStatus(s, f);
82 obj = new RegExp(s, f);
83
84 actual = (obj == RegExp(obj))? cnSUCCESS : cnFAILURE;
85 expect = cnSUCCESS;
86 reportCompare (expect, actual, status);
87 }
88 }
89
90 exitFunc ('test');
91 }
92
93
94 function getStatus(regexp, flag)
95 {
96 return (statprefix + quote(regexp) + comma + flag + closeparens);
97 }
98
99
100 function quote(text)
101 {
102 return (singlequote + text + singlequote);
103 }