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

Side by Side Diff: test/mjsunit/harmony/regexp-lookbehind.js

Issue 1418963009: Experimental support for RegExp lookbehind. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fixed test cases Created 5 years, 1 month 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
« test/cctest/test-regexp.cc ('K') | « test/cctest/test-regexp.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --harmony-regexp-lookbehind
6
7 // Simple fixed-length matches.
8 assertEquals(["a"], "a".match(/^.(?<=a)/));
9 assertNull("b".match(/^.(?<=a)/));
10 assertEquals(["foo"], "foo1".match(/^f..(?<=.oo)/));
11 assertEquals(["foo"], "foo2".match(/^f\w\w(?<=\woo)/));
12 assertNull("boo".match(/^f\w\w(?<=\woo)/));
13 assertNull("fao".match(/^f\w\w(?<=\woo)/));
14 assertNull("foa".match(/^f\w\w(?<=\woo)/));
15 assertEquals(["def"], "abcdef".match(/(?<=abc)\w\w\w/));
16 assertEquals(["def"], "abcdef".match(/(?<=a.c)\w\w\w/));
17 assertEquals(["def"], "abcdef".match(/(?<=a\wc)\w\w\w/));
18 assertEquals(["cde"], "abcdef".match(/(?<=a[a-z])\w\w\w/));
19 assertEquals(["def"], "abcdef".match(/(?<=a[a-z][a-z])\w\w\w/));
20 assertEquals(["def"], "abcdef".match(/(?<=a[a-z]{2})\w\w\w/));
21 assertEquals(["bcd"], "abcdef".match(/(?<=a{1})\w\w\w/));
22 assertEquals(["cde"], "abcdef".match(/(?<=a{1}b{1})\w\w\w/));
23 assertEquals(["def"], "abcdef".match(/(?<=a{1}[a-z]{2})\w\w\w/));
24
25 // Variable-length matches.
26 assertEquals(["def"], "abcdef".match(/(?<=[a|b|c]*)[^a|b|c]{3}/));
27 assertEquals(["def"], "abcdef".match(/(?<=\w*)[^a|b|c]{3}/));
28
29 // Start of line matches.
30 assertEquals(["def"], "abcdef".match(/(?<=^abc)def/));
31 assertEquals(["def"], "abcdef".match(/(?<=^[a-c]{3})def/));
32 assertEquals(["def"], "xyz\nabcdef".match(/(?<=^[a-c]{3})def/m));
33 assertNull("abcdef".match(/(?<=^[^a-c]{3})def/));
34 assertNull("foooo".match(/"^foooo(?<=^o+)$/));
35 assertNull("foooo".match(/"^foooo(?<=^o*)$/));
36 assertEquals(["foo"], "foo".match(/^foo(?<=^fo+)$/));
37 assertEquals(["foooo"], "foooo".match(/^foooo(?<=^fo*)/));
38 assertEquals(["foo", "f"], "foo".match(/^(f)oo(?<=^\1o+)$/));
39
40 // Word boundary matches.
41 assertEquals(["def"], "abc def".match(/(?<=\b)[d-f]{3}/));
42 assertEquals(["def"], "ab cdef".match(/(?<=\B)\w{3}/));
43 assertEquals(["def"], "ab cdef".match(/(?<=\B)(?<=c(?<=\w))\w{3}/));
44 assertNull("abcdef".match(/(?<=\b)[d-f]{3}/));
45
46 // Negative lookbehind.
47 assertEquals(["abc"], "abcdef".match(/(?<!abc)\w\w\w/));
48 assertEquals(["abc"], "abcdef".match(/(?<!a.c)\w\w\w/));
49 assertEquals(["abc"], "abcdef".match(/(?<!a\wc)\w\w\w/));
50 assertEquals(["abc"], "abcdef".match(/(?<!a[a-z])\w\w\w/));
51 assertEquals(["abc"], "abcdef".match(/(?<!a[a-z]{2})\w\w\w/));
52 assertNull("abcdef".match(/(?<!abc)def/));
53 assertNull("abcdef".match(/(?<!a.c)def/));
54 assertNull("abcdef".match(/(?<!a\wc)def/));
55 assertNull("abcdef".match(/(?<!a[a-z][a-z])def/));
56 assertNull("abcdef".match(/(?<!a[a-z]{2})def/));
57 assertNull("abcdef".match(/(?<!a{1}b{1})cde/));
58 assertNull("abcdef".match(/(?<!a{1}[a-z]{2})def/));
59
60 // Capturing matches.
61 assertEquals(["def", "c"], "abcdef".match(/(?<=(c))def/));
62 assertEquals(["def", "bc"], "abcdef".match(/(?<=(\w{2}))def/));
63 assertEquals(["def", "bc", "c"], "abcdef".match(/(?<=(\w(\w)))def/));
64 assertEquals(["def", "a"], "abcdef".match(/(?<=(\w){3})def/));
65 assertEquals(["d", "bc", undefined], "abcdef".match(/(?<=(bc)|(cd))./));
66 assertEquals(["c", "a", undefined],
67 "abcdef".match(/(?<=([ab]{1,2})\D|(abc))\w/));
68 assertEquals(["ab", "a", "b"], "abcdef".match(/\D(?<=([ab]+))(\w)/));
69 assertEquals(["c", "d"], "abcdef".match(/(?<=b|c)\w/g));
70 assertEquals(["cd", "ef"], "abcdef".match(/(?<=[b-e])\w{2}/g));
71
72 // Captures inside negative lookbehind. (They never capture.)
73 assertEquals(["de", undefined], "abcdef".match(/(?<!(^|[ab]))\w{2}/));
74
75 // Nested lookaround.
76 assertEquals(["ef"], "abcdef".match(/(?<=ab(?=c)\wd)\w\w/));
77 assertEquals(["ef", "bc"], "abcdef".match(/(?<=a(?=([^a]{2})d)\w{3})\w\w/));
78 assertEquals(["ef", "bc"],
79 "abcdef".match(/(?<=a(?=([bc]{2}(?<!a{2}))d)\w{3})\w\w/));
80 assertNull("abcdef".match(/(?<=a(?=([bc]{2}(?<!a*))d)\w{3})\w\w/));
81 assertEquals(["faaa"], "faaao".match(/^faaao?(?<=^f[oa]+(?=o))/));
82
83 // Back references.
84 assertEquals(["b", "b", "bb"], "abb".match(/(.)(?<=(\1\1))/));
85 assertEquals(["B", "B", "bB"], "abB".match(/(.)(?<=(\1\1))/i));
86 assertEquals(["aB", "aB", "a"], "aabAaBa".match(/((\w)\w)(?<=\1\2\1)/i));
87 assertEquals(["Ba", "Ba", "a"], "aabAaBa".match(/(\w(\w))(?<=\1\2\1)/i));
88 assertEquals(["b", "b", "B"], "abaBbAa".match(/(?=(\w))(?<=(\1))./i));
89 assertEquals(["foo", "'", "foo"], " 'foo' ".match(/(?<=(.))(\w+)(?=\1)/));
90 assertEquals(["foo", "\"", "foo"], " \"foo\" ".match(/(?<=(.))(\w+)(?=\1)/));
91 assertNull(" .foo\" ".match(/(?<=(.))(\w+)(?=\1)/));
92 assertNull("ab".match(/(.)(?<=\1\1\1)/));
93 assertNull("abb".match(/(.)(?<=\1\1\1)/));
94 assertEquals(["b", "b"], "abbb".match(/(.)(?<=\1\1\1)/));
95 assertNull("ab".match(/(..)(?<=\1\1\1)/));
96 assertNull("abb".match(/(..)(?<=\1\1\1)/));
97 assertNull("aabb".match(/(..)(?<=\1\1\1)/));
98 assertNull("abab".match(/(..)(?<=\1\1\1)/));
99 assertNull("fabxbab".match(/(..)(?<=\1\1\1)/));
100 assertNull("faxabab".match(/(..)(?<=\1\1\1)/));
101 assertEquals(["ab", "ab"], "fababab".match(/(..)(?<=\1\1\1)/));
102
103 // Back references to captures inside the lookbehind.
104 assertEquals(["d", "C"], "abcCd".match(/(?<=\1(\w))d/i));
105 assertEquals(["d", "x"], "abxxd".match(/(?<=\1([abx]))d/));
106 assertEquals(["c", "ab"], "ababc".match(/(?<=\1(\w+))c/));
107 assertEquals(["c", "b"], "ababbc".match(/(?<=\1(\w+))c/));
108 assertNull("ababdc".match(/(?<=\1(\w+))c/));
109 assertEquals(["c", "abab"], "ababc".match(/(?<=(\w+)\1)c/));
110
111 // Alternations are tried left to right,
112 // and we do not backtrack into a lookbehind.
113 assertEquals(["xabcd", "cd", ""], "xabcd".match(/.*(?<=(..|...|....))(.*)/));
114 assertEquals(["xabcd", "bcd", ""], "xabcd".match(/.*(?<=(xx|...|....))(.*)/));
115 assertEquals(["xxabcd", "bcd", ""], "xxabcd".match(/.*(?<=(xx|...))(.*)/));
116 assertEquals(["xxabcd", "xx", "abcd"], "xxabcd".match(/.*(?<=(xx|xxx))(.*)/));
117
118 // We do not backtrack into a lookbehind.
119 // The lookbehind captures "abc" so that \1 does not match. We do not backtrack
120 // to capture only "bc" in the lookbehind.
121 assertNull("abcdbc".match(/(?<=([abc]+)).\1/));
122
123 // Misc
124 assertNull("abcdef".match(/(?<=$abc)def/));
125 assertEquals(["foo"], "foo".match(/^foo(?<=foo)$/));
126 assertEquals(["foo"], "foo".match(/^f.o(?<=foo)$/));
127 assertNull("fno".match(/^f.o(?<=foo)$/));
128 assertNull("foo".match(/^foo(?<!foo)$/));
129 assertNull("foo".match(/^f.o(?<!foo)$/));
130 assertEquals(["fno"], "fno".match(/^f.o(?<!foo)$/));
131 assertEquals(["foooo"], "foooo".match(/^foooo(?<=fo+)$/));
132 assertEquals(["foooo"], "foooo".match(/^foooo(?<=fo*)$/));
OLDNEW
« test/cctest/test-regexp.cc ('K') | « test/cctest/test-regexp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698