1// Copyright 2013 the V8 project authors. All rights reserved.
2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions
6// are met:
7// 1.  Redistributions of source code must retain the above copyright
8//     notice, this list of conditions and the following disclaimer.
9// 2.  Redistributions in binary form must reproduce the above copyright
10//     notice, this list of conditions and the following disclaimer in the
11//     documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24description("This page tests handling of parenthetical assertions.");
25
26var regex1 = /(x)(?=\1)x/;
27shouldBe("regex1.exec('xx')", "['xx','x']");
28
29var regex2 = /(.*?)a(?!(a+)b\2c)\2(.*)/;
30shouldBe("regex2.exec('baaabaac')", "['baaabaac','ba',undefined,'abaac']");
31
32var regex3 = /(?=(a+?))(\1ab)/;
33shouldBe("regex3.exec('aaab')", "['aab','a','aab']");
34
35var regex4 = /(?=(a+?))(\1ab)/;
36shouldBe("regex4.exec('aaab')", "['aab','a','aab']");
37
38var regex5 = /^P([1-6])(?=\1)([1-6])$/;
39shouldBe("regex5.exec('P11')", "['P11','1','1']");
40
41var regex6 = /(([a-c])b*?\2)*/;
42shouldBe("regex6.exec('ababbbcbc')", "['ababb','bb','b']");
43
44var regex7 = /(x)(?=x)x/;
45shouldBe("regex7.exec('xx')", "['xx','x']");
46
47var regex8 = /(x)(\1)/;
48shouldBe("regex8.exec('xx')", "['xx','x','x']");
49
50var regex9 = /(x)(?=\1)x/;
51shouldBeNull("regex9.exec('xy')");
52
53var regex10 = /(x)(?=x)x/;
54shouldBeNull("regex10.exec('xy')");
55
56var regex11 = /(x)(\1)/;
57shouldBeNull("regex11.exec('xy')");
58
59var regex12 = /(x)(?=\1)x/;
60shouldBeNull("regex12.exec('x')");
61shouldBe("regex12.exec('xx')", "['xx','x']");
62shouldBe("regex12.exec('xxy')", "['xx','x']");
63
64var regex13 = /(x)zzz(?=\1)x/;
65shouldBe("regex13.exec('xzzzx')", "['xzzzx','x']");
66shouldBe("regex13.exec('xzzzxy')", "['xzzzx','x']");
67
68var regex14 = /(a)\1(?=(b*c))bc/;
69shouldBe("regex14.exec('aabc')", "['aabc','a','bc']");
70shouldBe("regex14.exec('aabcx')", "['aabc','a','bc']");
71
72var regex15 = /(a)a(?=(b*c))bc/;
73shouldBe("regex15.exec('aabc')", "['aabc','a','bc']");
74shouldBe("regex15.exec('aabcx')", "['aabc','a','bc']");
75
76var regex16 = /a(?=(b*c))bc/;
77shouldBeNull("regex16.exec('ab')");
78shouldBe("regex16.exec('abc')", "['abc','bc']");
79
80var regex17 = /(?=((?:ab)*))a/;
81shouldBe("regex17.exec('ab')", "['a','ab']");
82shouldBe("regex17.exec('abc')", "['a','ab']");
83
84var regex18 = /(?=((?:xx)*))x/;
85shouldBe("regex18.exec('x')", "['x','']");
86shouldBe("regex18.exec('xx')", "['x','xx']");
87shouldBe("regex18.exec('xxx')", "['x','xx']");
88
89var regex19 = /(?=((xx)*))x/;
90shouldBe("regex19.exec('x')", "['x','',undefined]");
91shouldBe("regex19.exec('xx')", "['x','xx','xx']");
92shouldBe("regex19.exec('xxx')", "['x','xx','xx']");
93
94var regex20 = /(?=(xx))+x/;
95shouldBeNull("regex20.exec('x')");
96shouldBe("regex20.exec('xx')", "['x','xx']");
97shouldBe("regex20.exec('xxx')", "['x','xx']");
98
99var regex21 = /(?=a+b)aab/;
100shouldBe("regex21.exec('aab')", "['aab']");
101
102var regex22 = /(?!(u|m{0,}g+)u{1,}|2{2,}!1%n|(?!K|(?=y)|(?=ip))+?)(?=(?=(((?:7))*?)*?))p/m;
103shouldBe("regex22.exec('55up')", "null");
104
105var regex23 = /(?=(a)b|c?)()*d/;
106shouldBe("regex23.exec('ax')", "null");
107
108var regex24 = /(?=a|b?)c/;
109shouldBe("regex24.exec('x')", "null");
110