1// Copyright 2011 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6//     * Redistributions of source code must retain the above copyright
7//       notice, this list of conditions and the following disclaimer.
8//     * Redistributions in binary form must reproduce the above
9//       copyright notice, this list of conditions and the following
10//       disclaimer in the documentation and/or other materials provided
11//       with the distribution.
12//     * Neither the name of Google Inc. nor the names of its
13//       contributors may be used to endorse or promote products derived
14//       from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28var foo = "lsdfj sldkfj sdklfj læsdfjl sdkfjlsdk fjsdl fjsdljskdj flsj flsdkj flskd regexp: /foobar/\nldkfj sdlkfj sdkl";
29for(var i = 0; i < 1000; i++) {
30  assertTrue(/^([a-z]+): (.*)/.test(foo.substring(foo.indexOf("regexp:"))));
31  assertEquals("regexp", RegExp.$1, "RegExp.$1");
32}
33
34var re = /^(((N({)?)|(R)|(U)|(V)|(B)|(H)|(n((n)|(r)|(v)|(h))?)|(r(r)?)|(v)|(b((n)|(b))?)|(h))|((Y)|(A)|(E)|(o(u)?)|(p(u)?)|(q(u)?)|(s)|(t)|(u)|(w)|(x(u)?)|(y)|(z)|(a((T)|(A)|(L))?)|(c)|(e)|(f(u)?)|(g(u)?)|(i)|(j)|(l)|(m(u)?)))+/;
35var r = new RegExp(re)
36var str = "_Avtnennan gunzvmu pubExnY nEvln vaTxh rmuhguhaTxnY_".slice(1,-1);
37str = str + str;
38assertTrue(r.test(str));
39assertTrue(r.test(str));
40var re = /x/;
41assertEquals("a.yb", "_axyb_".slice(1,-1).replace(re, "."));
42re.compile("y");
43assertEquals("ax.b", "_axyb_".slice(1,-1).replace(re, "."));
44re.compile("(x)");
45assertEquals(["x", "x"], re.exec("_axyb_".slice(1,-1)));
46re.compile("(y)");
47assertEquals(["y", "y"], re.exec("_axyb_".slice(1,-1)));
48
49for(var i = 0; i < 100; i++) {
50  var a = "aaaaaaaaaaaaaaaaaaaaaaaabbaacabbabaaaaabbaaaabbac".slice(24,-1);
51  var b = "bbaacabbabaaaaabbaaaabba" + a;
52  // The first time, the cons string will be flattened and handled by the
53  // runtime system.
54  assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(b));
55  // The second time, the cons string is already flattened and will be
56  // handled by generated code.
57  assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(b));
58  assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(a));
59  assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(a));
60}
61
62var c = "ABCDEFGHIJKLMN".slice(2,-2);
63var d = "ABCDEF\u1234GHIJKLMN".slice(2,-2);
64var e = "ABCDEFGHIJKLMN".slice(0,-2);
65assertTrue(/^C.*L$/.test(c));
66assertTrue(/^C.*L$/.test(c));
67assertTrue(/^C.*L$/.test(d));
68assertTrue(/^C.*L$/.test(d));
69assertTrue(/^A\w{10}L$/.test(e));
70assertTrue(/^A\w{10}L$/.test(e));
71
72var e = "qui-opIasd-fghjklzx-cvbn-mqwer-tyuio-pasdf-ghIjkl-zx".slice(6,-6);
73var e_split = e.split("-");
74assertEquals(e_split[0], "Iasd");
75assertEquals(e_split[1], "fghjklzx");
76assertEquals(e_split[6], "ghI");
77