// Copyright 2015 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Flags: --harmony-regexp-named-captures // Malformed named captures. assertThrows("/(?<>a)/u"); // Empty name. assertThrows("/(?a)/u"); // Name starting with digits. assertThrows("/(?<:a>a)/u"); // Name starting with invalid char. assertThrows("/(?a)/u"); // Name containing with invalid char. assertThrows("/(?a)(?a)/u"); // Duplicate name. assertThrows("/(?a)(?b)(?a)/u"); // Duplicate name. assertThrows("/\\k/u"); // Invalid reference. assertThrows("/(?a)\\k/u"); // Invalid reference. assertThrows("/(?a)\\k/u"); // Invalid reference. assertThrows("/\\k(?a)/u"); // Invalid reference. // Fallback behavior in non-unicode mode. assertThrows("/(?<>a)/"); assertThrows("/(?a)/"); assertThrows("/(?<:a>a)/"); assertThrows("/(?a)/"); assertThrows("/(?a)(?a)/"); assertThrows("/(?a)(?b)(?a)/"); assertThrows("/(?a)\\k/"); assertThrows("/(?a)\\k/"); assertEquals(["k"], "xxxkxxx".match(/\k/)); assertEquals(["kxxx".match(/\ka)/u)); assertEquals(["a", "a"], "bab".match(/(?a)/u)); assertEquals(["a", "a"], "bab".match(/(?<_>a)/u)); assertEquals(["a", "a"], "bab".match(/(?<$>a)/u)); assertEquals(["bab", "a"], "bab".match(/.(?<$>a)./u)); assertEquals(["bab", "a", "b"], "bab".match(/.(?a)(.)/u)); assertEquals(["bab", "a", "b"], "bab".match(/.(?a)(?.)/u)); assertEquals(["bab", "ab"], "bab".match(/.(?\w\w)/u)); assertEquals(["bab", "bab"], "bab".match(/(?\w\w\w)/u)); assertEquals(["bab", "ba", "b"], "bab".match(/(?\w\w)(?\w)/u)); assertEquals("bab".match(/(a)/u), "bab".match(/(?a)/u)); assertEquals("bab".match(/(a)/u), "bab".match(/(?a)/u)); assertEquals("bab".match(/(a)/u), "bab".match(/(?<_>a)/u)); assertEquals("bab".match(/(a)/u), "bab".match(/(?<$>a)/u)); assertEquals("bab".match(/.(a)./u), "bab".match(/.(?<$>a)./u)); assertEquals("bab".match(/.(a)(.)/u), "bab".match(/.(?a)(.)/u)); assertEquals("bab".match(/.(a)(.)/u), "bab".match(/.(?a)(?.)/u)); assertEquals("bab".match(/.(\w\w)/u), "bab".match(/.(?\w\w)/u)); assertEquals("bab".match(/(\w\w\w)/u), "bab".match(/(?\w\w\w)/u)); assertEquals("bab".match(/(\w\w)(\w)/u), "bab".match(/(?\w\w)(?\w)/u)); assertEquals(["bab", "b"], "bab".match(/(?b).\1/u)); assertEquals(["baba", "b", "a"], "baba".match(/(.)(?a)\1\2/u)); assertEquals(["baba", "b", "a", "b", "a"], "baba".match(/(.)(?a)(?\1)(\2)/u)); assertEquals(["<)a/u)); assertEquals([">a", ">"], ">a".match(/(?>)a/u)); // Named references. assertEquals(["bab", "b"], "bab".match(/(?.).\k/u)); assertNull("baa".match(/(?.).\k/u)); // Nested groups. assertEquals(["bab", "bab", "ab", "b"], "bab".match(/(?.(?.(?.)))/u)); // Reference inside group. assertEquals(["bab", "b"], "bab".match(/(?\k\w)../u)); // Reference before group. assertEquals(["bab", "b"], "bab".match(/\k(?b)\w\k/u)); assertEquals(["bab", "b", "a"], "bab".match(/(?b)\k(?a)\k/u));