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

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

Issue 2630233003: [regexp] Create property on result for each named capture (Closed)
Patch Set: Remove unused CaptureNameMapOffset Created 3 years, 11 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
« src/regexp/regexp-parser.cc ('K') | « 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
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --harmony-regexp-named-captures 5 // Flags: --harmony-regexp-named-captures
6 6
7 // Malformed named captures. 7 // Malformed named captures.
8 assertThrows("/(?<>a)/u"); // Empty name. 8 assertThrows("/(?<>a)/u"); // Empty name.
9 assertThrows("/(?<aa)/u"); // Unterminated name. 9 assertThrows("/(?<aa)/u"); // Unterminated name.
10 assertThrows("/(?<42a>a)/u"); // Name starting with digits. 10 assertThrows("/(?<42a>a)/u"); // Name starting with digits.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 // Nested groups. 68 // Nested groups.
69 assertEquals(["bab", "bab", "ab", "b"], "bab".match(/(?<a>.(?<b>.(?<c>.)))/u)); 69 assertEquals(["bab", "bab", "ab", "b"], "bab".match(/(?<a>.(?<b>.(?<c>.)))/u));
70 70
71 // Reference inside group. 71 // Reference inside group.
72 assertEquals(["bab", "b"], "bab".match(/(?<a>\k<a>\w)../u)); 72 assertEquals(["bab", "b"], "bab".match(/(?<a>\k<a>\w)../u));
73 73
74 // Reference before group. 74 // Reference before group.
75 assertEquals(["bab", "b"], "bab".match(/\k<a>(?<a>b)\w\k<a>/u)); 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)); 76 assertEquals(["bab", "b", "a"], "bab".match(/(?<b>b)\k<a>(?<a>a)\k<b>/u));
77
78 // Reference properties.
79 assertEquals("a", /(?<a>a)(?<b>b)\k<a>/u.exec("aba").a);
80 assertEquals("b", /(?<a>a)(?<b>b)\k<a>/u.exec("aba").b);
81 assertEquals(undefined, /(?<a>a)(?<b>b)\k<a>/u.exec("aba").c);
82 assertFalse(/(?<a>a)(?<b>b)\k<a>/u.exec("aba").hasOwnProperty("c"));
83 assertEquals(undefined, /(?<a>a)(?<b>b)\k<a>|(?<c>c)/u.exec("aba").c);
84 assertTrue(/(?<a>a)(?<b>b)\k<a>|(?<c>c)/u.exec("aba").hasOwnProperty("c"));
85
86 // Unicode names.
87 assertEquals("a", /(?<π>a)/u.exec("bab").π);
88 assertEquals("a", /(?<\u{03C0}>a)/u.exec("bab").\u03C0);
89 assertEquals("a", /(?<$>a)/u.exec("bab").$);
90 assertEquals("a", /(?<_>a)/u.exec("bab")._);
91 assertEquals("a", /(?<$𐒤>a)/u.exec("bab").$𐒤);
92 assertEquals("a", /(?<_\u200C>a)/u.exec("bab")._\u200C);
93 assertEquals("a", /(?<_\u200D>a)/u.exec("bab")._\u200D);
94 assertEquals("a", /(?<ಠ_ಠ>a)/u.exec("bab").ಠ_ಠ);
95 assertThrows('/(?<❤>a)/u');
96 assertThrows('/(?<𐒤>a)/u'); // ID_Continue but not ID_Start.
Dan Ehrenberg 2017/01/18 18:19:04 For syntax error tests, how about assertThrows('/(
jgruber 2017/01/19 15:59:12 Done.
97
98 // Capture name conflicts.
99 assertThrows(() => /(?<index>a)/u);
100 assertThrows(() => /(?<input>a)/u);
101 assertThrows(() => /(?<length>a)/u);
102
103 assertEquals("a", /(?<inde>a)/u.exec("a").inde);
104 assertEquals("a", /(?<indexi>a)/u.exec("a").indexi);
OLDNEW
« src/regexp/regexp-parser.cc ('K') | « src/regexp/regexp-parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698