blob: 56b9c5eb8cb3059680e43d2bd6046675e1229f52 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001// Copyright 2016 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
Ben Murdoch61f157c2016-09-16 13:49:30 +01005// Flags: --harmony-regexp-lookbehind
Ben Murdoch097c5b22016-05-18 11:27:45 +01006
7// Back reference does not end in the middle of a surrogate pair.
8function replace(string) {
9 return string.replace(/L/g, "\ud800")
10 .replace(/l/g, "\ud801")
11 .replace(/T/g, "\udc00")
12 .replace(/\./g, "[^]");
13}
14
15function test(expectation, regexp_source, subject) {
16 if (expectation !== null) expectation = expectation.map(replace);
17 subject = replace(subject);
18 regexp_source = replace(regexp_source);
19 assertEquals(expectation, new RegExp(regexp_source, "u").exec(subject));
20}
21
22// Back reference does not end in the middle of a surrogate pair.
23test(null, "(L)\\1", "LLT");
24test(["LLTLl", "L", "l"], "(L).*\\1(.)", "LLTLl");
25test(null, "(aL).*\\1", "aLaLT");
26test(["aLaLTaLl", "aL", "l"], "(aL).*\\1(.)", "aLaLTaLl");
27
28var s = "TabcLxLTabcLxTabcLTyTabcLz";
29test([s, "TabcL", "z"], "([^x]+).*\\1(.)", s);
30
31// Back reference does not start in the middle of a surrogate pair.
32test(["TLTabTc", "T", "c"], "(T).*\\1(.)", "TLTabTc");
33
34// Lookbehinds.
35test(null, "(?<=\\1(T)x)", "LTTx");
36test(["", "b", "T"], "(?<=(.)\\2.*(T)x)", "bTaLTTx");
37test(null, "(?<=\\1.*(L)x)", "LTLx");
38test(["", "b", "L"], "(?<=(.)\\2.*(L)x)", "bLaLTLx");
39
40
41test(null, "([^x]+)x*\\1", "LxLT");
42test(null, "([^x]+)x*\\1", "TxLT");
43test(null, "([^x]+)x*\\1", "LTxL");
44test(null, "([^x]+)x*\\1", "LTxT");
45test(null, "([^x]+)x*\\1", "xLxLT");
46test(null, "([^x]+)x*\\1", "xTxLT");
47test(null, "([^x]+)x*\\1", "xLTxL");
48test(null, "([^x]+)x*\\1", "xLTxT");
49test(null, "([^x]+)x*\\1", "xxxLxxLTxx");
50test(null, "([^x]+)x*\\1", "xxxTxxLTxx");
51test(null, "([^x]+)x*\\1", "xxxLTxxLxx");
52test(null, "([^x]+)x*\\1", "xxxLTxxTxx");
53test(["LTTxxLTT", "LTT"], "([^x]+)x*\\1", "xxxLTTxxLTTxx");