// 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. function checkEquals(array, subject, regexp) { // Do it once with the interpreter. var result = subject.match(regexp); assertEquals(array, result); // Do it again with the machine code. result = subject.match(regexp); assertEquals(array, result); } function checkExec(array, regexp, subject) { // Do it once with the interpreter. var result = regexp.exec(subject); assertEquals(array, result); // Do it again with the machine code. result = regexp.exec(subject); assertEquals(array, result); } function checkNull(subject, regexp) { // Do it once with the interpreter. var result = subject.match(regexp); assertNull(result); // Do it again with the machine code. result = subject.match(regexp); assertNull(result); } // Simple fixed-length matches. checkEquals(["a"], "a", /^.(?<=a)/); checkNull("b", /^.(?<=a)/); checkEquals(["foo"], "foo1", /^f..(?<=.oo)/); checkEquals(["foo"], "foo2", /^f\w\w(?<=\woo)/); checkNull("boo", /^f\w\w(?<=\woo)/); checkNull("fao", /^f\w\w(?<=\woo)/); checkNull("foa", /^f\w\w(?<=\woo)/); checkEquals(["def"], "abcdef", /(?<=abc)\w\w\w/); checkEquals(["def"], "abcdef", /(?<=a.c)\w\w\w/); checkEquals(["def"], "abcdef", /(?<=a\wc)\w\w\w/); checkEquals(["cde"], "abcdef", /(?<=a[a-z])\w\w\w/); checkEquals(["def"], "abcdef", /(?<=a[a-z][a-z])\w\w\w/); checkEquals(["def"], "abcdef", /(?<=a[a-z]{2})\w\w\w/); checkEquals(["bcd"], "abcdef", /(?<=a{1})\w\w\w/); checkEquals(["cde"], "abcdef", /(?<=a{1}b{1})\w\w\w/); checkEquals(["def"], "abcdef", /(?<=a{1}[a-z]{2})\w\w\w/); // Variable-length matches. checkEquals(["def"], "abcdef", /(?<=[a|b|c]*)[^a|b|c]{3}/); checkEquals(["def"], "abcdef", /(?<=\w*)[^a|b|c]{3}/); // Start of line matches. checkEquals(["def"], "abcdef", /(?<=^abc)def/); checkEquals(["def"], "abcdef", /(?<=^[a-c]{3})def/); checkEquals(["def"], "abcabcdef", /(?<=^[a-c]{6})def/); checkEquals(["def"], "xyz\nabcdef", /(?<=^[a-c]{3})def/m); checkEquals(["ab", "cd", "efg"], "ab\ncd\nefg", /(?<=^)\w+/gm); checkEquals(["ab", "cd", "efg"], "ab\ncd\nefg", /\w+(?<=$)/gm); checkEquals(["ab", "cd", "efg"], "ab\ncd\nefg", /(?<=^)\w+(?<=$)/gm); checkNull("abcdef", /(?<=^[^a-c]{3})def/); checkNull("foooo", /"^foooo(?<=^o+)$/); checkNull("foooo", /"^foooo(?<=^o*)$/); checkEquals(["foo"], "foo", /^foo(?<=^fo+)$/); checkEquals(["foooo"], "foooo", /^foooo(?<=^fo*)/); checkEquals(["foo", "f"], "foo", /^(f)oo(?<=^\1o+)$/); checkEquals(["foo", "f"], "foo", /^(f)oo(?<=^\1o+)$/i); checkEquals(["foo\u1234", "f"], "foo\u1234", /^(f)oo(?<=^\1o+).$/i); checkEquals(["def"], "abcdefdef", /(?<=^\w+)def/); checkEquals(["def", "def"], "abcdefdef", /(?<=^\w+)def/g); // Word boundary matches. checkEquals(["def"], "abc def", /(?<=\b)[d-f]{3}/); checkEquals(["def"], "ab cdef", /(?<=\B)\w{3}/); checkEquals(["def"], "ab cdef", /(?<=\B)(?<=c(?<=\w))\w{3}/); checkNull("abcdef", /(?<=\b)[d-f]{3}/); // Negative lookbehind. checkEquals(["abc"], "abcdef", /(?