OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-unicode-regexps --harmony-regexp-lookbehind |
| 6 |
| 7 function execl(expectation, regexp, subject) { |
| 8 if (regexp instanceof String) regexp = new RegExp(regexp, "u"); |
| 9 assertEquals(expectation, regexp.exec(subject)); |
| 10 } |
| 11 |
| 12 function execs(expectation, regexp_source, subject) { |
| 13 execl(expectation, new RegExp(regexp_source, "u"), subject); |
| 14 } |
| 15 |
| 16 // Character ranges. |
| 17 execl(["A"], /[A-D]/u, "A"); |
| 18 execs(["A"], "[A-D]", "A"); |
| 19 execl(["ABCD"], /[A-D]+/u, "ZABCDEF"); |
| 20 execs(["ABCD"], "[A-D]+", "ZABCDEF"); |
| 21 |
| 22 execl(["\u{12345}"], /[\u1234-\u{12345}]/u, "\u{12345}"); |
| 23 execs(["\u{12345}"], "[\u1234-\u{12345}]", "\u{12345}"); |
| 24 execl(null, /[^\u1234-\u{12345}]/u, "\u{12345}"); |
| 25 execs(null, "[^\u1234-\u{12345}]", "\u{12345}"); |
| 26 |
| 27 execl(["\u{1234}"], /[\u1234-\u{12345}]/u, "\u{1234}"); |
| 28 execs(["\u{1234}"], "[\u1234-\u{12345}]", "\u{1234}"); |
| 29 execl(null, /[^\u1234-\u{12345}]/u, "\u{1234}"); |
| 30 execs(null, "[^\u1234-\u{12345}]", "\u{1234}"); |
| 31 |
| 32 execl(null, /[\u1234-\u{12345}]/u, "\u{1233}"); |
| 33 execs(null, "[\u1234-\u{12345}]", "\u{1233}"); |
| 34 execl(["\u{1233}"], /[^\u1234-\u{12345}]/u, "\u{1233}"); |
| 35 execs(["\u{1233}"], "[^\u1234-\u{12345}]", "\u{1233}"); |
| 36 |
| 37 execl(["\u{12346}"], /[^\u1234-\u{12345}]/u, "\u{12346}"); |
| 38 execs(["\u{12346}"], "[^\u1234-\u{12345}]", "\u{12346}"); |
| 39 execl(null, /[\u1234-\u{12345}]/u, "\u{12346}"); |
| 40 execs(null, "[\u1234-\u{12345}]", "\u{12346}"); |
| 41 |
| 42 execl(["\u{12342}"], /[\u{12340}-\u{12345}]/u, "\u{12342}"); |
| 43 execs(["\u{12342}"], "[\u{12340}-\u{12345}]", "\u{12342}"); |
| 44 execl(["\u{12342}"], /[\ud808\udf40-\ud808\udf45]/u, "\u{12342}"); |
| 45 execs(["\u{12342}"], "[\ud808\udf40-\ud808\udf45]", "\u{12342}"); |
| 46 execl(null, /[^\u{12340}-\u{12345}]/u, "\u{12342}"); |
| 47 execs(null, "[^\u{12340}-\u{12345}]", "\u{12342}"); |
| 48 execl(null, /[^\ud808\udf40-\ud808\udf45]/u, "\u{12342}"); |
| 49 execs(null, "[^\ud808\udf40-\ud808\udf45]", "\u{12342}"); |
| 50 |
| 51 execl(["\u{ffff}"], /[\u{ff80}-\u{12345}]/u, "\u{ffff}"); |
| 52 execs(["\u{ffff}"], "[\u{ff80}-\u{12345}]", "\u{ffff}"); |
| 53 execl(["\u{ffff}"], /[\u{ff80}-\ud808\udf45]/u, "\u{ffff}"); |
| 54 execs(["\u{ffff}"], "[\u{ff80}-\ud808\udf45]", "\u{ffff}"); |
| 55 execl(null, /[^\u{ff80}-\u{12345}]/u, "\u{ffff}"); |
| 56 execs(null, "[^\u{ff80}-\u{12345}]", "\u{ffff}"); |
| 57 execl(null, /[^\u{ff80}-\ud808\udf45]/u, "\u{ffff}"); |
| 58 execs(null, "[^\u{ff80}-\ud808\udf45]", "\u{ffff}"); |
| 59 |
| 60 // Lone surrogate |
| 61 execl(["\ud800"], /[^\u{ff80}-\u{12345}]/u, "\uff99\u{d800}A"); |
| 62 execs(["\udc00"], "[^\u{ff80}-\u{12345}]", "\uff99\u{dc00}A"); |
| 63 execl(["\udc01"], /[\u0100-\u{10ffff}]/u, "A\udc01"); |
| 64 execl(["\udc03"], /[\udc01-\udc03]/u, "\ud801\udc02\udc03"); |
| 65 execl(["\ud801"], /[\ud801-\ud803]/u, "\ud802\udc01\ud801"); |
| 66 |
| 67 // Paired sorrogate. |
| 68 execl(null, /[^\u{ff80}-\u{12345}]/u, "\u{d800}\u{dc00}"); |
| 69 execs(null, "[^\u{ff80}-\u{12345}]", "\u{d800}\u{dc00}"); |
| 70 execl(["\ud800\udc00"], /[\u{ff80}-\u{12345}]/u, "\u{d800}\u{dc00}"); |
| 71 execs(["\ud800\udc00"], "[\u{ff80}-\u{12345}]", "\u{d800}\u{dc00}"); |
| 72 execl(["foo\u{10e6d}bar"], /foo\ud803\ude6dbar/u, "foo\u{10e6d}bar"); |
| 73 |
| 74 // Lone surrogates |
| 75 execl(["\ud801\ud801"], /\ud801+/u, "\ud801\udc01\ud801\ud801"); |
| 76 execl(["\udc01\udc01"], /\udc01+/u, "\ud801\ud801\udc01\udc01\udc01"); |
| 77 |
| 78 execl(["\udc02\udc03A"], /\W\WA/u, "\ud801\udc01A\udc02\udc03A"); |
| 79 execl(["\ud801\ud802"], /\ud801./u, "\ud801\udc01\ud801\ud802"); |
| 80 execl(["\udc02\udc03A"], /[\ud800-\udfff][\ud800-\udfff]A/u, |
| 81 "\ud801\udc01A\udc02\udc03A"); |
| 82 |
| 83 // Character classes |
| 84 execl(null, /\w/u, "\ud801\udc01"); |
| 85 execl(["\ud801"], /[^\w]/, "\ud801\udc01"); |
| 86 execl(["\ud801\udc01"], /[^\w]/u, "\ud801\udc01"); |
| 87 execl(["\ud801"], /\W/, "\ud801\udc01"); |
| 88 execl(["\ud801\udc01"], /\W/u, "\ud801\udc01"); |
| 89 |
| 90 execl(["\ud800X"], /.X/u, "\ud800XaX"); |
| 91 execl(["aX"], /.(?<!\ud800)X/u, "\ud800XaX"); |
| 92 execl(["aX"], /.(?<![\ud800-\ud900])X/u, "\ud800XaX"); |
| 93 |
| 94 execl(null, /[]/u, "\u1234"); |
| 95 execl(["0abc"], /[^]abc/u, "0abc"); |
| 96 execl(["\u1234abc"], /[^]abc/u, "\u1234abc"); |
| 97 execl(["\u{12345}abc"], /[^]abc/u, "\u{12345}abc"); |
| 98 |
| 99 // Backward matches of lone surrogates. |
| 100 execl(["B", "\ud803A"], /(?<=([\ud800-\ud900]A))B/u, |
| 101 "\ud801\udc00AB\udc00AB\ud802\ud803AB"); |
| 102 execl(["B", "\udc00A"], /(?<=([\ud800-\u{10300}]A))B/u, |
| 103 "\ud801\udc00AB\udc00AB\ud802\ud803AB"); |
| 104 execl(["B", "\udc11A"], /(?<=([\udc00-\udd00]A))B/u, |
| 105 "\ud801\udc00AB\udc11AB\ud802\ud803AB"); |
| 106 execl(["X", "\ud800C"], /(?<=(\ud800\w))X/u, |
| 107 "\ud800\udc00AX\udc11BX\ud800\ud800CX"); |
| 108 execl(["C", "\ud800\ud800"], /(?<=(\ud800.))\w/u, |
| 109 "\ud800\udc00AX\udc11BX\ud800\ud800CX"); |
| 110 execl(["X", "\udc01C"], /(?<=(\udc01\w))X/u, |
| 111 "\ud800\udc01AX\udc11BX\udc01\udc01CX"); |
| 112 execl(["C", "\udc01\udc01"], /(?<=(\udc01.))./u, |
| 113 "\ud800\udc01AX\udc11BX\udc01\udc01CX"); |
| 114 |
| 115 var L = "\ud800"; |
| 116 var T = "\udc00"; |
| 117 var X = "X"; |
| 118 |
| 119 // Test string contains only match. |
| 120 function testw(expect, src, subject) { |
| 121 var re = new RegExp("^" + src + "$", "u"); |
| 122 assertEquals(expect, re.test(subject)); |
| 123 } |
| 124 |
| 125 // Test string starts with match. |
| 126 function tests(expect, src, subject) { |
| 127 var re = new RegExp("^" + src, "u"); |
| 128 assertEquals(expect, re.test(subject)); |
| 129 } |
| 130 |
| 131 testw(true, X, X); |
| 132 testw(true, L, L); |
| 133 testw(true, T, T); |
| 134 testw(true, L + T, L + T); |
| 135 testw(true, T + L, T + L); |
| 136 testw(false, T, L + T); |
| 137 testw(false, L, L + T); |
| 138 testw(true, ".(?<=" + L + ")", L); |
| 139 testw(true, ".(?<=" + T + ")", T); |
| 140 testw(true, ".(?<=" + L + T + ")", L + T); |
| 141 testw(true, ".(?<=" + L + T + ")", L + T); |
| 142 tests(true, ".(?<=" + T + ")", T + L); |
| 143 tests(false, ".(?<=" + L + ")", L + T); |
| 144 tests(false, ".(?<=" + T + ")", L + T); |
| 145 tests(true, "..(?<=" + T + ")", T + T + L); |
| 146 tests(true, "..(?<=" + T + ")", X + T + L); |
| 147 tests(true, "...(?<=" + L + ")", X + T + L); |
| 148 tests(false, "...(?<=" + T + ")", X + L + T) |
| 149 tests(true, "..(?<=" + L + T + ")", X + L + T) |
| 150 tests(true, "..(?<=" + L + T + "(?<=" + L + T + "))", X + L + T); |
| 151 tests(false, "..(?<=" + L + "(" + T + "))", X + L + T); |
| 152 tests(false, ".*" + L, X + L + T); |
| 153 tests(true, ".*" + L, X + L + L + T); |
| 154 tests(false, ".*" + L, X + L + T + L + T); |
| 155 tests(false, ".*" + T, X + L + T + L + T); |
| 156 tests(true, ".*" + T, X + L + T + T + L + T); |
OLD | NEW |