OLD | NEW |
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 77 |
78 // Reference properties. | 78 // Reference properties. |
79 assertEquals("a", /(?<a>a)(?<b>b)\k<a>/u.exec("aba").group.a); | 79 assertEquals("a", /(?<a>a)(?<b>b)\k<a>/u.exec("aba").groups.a); |
80 assertEquals("b", /(?<a>a)(?<b>b)\k<a>/u.exec("aba").group.b); | 80 assertEquals("b", /(?<a>a)(?<b>b)\k<a>/u.exec("aba").groups.b); |
81 assertEquals(undefined, /(?<a>a)(?<b>b)\k<a>/u.exec("aba").group.c); | 81 assertEquals(undefined, /(?<a>a)(?<b>b)\k<a>/u.exec("aba").groups.c); |
82 assertEquals(undefined, /(?<a>a)(?<b>b)\k<a>|(?<c>c)/u.exec("aba").group.c); | 82 assertEquals(undefined, /(?<a>a)(?<b>b)\k<a>|(?<c>c)/u.exec("aba").groups.c); |
83 | 83 |
84 // Unicode names. | 84 // Unicode names. |
85 assertEquals("a", /(?<π>a)/u.exec("bab").group.π); | 85 assertEquals("a", /(?<π>a)/u.exec("bab").groups.π); |
86 assertEquals("a", /(?<\u{03C0}>a)/u.exec("bab").group.\u03C0); | 86 assertEquals("a", /(?<\u{03C0}>a)/u.exec("bab").groups.\u03C0); |
87 assertEquals("a", /(?<$>a)/u.exec("bab").group.$); | 87 assertEquals("a", /(?<$>a)/u.exec("bab").groups.$); |
88 assertEquals("a", /(?<_>a)/u.exec("bab").group._); | 88 assertEquals("a", /(?<_>a)/u.exec("bab").groups._); |
89 assertEquals("a", /(?<$𐒤>a)/u.exec("bab").group.$𐒤); | 89 assertEquals("a", /(?<$𐒤>a)/u.exec("bab").groups.$𐒤); |
90 assertEquals("a", /(?<_\u200C>a)/u.exec("bab").group._\u200C); | 90 assertEquals("a", /(?<_\u200C>a)/u.exec("bab").groups._\u200C); |
91 assertEquals("a", /(?<_\u200D>a)/u.exec("bab").group._\u200D); | 91 assertEquals("a", /(?<_\u200D>a)/u.exec("bab").groups._\u200D); |
92 assertEquals("a", /(?<ಠ_ಠ>a)/u.exec("bab").group.ಠ_ಠ); | 92 assertEquals("a", /(?<ಠ_ಠ>a)/u.exec("bab").groups.ಠ_ಠ); |
93 assertThrows('/(?<❤>a)/u', SyntaxError); | 93 assertThrows('/(?<❤>a)/u', SyntaxError); |
94 assertThrows('/(?<𐒤>a)/u', SyntaxError); // ID_Continue but not ID_Start. | 94 assertThrows('/(?<𐒤>a)/u', SyntaxError); // ID_Continue but not ID_Start. |
95 | 95 |
96 // The '__proto__' property on the groups object. | 96 // The '__proto__' property on the groups object. |
97 assertEquals(undefined, /(?<a>.)/u.exec("a").group.__proto__); | 97 assertEquals(undefined, /(?<a>.)/u.exec("a").groups.__proto__); |
98 assertEquals("a", /(?<__proto__>a)/u.exec("a").group.__proto__); | 98 assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__); |
OLD | NEW |