OLD | NEW |
| (Empty) |
1 // 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 | |
5 // Flags: --harmony-unicode-regexps | |
6 | |
7 var L = "\ud800"; | |
8 var T = "\udc00"; | |
9 var x = "x"; | |
10 | |
11 var r = /()/g; // Global, but not unicode. | |
12 // Zero-length matches do not advance lastIndex. | |
13 assertEquals(["", ""], r.exec(L + T + L + T)); | |
14 assertEquals(0, r.lastIndex); | |
15 r.lastIndex = 1; | |
16 assertEquals(["", ""], r.exec(L + T + L + T)); | |
17 assertEquals(1, r.lastIndex); | |
18 | |
19 var u = /()/ug; // Global and unicode. | |
20 // Zero-length matches do not advance lastIndex. | |
21 assertEquals(["", ""], u.exec(L + T + L + T)); | |
22 assertEquals(0, u.lastIndex); | |
23 u.lastIndex = 1; | |
24 assertEquals(["", ""], u.exec(L + T + L + T)); | |
25 assertEquals(0, u.lastIndex); | |
26 | |
27 // However, with repeating matches, lastIndex does not matter. | |
28 // We do advance from match to match. | |
29 r.lastIndex = 2; | |
30 assertEquals(x + L + x + T + x + L + x + T + x, | |
31 (L + T + L + T).replace(r, "x")); | |
32 | |
33 // With unicode flag, we advance code point by code point. | |
34 u.lastIndex = 3; | |
35 assertEquals(x + L + T + x + L + T + x, | |
36 (L + T + L + T).replace(u, "x")); | |
37 | |
38 // Test that exhausting the global match cache is fine. | |
39 assertEquals((x + L + T).repeat(1000) + x, | |
40 (L + T).repeat(1000).replace(u, "x")); | |
41 | |
42 // Same thing for RegExp.prototype.match. | |
43 r.lastIndex = 1; | |
44 assertEquals(["","","","",""], (L + T + L + T).match(r)); | |
45 r.lastIndex = 2; | |
46 assertEquals(["","","","",""], (L + T + L + T).match(r)); | |
47 | |
48 u.lastIndex = 1; | |
49 assertEquals(["","",""], (L + T + L + T).match(u)); | |
50 u.lastIndex = 2; | |
51 assertEquals(["","",""], (L + T + L + T).match(u)); | |
52 | |
53 var expected = []; | |
54 for (var i = 0; i <= 1000; i++) expected.push(""); | |
55 assertEquals(expected, (L + T).repeat(1000).match(u)); | |
56 | |
57 // Also test RegExp.prototype.@@split. | |
58 assertEquals(["\u{12345}"], "\u{12345}".split(/(?:)/u)); | |
OLD | NEW |