Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: test/mjsunit/string-slices-regexp.js

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Some more suggested changes. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2009 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 // Flags: --string-slices
29
30 //assertEquals('345"12345 6"1234567"123',
31 // '12345""12345 6""1234567""1234'.slice(2,-1).replace(/""/g, '"'));
32
33 var foo = "lsdfj sldkfj sdklfj læsdfjl sdkfjlsdk fjsdl fjsdljskdj flsj flsdkj fl skd regexp: /foobar/\nldkfj sdlkfj sdkl";
34 for(var i = 0; i < 1000; i++) {
35 assertTrue(/^([a-z]+): (.*)/.test(foo.substring(foo.indexOf("regexp:"))));
36 assertEquals("regexp", RegExp.$1, "RegExp.$1");
37 }
38
39 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)?)))+/;
40 var r = new RegExp(re)
41 var str = "_Avtnennan gunzvmu pubExnY nEvln vaTxh rmuhguhaTxnY_".slice(1,-1);
42 str = str + str;
43 assertTrue(r.test(str));
44 assertTrue(r.test(str));
45 var re = /x/;
46 assertEquals("a.yb", "_axyb_".slice(1,-1).replace(re, "."));
47 re.compile("y");
48 assertEquals("ax.b", "_axyb_".slice(1,-1).replace(re, "."));
49 re.compile("(x)");
50 assertEquals(["x", "x"], re.exec("_axyb_".slice(1,-1)));
51 re.compile("(y)");
52 assertEquals(["y", "y"], re.exec("_axyb_".slice(1,-1)));
53
54 for(var i = 0; i < 100; i++) {
55 var a = "aaaaaaaaaaaaaaaaaaaaaaaabbaacabbabaaaaabbaaaabbac".slice(24,-1);
56 var b = "bbaacabbabaaaaabbaaaabba" + a;
57 // The first time, the cons string will be flattened and handled by the
58 // runtime system.
59 assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(b));
60 // The second time, the cons string is already flattened and will be
61 // handled by generated code.
62 assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(b));
63 assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(a));
64 assertEquals(["bbaa", "a", "", "a"], /((\3|b)\2(a)){2,}/.exec(a));
65 }
66
67 var c = "ABCDEFGHIJKLMN".slice(2,-2);
68 var d = "ABCDEF\u1234GHIJKLMN".slice(2,-2);
69 var e = "ABCDEFGHIJKLMN".slice(0,-2);
70 assertTrue(/^C.*L$/.test(c));
71 assertTrue(/^C.*L$/.test(c));
72 assertTrue(/^C.*L$/.test(d));
73 assertTrue(/^C.*L$/.test(d));
74 assertTrue(/^A\w{10}L$/.test(e));
75 assertTrue(/^A\w{10}L$/.test(e));
76
77 var e = "qui-opIasd-fghjklzx-cvbn-mqwer-tyuio-pasdf-ghIjkl-zx".slice(6,-6);
78 var e_split = e.split("-");
79 assertEquals(e_split[0], "Iasd");
80 assertEquals(e_split[1], "fghjklzx");
81 assertEquals(e_split[6], "ghI");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698