Home | History | Annotate | Download | only in mjsunit
      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 
     28 var foo = "lsdfj sldkfj sdklfj lsdfjl sdkfjlsdk fjsdl fjsdljskdj flsj flsdkj flskd regexp: /foobar/\nldkfj sdlkfj sdkl";
     29 for(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 
     34 var 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)?)))+/;
     35 var r = new RegExp(re)
     36 var str = "_Avtnennan gunzvmu pubExnY nEvln vaTxh rmuhguhaTxnY_".slice(1,-1);
     37 str = str + str;
     38 assertTrue(r.test(str));
     39 assertTrue(r.test(str));
     40 var re = /x/;
     41 assertEquals("a.yb", "_axyb_".slice(1,-1).replace(re, "."));
     42 re.compile("y");
     43 assertEquals("ax.b", "_axyb_".slice(1,-1).replace(re, "."));
     44 re.compile("(x)");
     45 assertEquals(["x", "x"], re.exec("_axyb_".slice(1,-1)));
     46 re.compile("(y)");
     47 assertEquals(["y", "y"], re.exec("_axyb_".slice(1,-1)));
     48 
     49 for(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 
     62 var c = "ABCDEFGHIJKLMN".slice(2,-2);
     63 var d = "ABCDEF\u1234GHIJKLMN".slice(2,-2);
     64 var e = "ABCDEFGHIJKLMN".slice(0,-2);
     65 assertTrue(/^C.*L$/.test(c));
     66 assertTrue(/^C.*L$/.test(c));
     67 assertTrue(/^C.*L$/.test(d));
     68 assertTrue(/^C.*L$/.test(d));
     69 assertTrue(/^A\w{10}L$/.test(e));
     70 assertTrue(/^A\w{10}L$/.test(e));
     71 
     72 var e = "qui-opIasd-fghjklzx-cvbn-mqwer-tyuio-pasdf-ghIjkl-zx".slice(6,-6);
     73 var e_split = e.split("-");
     74 assertEquals(e_split[0], "Iasd");
     75 assertEquals(e_split[1], "fghjklzx");
     76 assertEquals(e_split[6], "ghI");
     77