| Index: test/mjsunit/harmony/unicode-character-ranges.js
|
| diff --git a/test/mjsunit/harmony/unicode-character-ranges.js b/test/mjsunit/harmony/unicode-character-ranges.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e107b70d4cbccd013cfeeeb6f6be0c968e9439dc
|
| --- /dev/null
|
| +++ b/test/mjsunit/harmony/unicode-character-ranges.js
|
| @@ -0,0 +1,103 @@
|
| +// Copyright 2016 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-unicode-regexps --harmony-regexp-lookbehind
|
| +
|
| +function testl(expectation, regexp, subject) {
|
| + if (regexp instanceof String) regexp = new RegExp(regexp, "u");
|
| + assertEquals(expectation, regexp.exec(subject));
|
| +}
|
| +
|
| +function tests(expectation, string, subject) {
|
| + testl(expectation, new RegExp(string, "u"), subject);
|
| +}
|
| +
|
| +// Character ranges.
|
| +testl(["A"], /[A-D]/u, "A");
|
| +tests(["A"], "[A-D]", "A");
|
| +testl(["ABCD"], /[A-D]+/u, "ZABCDEF");
|
| +tests(["ABCD"], "[A-D]+", "ZABCDEF");
|
| +
|
| +testl(["\u{12345}"], /[\u1234-\u{12345}]/u, "\u{12345}");
|
| +tests(["\u{12345}"], "[\u1234-\u{12345}]", "\u{12345}");
|
| +testl(null, /[^\u1234-\u{12345}]/u, "\u{12345}");
|
| +tests(null, "[^\u1234-\u{12345}]", "\u{12345}");
|
| +
|
| +testl(["\u{1234}"], /[\u1234-\u{12345}]/u, "\u{1234}");
|
| +tests(["\u{1234}"], "[\u1234-\u{12345}]", "\u{1234}");
|
| +testl(null, /[^\u1234-\u{12345}]/u, "\u{1234}");
|
| +tests(null, "[^\u1234-\u{12345}]", "\u{1234}");
|
| +
|
| +testl(null, /[\u1234-\u{12345}]/u, "\u{1233}");
|
| +tests(null, "[\u1234-\u{12345}]", "\u{1233}");
|
| +testl(["\u{1233}"], /[^\u1234-\u{12345}]/u, "\u{1233}");
|
| +tests(["\u{1233}"], "[^\u1234-\u{12345}]", "\u{1233}");
|
| +
|
| +testl(["\u{12346}"], /[^\u1234-\u{12345}]/u, "\u{12346}");
|
| +tests(["\u{12346}"], "[^\u1234-\u{12345}]", "\u{12346}");
|
| +testl(null, /[\u1234-\u{12345}]/u, "\u{12346}");
|
| +tests(null, "[\u1234-\u{12345}]", "\u{12346}");
|
| +
|
| +testl(["\u{12342}"], /[\u{12340}-\u{12345}]/u, "\u{12342}");
|
| +tests(["\u{12342}"], "[\u{12340}-\u{12345}]", "\u{12342}");
|
| +testl(null, /[^\u{12340}-\u{12345}]/u, "\u{12342}");
|
| +tests(null, "[^\u{12340}-\u{12345}]", "\u{12342}");
|
| +
|
| +testl(["\u{ffff}"], /[\u{ff80}-\u{12345}]/u, "\u{ffff}");
|
| +tests(["\u{ffff}"], "[\u{ff80}-\u{12345}]", "\u{ffff}");
|
| +testl(null, /[^\u{ff80}-\u{12345}]/u, "\u{ffff}");
|
| +tests(null, "[^\u{ff80}-\u{12345}]", "\u{ffff}");
|
| +
|
| +// Lone surrogate
|
| +testl(["\ud800"], /[^\u{ff80}-\u{12345}]/u, "\uff99\u{d800}A");
|
| +tests(["\udc00"], "[^\u{ff80}-\u{12345}]", "\uff99\u{dc00}A");
|
| +testl(["\udc01"], /[\u0100-\u{10ffff}]/u, "A\udc01");
|
| +testl(["\udc03"], /[\udc01-\udc03]/u, "\ud801\udc02\udc03");
|
| +testl(["\ud801"], /[\ud801-\ud803]/u, "\ud802\udc01\ud801");
|
| +
|
| +// Paired sorrogate.
|
| +testl(null, /[^\u{ff80}-\u{12345}]/u, "\u{d800}\u{dc00}");
|
| +tests(null, "[^\u{ff80}-\u{12345}]", "\u{d800}\u{dc00}");
|
| +testl(["\ud800\udc00"], /[\u{ff80}-\u{12345}]/u, "\u{d800}\u{dc00}");
|
| +tests(["\ud800\udc00"], "[\u{ff80}-\u{12345}]", "\u{d800}\u{dc00}");
|
| +testl(["foo\u{10e6d}bar"], /foo\ud803\ude6dbar/u, "foo\u{10e6d}bar");
|
| +
|
| +// Lone surrogates
|
| +testl(["\ud801\ud801"], /\ud801+/u, "\ud801\udc01\ud801\ud801");
|
| +testl(["\udc01\udc01"], /\udc01+/u, "\ud801\ud801\udc01\udc01\udc01");
|
| +
|
| +testl(["\udc02\udc03A"], /\W\WA/u, "\ud801\udc01A\udc02\udc03A");
|
| +testl(["\ud801\ud802"], /\ud801./u, "\ud801\udc01\ud801\ud802");
|
| +testl(["\udc02\udc03A"], /[\ud800-\udfff][\ud800-\udfff]A/u,
|
| + "\ud801\udc01A\udc02\udc03A");
|
| +
|
| +// Character classes
|
| +testl(null, /\w/u, "\ud801\udc01");
|
| +testl(["\ud801"], /[^\w]/, "\ud801\udc01");
|
| +testl(["\ud801\udc01"], /[^\w]/u, "\ud801\udc01");
|
| +testl(["\ud801"], /\W/, "\ud801\udc01");
|
| +testl(["\ud801\udc01"], /\W/u, "\ud801\udc01");
|
| +
|
| +testl(["\ud800X"], /.X/u, "\ud800XaX");
|
| +testl(["aX"], /.(?<!\ud800)X/u, "\ud800XaX");
|
| +testl(["aX"], /.(?<![\ud800-\ud900])X/u, "\ud800XaX");
|
| +
|
| +testl(null, /[]/u, "\u1234");
|
| +testl(["0abc"], /[^]abc/u, "0abc");
|
| +testl(["\u1234abc"], /[^]abc/u, "\u1234abc");
|
| +testl(["\u{12345}abc"], /[^]abc/u, "\u{12345}abc");
|
| +
|
| +// Backward matches of lone surrogates.
|
| +testl(["B", "\ud803A"], /(?<=([\ud800-\ud900]A))B/u,
|
| + "\ud801\udc00AB\udc00AB\ud802\ud803AB");
|
| +testl(["B", "\udc11A"], /(?<=([\udc00-\udd00]A))B/u,
|
| + "\ud801\udc00AB\udc11AB\ud802\ud803AB");
|
| +testl(["X", "\ud800C"], /(?<=(\ud800\w))X/u,
|
| + "\ud800\udc00AX\udc11BX\ud800\ud800CX");
|
| +testl(["C", "\ud800\ud800"], /(?<=(\ud800.))\w/u,
|
| + "\ud800\udc00AX\udc11BX\ud800\ud800CX");
|
| +testl(["X", "\udc01C"], /(?<=(\udc01\w))X/u,
|
| + "\ud800\udc01AX\udc11BX\udc01\udc01CX");
|
| +testl(["C", "\udc01\udc01"], /(?<=(\udc01.))./u,
|
| + "\ud800\udc01AX\udc11BX\udc01\udc01CX");
|
|
|