Debian Codegraph @

rhino/testsrc/tests/ecma_3/RegExp/15.10.4.1-5-n.js

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