• 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 ("[abc]*").exec("aaabbcccabcacbacabacbacab");
18assert (r == "aaabbcccabcacbacabacbacab");
19
20r = new RegExp ("[abc]*").exec("aaabbcccabdcacb");
21assert (r == "aaabbcccab");
22
23r = new RegExp ("[abc]*").exec("defghjklmnopqrstuvwxyz");
24assert (r == "");
25
26r = new RegExp ("[a-z]*").exec("abcdefghjklmnopqrstuvwxyz");
27assert (r == "abcdefghjklmnopqrstuvwxyz");
28
29r = new RegExp ("[A-Z]*").exec("abcdefghjklmnopqrstuvwxyz");
30assert (r == "");
31
32r = new RegExp ("[^a-z]*").exec("abcdefghjklmnopqrstuvwxyz");
33assert (r == "");
34
35r = new RegExp ("[^A-Z]*").exec("abcdefghjklmnopqrstuvwxyz");
36assert (r == "abcdefghjklmnopqrstuvwxyz");
37
38r = new RegExp ("\\d*").exec("abcdefghjklmnopqrstuvwxyz");
39assert (r == "");
40
41r = new RegExp ("\\D*").exec("abcdefghjklmnopqrstuvwxyz");
42assert (r == "abcdefghjklmnopqrstuvwxyz");
43
44r = new RegExp ("\\w*").exec("abcdefghjklmnopqrstuvwxyz");
45assert (r == "abcdefghjklmnopqrstuvwxyz");
46
47r = new RegExp ("\\W*").exec("abcdefghjklmnopqrstuvwxyz");
48assert (r == "");
49
50r = new RegExp ("\\s*").exec("abcdefghjklmnopqrstuvwxyz");
51assert (r == "");
52
53r = new RegExp ("\\S*").exec("abcdefghjklmnopqrstuvwxyz");
54assert (r == "abcdefghjklmnopqrstuvwxyz");
55
56r = new RegExp ("[\\d]*").exec("abcdefghjklmnopqrstuvwxyz");
57assert (r == "");
58
59r = new RegExp ("[\\D]*").exec("abcdefghjklmnopqrstuvwxyz");
60assert (r == "abcdefghjklmnopqrstuvwxyz");
61
62r = new RegExp ("[\\w]*").exec("abcdefghjklmnopqrstuvwxyz");
63assert (r == "abcdefghjklmnopqrstuvwxyz");
64
65r = new RegExp ("[\\W]*").exec("abcdefghjklmnopqrstuvwxyz");
66assert (r == "");
67
68r = new RegExp ("[\\s]*").exec("abcdefghjklmnopqrstuvwxyz");
69assert (r == "");
70
71r = new RegExp ("[\\S]*").exec("abcdefghjklmnopqrstuvwxyz");
72assert (r == "abcdefghjklmnopqrstuvwxyz");
73
74r = new RegExp ("[^\\d]*").exec("abcdefghjklmnopqrstuvwxyz");
75assert (r == "abcdefghjklmnopqrstuvwxyz");
76
77r = new RegExp ("[^\\D]*").exec("abcdefghjklmnopqrstuvwxyz");
78assert (r == "");
79
80r = new RegExp ("[^\\w]*").exec("abcdefghjklmnopqrstuvwxyz");
81assert (r == "");
82
83r = new RegExp ("[^\\W]*").exec("abcdefghjklmnopqrstuvwxyz");
84assert (r == "abcdefghjklmnopqrstuvwxyz");
85
86r = new RegExp ("[^\\s]*").exec("abcdefghjklmnopqrstuvwxyz");
87assert (r == "abcdefghjklmnopqrstuvwxyz");
88
89r = new RegExp ("[^\\S]*").exec("abcdefghjklmnopqrstuvwxyz");
90assert (r == "");
91
92r = new RegExp ("\\d*").exec("0123456789");
93assert (r == "0123456789");
94
95try
96{
97  r = new RegExp("[");
98  assert (false);
99}
100catch (e)
101{
102  assert (e instanceof SyntaxError);
103}
104
105try
106{
107  r = new RegExp("[\\");
108  assert (false);
109}
110catch (e)
111{
112  assert (e instanceof SyntaxError);
113}
114
115r = new RegExp ("^[\\u0061-\\u007a]+$").exec("abcdefghjklmnopqrstuvwxyz");
116assert (r == "abcdefghjklmnopqrstuvwxyz");
117
118r = new RegExp ("^[\\u0061-\\u007a]+").exec("abcdefghjklmnopqrstuvwxyz");
119assert (r == "abcdefghjklmnopqrstuvwxyz");
120
121r = new RegExp ("[\\u0061-\\u007a]+$").exec("abcdefghjklmnopqrstuvwxyz");
122assert (r == "abcdefghjklmnopqrstuvwxyz");
123
124r = new RegExp ("^[\\x61-\\x7a]+$").exec("abcdefghjklmnopqrstuvwxyz");
125assert (r == "abcdefghjklmnopqrstuvwxyz");
126
127r = new RegExp ("^[\\x61-\\x7a]+").exec("abcdefghjklmnopqrstuvwxyz");
128assert (r == "abcdefghjklmnopqrstuvwxyz");
129
130r = new RegExp ("[\\x61-\\x7a]+$").exec("abcdefghjklmnopqrstuvwxyz");
131assert (r == "abcdefghjklmnopqrstuvwxyz");
132
133r = new RegExp("[\\u0800-\\uffff]", "g");
134assert (r.test ("\uffff"));
135assert (!r.test ("\uffff"));
136
137r = new RegExp("[\0]");
138assert (r.test ("\0"));
139assert (!r.test ("0"));
140
141r = new RegExp("[\0-\1]");
142assert (r.test ("\1"));
143