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

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

Issue 2050343002: [regexp] Experimental support for regexp named captures (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove invalid DCHECKs Created 4 years, 6 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/regexp/regexp-parser.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.
Yang 2016/06/13 13:38:00 Can we also some parsing-related tests in cctest/t
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-named-captures
6
7 // Malformed named captures.
8 assertThrows("/(?<>a)/u"); // Empty name.
9 assertThrows("/(?<aa)/u"); // Unterminated name.
10 assertThrows("/(?<42a>a)/u"); // Name starting with digits.
11 assertThrows("/(?<:a>a)/u"); // Name starting with invalid char.
12 assertThrows("/(?<a:>a)/u"); // Name containing with invalid char.
13 assertThrows("/(?<a>a)(?<a>a)/u"); // Duplicate name.
14 assertThrows("/(?<a>a)(?<b>b)(?<a>a)/u"); // Duplicate name.
15 assertThrows("/\\k<a>/u"); // Invalid reference.
16 assertThrows("/(?<a>a)\\k<ab>/u"); // Invalid reference.
17 assertThrows("/(?<ab>a)\\k<a>/u"); // Invalid reference.
18 assertThrows("/\\k<a>(?<ab>a)/u"); // Invalid reference.
19
20 // Fallback behavior in non-unicode mode.
21 assertThrows("/(?<>a)/");
22 assertThrows("/(?<aa)/");
23 assertThrows("/(?<42a>a)/");
24 assertThrows("/(?<:a>a)/");
25 assertThrows("/(?<a:>a)/");
26 assertThrows("/(?<a>a)(?<a>a)/");
27 assertThrows("/(?<a>a)(?<b>b)(?<a>a)/");
28 assertThrows("/(?<a>a)\\k<ab>/");
29 assertThrows("/(?<ab>a)\\k<a>/");
30
31 assertEquals(["k<a>"], "xxxk<a>xxx".match(/\k<a>/));
32 assertEquals(["k<a"], "xxxk<a>xxx".match(/\k<a/));
33
34 // Basic named groups.
35 assertEquals(["a", "a"], "bab".match(/(?<a>a)/u));
36 assertEquals(["a", "a"], "bab".match(/(?<a42>a)/u));
37 assertEquals(["a", "a"], "bab".match(/(?<_>a)/u));
38 assertEquals(["a", "a"], "bab".match(/(?<$>a)/u));
39 assertEquals(["bab", "a"], "bab".match(/.(?<$>a)./u));
40 assertEquals(["bab", "a", "b"], "bab".match(/.(?<a>a)(.)/u));
41 assertEquals(["bab", "a", "b"], "bab".match(/.(?<a>a)(?<b>.)/u));
42 assertEquals(["bab", "ab"], "bab".match(/.(?<a>\w\w)/u));
43 assertEquals(["bab", "bab"], "bab".match(/(?<a>\w\w\w)/u));
44 assertEquals(["bab", "ba", "b"], "bab".match(/(?<a>\w\w)(?<b>\w)/u));
45
46 assertEquals("bab".match(/(a)/u), "bab".match(/(?<a>a)/u));
47 assertEquals("bab".match(/(a)/u), "bab".match(/(?<a42>a)/u));
48 assertEquals("bab".match(/(a)/u), "bab".match(/(?<_>a)/u));
49 assertEquals("bab".match(/(a)/u), "bab".match(/(?<$>a)/u));
50 assertEquals("bab".match(/.(a)./u), "bab".match(/.(?<$>a)./u));
51 assertEquals("bab".match(/.(a)(.)/u), "bab".match(/.(?<a>a)(.)/u));
52 assertEquals("bab".match(/.(a)(.)/u), "bab".match(/.(?<a>a)(?<b>.)/u));
53 assertEquals("bab".match(/.(\w\w)/u), "bab".match(/.(?<a>\w\w)/u));
54 assertEquals("bab".match(/(\w\w\w)/u), "bab".match(/(?<a>\w\w\w)/u));
55 assertEquals("bab".match(/(\w\w)(\w)/u), "bab".match(/(?<a>\w\w)(?<b>\w)/u));
56
57 assertEquals(["bab", "b"], "bab".match(/(?<b>b).\1/u));
58 assertEquals(["baba", "b", "a"], "baba".match(/(.)(?<a>a)\1\2/u));
59 assertEquals(["baba", "b", "a", "b", "a"],
60 "baba".match(/(.)(?<a>a)(?<b>\1)(\2)/u));
61 assertEquals(["<a", "<"], "<a".match(/(?<lt><)a/u));
62 assertEquals([">a", ">"], ">a".match(/(?<gt>>)a/u));
63
64 // Named references.
65 assertEquals(["bab", "b"], "bab".match(/(?<b>.).\k<b>/u));
66 assertNull("baa".match(/(?<b>.).\k<b>/u));
67
68 // Nested groups.
69 assertEquals(["bab", "bab", "ab", "b"], "bab".match(/(?<a>.(?<b>.(?<c>.)))/u));
70
71 // Reference inside group.
72 assertEquals(["bab", "b"], "bab".match(/(?<a>\k<a>\w)../u));
73
74 // Reference before group.
75 assertEquals(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/u));
76 assertEquals(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/u));
OLDNEW
« no previous file with comments | « src/regexp/regexp-parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698