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

Side by Side Diff: test/mjsunit/harmony/unicode-regexp-zero-length.js

Issue 1630633002: [regexp] correctly advance zero length matches for global/unicode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@backrefbounds
Patch Set: fix test Created 4 years, 10 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
« no previous file with comments | « src/runtime/runtime-strings.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 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));
OLDNEW
« no previous file with comments | « src/runtime/runtime-strings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698