• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15var r;
16
17r = new RegExp ();
18assert (r.source == "(?:)");
19assert (r.global == false);
20assert (r.ignoreCase == false);
21assert (r.multiline == false);
22
23r = new RegExp ("a");
24assert (r.source == "a");
25assert (r.global == false);
26assert (r.ignoreCase == false);
27assert (r.multiline == false);
28
29r = new RegExp ("a","gim");
30assert (r.source == "a");
31assert (r.global == true);
32assert (r.ignoreCase == true);
33assert (r.multiline == true);
34
35r = RegExp ("a");
36assert (r.source == "a");
37assert (r.global == false);
38assert (r.ignoreCase == false);
39assert (r.multiline == false);
40
41r = RegExp ("a","gim");
42assert (r.source == "a");
43assert (r.global == true);
44assert (r.ignoreCase == true);
45assert (r.multiline == true);
46
47var r2;
48
49r2 = RegExp (r);
50assert (r2.source == "a");
51assert (r2.global == true);
52assert (r2.ignoreCase == true);
53assert (r2.multiline == true);
54
55r2 = RegExp (r, undefined);
56assert (r2.source == "a");
57assert (r2.global == true);
58assert (r2.ignoreCase == true);
59assert (r2.multiline == true);
60
61r = /(?:)/;
62assert (r.source == "(?:)");
63assert (r.global == false);
64assert (r.ignoreCase == false);
65assert (r.multiline == false);
66
67r = /a/;
68assert (r.source == "a");
69assert (r.global == false);
70assert (r.ignoreCase == false);
71assert (r.multiline == false);
72
73r = /a/gim;
74assert (r.source == "a");
75assert (r.global == true);
76assert (r.ignoreCase == true);
77assert (r.multiline == true);
78
79/* The 'undefined' argument for the RegExp constructor should not be converted to string,
80 * and it should behave just like when there is no argument.
81 */
82r1 = new RegExp();
83r2 = new RegExp(undefined);
84var foo;
85r3 = new RegExp(foo)
86
87assert (r1.source === r2.source);
88assert (r2.source === r3.source);
89
90r = new RegExp ("foo", undefined);
91assert (r.source === "foo");
92assert (r.global === false);
93assert (r.ignoreCase === false);
94assert (r.multiline === false);
95
96r = new RegExp ("foo", void 0);
97assert (r.source === "foo");
98assert (r.global === false);
99assert (r.ignoreCase === false);
100assert (r.multiline === false);
101
102try {
103  new RegExp (undefined, "ii");
104  assert (false);
105} catch (e) {
106  assert (e instanceof SyntaxError);
107}
108
109try {
110  new RegExp ("", "gg");
111  assert (false);
112} catch (e) {
113  assert (e instanceof SyntaxError);
114}
115
116try {
117  new RegExp (void 0, "mm");
118  assert (false);
119} catch (e) {
120  assert (e instanceof SyntaxError);
121}
122
123r = new RegExp (undefined, undefined);
124assert (r.source == "(?:)");
125assert (r.global == false);
126assert (r.ignoreCase == false);
127assert (r.multiline == false);
128
129/* RegExp properties */
130assert (RegExp.length === 2);
131