1425bb815Sopenharmony_ci// Copyright JS Foundation and other contributors, http://js.foundation 2425bb815Sopenharmony_ci// 3425bb815Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4425bb815Sopenharmony_ci// you may not use this file except in compliance with the License. 5425bb815Sopenharmony_ci// You may obtain a copy of the License at 6425bb815Sopenharmony_ci// 7425bb815Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8425bb815Sopenharmony_ci// 9425bb815Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10425bb815Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS 11425bb815Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12425bb815Sopenharmony_ci// See the License for the specific language governing permissions and 13425bb815Sopenharmony_ci// limitations under the License. 14425bb815Sopenharmony_ci 15425bb815Sopenharmony_civar result = /\0/.exec("\u0000"); 16425bb815Sopenharmony_ciassert (result !== null); 17425bb815Sopenharmony_ciassert (result[0] === "\u0000"); 18425bb815Sopenharmony_ci 19425bb815Sopenharmony_ciresult = /\0/u.exec("\u0000"); 20425bb815Sopenharmony_ciassert (result !== null); 21425bb815Sopenharmony_ciassert (result[0] === "\u0000"); 22425bb815Sopenharmony_ci 23425bb815Sopenharmony_ciresult = /\000/.exec("\u0000"); 24425bb815Sopenharmony_ciassert (result !== null); 25425bb815Sopenharmony_ciassert (result[0] === "\u0000"); 26425bb815Sopenharmony_ci 27425bb815Sopenharmony_citry { 28425bb815Sopenharmony_ci new RegExp("\\000", 'u').exec("\u0000"); 29425bb815Sopenharmony_ci assert (false); 30425bb815Sopenharmony_ci} catch (e) { 31425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 32425bb815Sopenharmony_ci} 33425bb815Sopenharmony_ci 34425bb815Sopenharmony_ciresult = /\0000/.exec("\u0000\u0030"); 35425bb815Sopenharmony_ciassert (result !== null); 36425bb815Sopenharmony_ciassert (result[0] === "\u0000\u0030"); 37425bb815Sopenharmony_ci 38425bb815Sopenharmony_ciresult = /\377/.exec("\u00ff"); 39425bb815Sopenharmony_ciassert (result !== null); 40425bb815Sopenharmony_ciassert (result[0] === "\u00ff"); 41425bb815Sopenharmony_ci 42425bb815Sopenharmony_citry { 43425bb815Sopenharmony_ci new RegExp("\\377", 'u').exec("\u00ff"); 44425bb815Sopenharmony_ci assert (false); 45425bb815Sopenharmony_ci} catch (e) { 46425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 47425bb815Sopenharmony_ci} 48425bb815Sopenharmony_ci 49425bb815Sopenharmony_ciresult = /\3777/.exec("\u00ff\u0037"); 50425bb815Sopenharmony_ciassert (result !== null); 51425bb815Sopenharmony_ciassert (result[0] === "\u00ff\u0037"); 52425bb815Sopenharmony_ci 53425bb815Sopenharmony_citry { 54425bb815Sopenharmony_ci new RegExp("\\3777", 'u').exec("\u00ff\u0037"); 55425bb815Sopenharmony_ci assert (false); 56425bb815Sopenharmony_ci} catch (e) { 57425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 58425bb815Sopenharmony_ci} 59425bb815Sopenharmony_ci 60425bb815Sopenharmony_ciresult = /\400/.exec("\u0020\u0030"); 61425bb815Sopenharmony_ciassert (result !== null); 62425bb815Sopenharmony_ciassert (result[0] === "\u0020\u0030"); 63425bb815Sopenharmony_ci 64425bb815Sopenharmony_citry { 65425bb815Sopenharmony_ci new RegExp("\\400", 'u').exec("\u0020\u0030"); 66425bb815Sopenharmony_ci assert (false); 67425bb815Sopenharmony_ci} catch (e) { 68425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 69425bb815Sopenharmony_ci} 70425bb815Sopenharmony_ci 71425bb815Sopenharmony_ciresult = /(\1)/.exec("\u0001"); 72425bb815Sopenharmony_ciassert (result !== null); 73425bb815Sopenharmony_ciassert (result[0].length === 0); 74425bb815Sopenharmony_ci 75425bb815Sopenharmony_ciresult = /(\1)/u.exec("\u0001"); 76425bb815Sopenharmony_ciassert (result !== null); 77425bb815Sopenharmony_ciassert (result[0].length === 0); 78425bb815Sopenharmony_ci 79425bb815Sopenharmony_ciresult = /(\2)/.exec("\u0002"); 80425bb815Sopenharmony_ciassert (result !== null); 81425bb815Sopenharmony_ciassert (result[0] === '\u0002'); 82425bb815Sopenharmony_ci 83425bb815Sopenharmony_citry { 84425bb815Sopenharmony_ci new RegExp("(\\2)", 'u').exec("\u0002"); 85425bb815Sopenharmony_ci assert (false); 86425bb815Sopenharmony_ci} catch (e) { 87425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 88425bb815Sopenharmony_ci} 89425bb815Sopenharmony_ci 90425bb815Sopenharmony_ciresult = /\8/.exec("\u0038"); 91425bb815Sopenharmony_ciassert (result !== null); 92425bb815Sopenharmony_ciassert (result[0] === '8'); 93425bb815Sopenharmony_ci 94425bb815Sopenharmony_ciresult = /\99/.exec("\u0039\u0039"); 95425bb815Sopenharmony_ciassert (result !== null); 96425bb815Sopenharmony_ciassert (result[0] === "99"); 97425bb815Sopenharmony_ci 98425bb815Sopenharmony_ci// CharClassEscape 99425bb815Sopenharmony_ciassert (/\d+/.exec("123")[0] === "123"); 100425bb815Sopenharmony_ciassert (/\D+/.exec("abc")[0] === "abc"); 101425bb815Sopenharmony_ciassert (/\s+/.exec(" ")[0] === " "); 102425bb815Sopenharmony_ciassert (/\S+/.exec("abc")[0] === "abc"); 103425bb815Sopenharmony_ciassert (/\w+/.exec("abc")[0] === "abc"); 104425bb815Sopenharmony_ciassert (/\W+/.exec("|||")[0] === "|||"); 105425bb815Sopenharmony_ciassert (/\d+/u.exec("123")[0] === "123"); 106425bb815Sopenharmony_ciassert (/\D+/u.exec("abc")[0] === "abc"); 107425bb815Sopenharmony_ciassert (/\s+/u.exec(" ")[0] === " "); 108425bb815Sopenharmony_ciassert (/\S+/u.exec("abc")[0] === "abc"); 109425bb815Sopenharmony_ciassert (/\w+/u.exec("abc")[0] === "abc"); 110425bb815Sopenharmony_ciassert (/\W+/u.exec("|||")[0] === "|||"); 111425bb815Sopenharmony_ci 112425bb815Sopenharmony_ciassert (/\d+/u.exec("\u{10CAF}") === null); 113425bb815Sopenharmony_ciassert (/\D+/u.exec("\u{10CAF}")[0] === "\u{10CAF}"); 114425bb815Sopenharmony_ciassert (/\s+/u.exec("\u{10CAF}") === null); 115425bb815Sopenharmony_ciassert (/\S+/u.exec("\u{10CAF}")[0] === "\u{10CAF}"); 116425bb815Sopenharmony_ciassert (/\w+/u.exec("\u{10CAF}") === null); 117425bb815Sopenharmony_ciassert (/\W+/u.exec("\u{10CAF}")[0] === "\u{10CAF}"); 118425bb815Sopenharmony_ci 119425bb815Sopenharmony_ciresult = /\xz/.exec("xz"); 120425bb815Sopenharmony_ciassert (result !== null); 121425bb815Sopenharmony_ciassert (result[0] === "xz"); 122425bb815Sopenharmony_ci 123425bb815Sopenharmony_citry { 124425bb815Sopenharmony_ci new RegExp("\\xz", "u").exec("xz"); 125425bb815Sopenharmony_ci assert (false); 126425bb815Sopenharmony_ci} catch (e) { 127425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 128425bb815Sopenharmony_ci} 129425bb815Sopenharmony_ci 130425bb815Sopenharmony_ciresult = /\c/.exec("\\c"); 131425bb815Sopenharmony_ciassert (result !== null); 132425bb815Sopenharmony_ciassert (result[0] === "\\c"); 133425bb815Sopenharmony_ci 134425bb815Sopenharmony_citry { 135425bb815Sopenharmony_ci new RegExp("\\c", 'u').exec("\\c") 136425bb815Sopenharmony_ci assert (false); 137425bb815Sopenharmony_ci} catch (e) { 138425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 139425bb815Sopenharmony_ci} 140425bb815Sopenharmony_ci 141425bb815Sopenharmony_ciresult = /\c1/.exec("\\c1"); 142425bb815Sopenharmony_ciassert (result !== null); 143425bb815Sopenharmony_ciassert (result[0] === "\\c1"); 144425bb815Sopenharmony_ci 145425bb815Sopenharmony_citry { 146425bb815Sopenharmony_ci new RegExp("\\c1", 'u').exec("\\c1"); 147425bb815Sopenharmony_ci assert (false); 148425bb815Sopenharmony_ci} catch (e) { 149425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 150425bb815Sopenharmony_ci} 151425bb815Sopenharmony_ci 152425bb815Sopenharmony_citry { 153425bb815Sopenharmony_ci new RegExp("^+"); 154425bb815Sopenharmony_ci assert (false); 155425bb815Sopenharmony_ci} catch (e) { 156425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 157425bb815Sopenharmony_ci} 158425bb815Sopenharmony_ci 159425bb815Sopenharmony_citry { 160425bb815Sopenharmony_ci new RegExp("$+"); 161425bb815Sopenharmony_ci assert (false); 162425bb815Sopenharmony_ci} catch (e) { 163425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 164425bb815Sopenharmony_ci} 165425bb815Sopenharmony_ci 166425bb815Sopenharmony_citry { 167425bb815Sopenharmony_ci new RegExp("\\b+"); 168425bb815Sopenharmony_ci assert (false); 169425bb815Sopenharmony_ci} catch (e) { 170425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 171425bb815Sopenharmony_ci} 172425bb815Sopenharmony_ci 173425bb815Sopenharmony_citry { 174425bb815Sopenharmony_ci new RegExp("\\B+"); 175425bb815Sopenharmony_ci assert (false); 176425bb815Sopenharmony_ci} catch (e) { 177425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 178425bb815Sopenharmony_ci} 179425bb815Sopenharmony_ci 180425bb815Sopenharmony_ciassert (/[\b]/.exec("\u0008")[0] === "\u0008"); 181425bb815Sopenharmony_ciassert (/[\b]/u.exec("\u0008")[0] === "\u0008"); 182425bb815Sopenharmony_ciassert (/[\B]/.exec("\u0042")[0] === "\u0042"); 183425bb815Sopenharmony_ci 184425bb815Sopenharmony_citry { 185425bb815Sopenharmony_ci new RegExp ("[\\B]", 'u').exec("\u0042"); 186425bb815Sopenharmony_ci assert (false); 187425bb815Sopenharmony_ci} catch (e) { 188425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 189425bb815Sopenharmony_ci} 190425bb815Sopenharmony_ci 191425bb815Sopenharmony_ciassert (/[\c1]/.exec("\u0011")[0] === "\u0011"); 192425bb815Sopenharmony_ciassert (/[\c_]/.exec("\u001f")[0] === "\u001f"); 193425bb815Sopenharmony_ciassert (/[\c]/.exec("\\")[0] === "\\"); 194425bb815Sopenharmony_ciassert (/[\c]/.exec("c")[0] === "c"); 195425bb815Sopenharmony_ci 196425bb815Sopenharmony_citry { 197425bb815Sopenharmony_ci new RegExp("[\\c1]", 'u'); 198425bb815Sopenharmony_ci assert (false); 199425bb815Sopenharmony_ci} catch (e) { 200425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 201425bb815Sopenharmony_ci} 202425bb815Sopenharmony_ci 203425bb815Sopenharmony_citry { 204425bb815Sopenharmony_ci new RegExp("[\\c]", 'u'); 205425bb815Sopenharmony_ci assert (false); 206425bb815Sopenharmony_ci} catch (e) { 207425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 208425bb815Sopenharmony_ci} 209425bb815Sopenharmony_ci 210425bb815Sopenharmony_citry { 211425bb815Sopenharmony_ci new RegExp("[\\c_]", 'u'); 212425bb815Sopenharmony_ci assert (false); 213425bb815Sopenharmony_ci} catch (e) { 214425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 215425bb815Sopenharmony_ci} 216425bb815Sopenharmony_ci 217425bb815Sopenharmony_ciassert (/{{1,2}/.exec("{{")[0] === "{{"); 218425bb815Sopenharmony_ci 219425bb815Sopenharmony_citry { 220425bb815Sopenharmony_ci new RegExp("{{1,2}", 'u').exec("{{"); 221425bb815Sopenharmony_ci assert (false); 222425bb815Sopenharmony_ci} catch (e) { 223425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 224425bb815Sopenharmony_ci} 225425bb815Sopenharmony_ci 226425bb815Sopenharmony_ciassert (/a{1,2/.exec("a{1,2")[0] === "a{1,2"); 227425bb815Sopenharmony_ci 228425bb815Sopenharmony_citry { 229425bb815Sopenharmony_ci new RegExp("a{1,2", 'u').exec("a{1,2"); 230425bb815Sopenharmony_ci assert (false); 231425bb815Sopenharmony_ci} catch (e) { 232425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 233425bb815Sopenharmony_ci} 234425bb815Sopenharmony_ci 235425bb815Sopenharmony_ciassert (/\u017f/i.exec("s") === null); 236425bb815Sopenharmony_ciassert (/\u017f/ui.exec("s")[0] === "s"); 237425bb815Sopenharmony_ci 238425bb815Sopenharmony_ciassert (//.exec("")[0] === ""); 239425bb815Sopenharmony_ciassert (//u.exec("")[0] === ""); 240425bb815Sopenharmony_ciassert (/*?/.exec("")[0] === "\ud803"); 241425bb815Sopenharmony_ciassert (/*?/u.exec("")[0] === ""); 242425bb815Sopenharmony_ciassert (/+/.exec("")[0] === ""); 243425bb815Sopenharmony_ciassert (/+/u.exec("")[0] === ""); 244425bb815Sopenharmony_ci 245425bb815Sopenharmony_ciassert (/\ud803\udc96*?/.exec("")[0] === '\ud803'); 246425bb815Sopenharmony_ciassert (/\ud803\udc96*?/u.exec("")[0] === ''); 247425bb815Sopenharmony_ciassert (/\ud803\udc96+/.exec("")[0] === ''); 248425bb815Sopenharmony_ciassert (/\ud803\udc96+/u.exec("")[0] === ''); 249425bb815Sopenharmony_ci 250425bb815Sopenharmony_ciassert (/.*/u.exec("")[0] === ''); 251425bb815Sopenharmony_ci 252425bb815Sopenharmony_ciassert (/[\u{10000}]/.exec("\u{10000}") === null); 253425bb815Sopenharmony_ciassert (/[\u{10000}]/.exec("{")[0] === "{"); 254425bb815Sopenharmony_ciassert (/[^\u{10000}]/.exec("\u{10000}")[0] === "\ud800"); 255425bb815Sopenharmony_ciassert (/[^\u{10000}]/.exec("{") === null); 256425bb815Sopenharmony_ci 257425bb815Sopenharmony_ciassert (/[\uffff]/.exec("\uffff")[0] === "\uffff"); 258425bb815Sopenharmony_ciassert (/[^\uffff]/.exec("\uffff") === null); 259425bb815Sopenharmony_ci 260425bb815Sopenharmony_ciassert (/[\u{10000}]/u.exec("\u{10000}")[0] === "\u{10000}"); 261425bb815Sopenharmony_ciassert (/[\u{10000}]/u.exec("{") === null); 262425bb815Sopenharmony_ciassert (/[^\u{10000}]/u.exec("\u{10000}") === null); 263425bb815Sopenharmony_ciassert (/[^\u{10000}]/u.exec("{")[0] === "{"); 264425bb815Sopenharmony_ci 265425bb815Sopenharmony_ciassert (/[\uffff]/u.exec("\uffff")[0] === "\uffff"); 266425bb815Sopenharmony_ciassert (/[^\uffff]/u.exec("\uffff") === null); 267425bb815Sopenharmony_ci 268425bb815Sopenharmony_ciassert (/a{4294967296,4294967297}/.exec("aaaa") === null); 269425bb815Sopenharmony_ciassert (/a{4294967294,4294967295}/.exec("aaaa") === null); 270425bb815Sopenharmony_ciassert (/a{0000000000000000001,0000000000000000002}/u.exec("aaaa")[0] === 'aa'); 271425bb815Sopenharmony_ciassert (/(\4294967297)/.exec("\4294967297")[0] === "\4294967297"); 272425bb815Sopenharmony_ciassert (/(\1)/u.exec("aaaa")[0] === ""); 273425bb815Sopenharmony_ci 274425bb815Sopenharmony_citry { 275425bb815Sopenharmony_ci new RegExp("a{4294967295,4294967294}", ''); 276425bb815Sopenharmony_ci assert (false); 277425bb815Sopenharmony_ci} catch (e) { 278425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 279425bb815Sopenharmony_ci} 280425bb815Sopenharmony_ci 281425bb815Sopenharmony_ciassert (/[\d-\s]/.exec("-")[0] === "-"); 282425bb815Sopenharmony_ciassert (/[0-\s]/.exec("-")[0] === "-"); 283425bb815Sopenharmony_ciassert (/[\d-0]/.exec("-")[0] === "-"); 284425bb815Sopenharmony_ci 285425bb815Sopenharmony_citry { 286425bb815Sopenharmony_ci new RegExp("[\\d-\\s]", 'u').exec("-"); 287425bb815Sopenharmony_ci assert (false); 288425bb815Sopenharmony_ci} catch (e) { 289425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 290425bb815Sopenharmony_ci} 291425bb815Sopenharmony_ci 292425bb815Sopenharmony_citry { 293425bb815Sopenharmony_ci new RegExp("[0-\\s]", 'u').exec("-"); 294425bb815Sopenharmony_ci assert (false); 295425bb815Sopenharmony_ci} catch (e) { 296425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 297425bb815Sopenharmony_ci} 298425bb815Sopenharmony_ci 299425bb815Sopenharmony_citry { 300425bb815Sopenharmony_ci new RegExp("[\\d-0]", 'u').exec("-"); 301425bb815Sopenharmony_ci assert (false); 302425bb815Sopenharmony_ci} catch (e) { 303425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 304425bb815Sopenharmony_ci} 305425bb815Sopenharmony_ci 306425bb815Sopenharmony_ciassert (/[-]/.exec("-")[0] === "-"); 307425bb815Sopenharmony_ciassert (/[-]/u.exec("-")[0] === "-"); 308425bb815Sopenharmony_ciassert (/[--]/.exec("-")[0] === "-"); 309425bb815Sopenharmony_ciassert (/[--]/u.exec("-")[0] === "-"); 310425bb815Sopenharmony_ci 311425bb815Sopenharmony_ciassert (/}/.exec("}")[0] === "}"); 312425bb815Sopenharmony_ciassert (/\}/u.exec("}")[0] === "}"); 313425bb815Sopenharmony_ci 314425bb815Sopenharmony_citry { 315425bb815Sopenharmony_ci new RegExp("}", 'u').exec("}"); 316425bb815Sopenharmony_ci assert (false); 317425bb815Sopenharmony_ci} catch (e) { 318425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 319425bb815Sopenharmony_ci} 320425bb815Sopenharmony_ci 321425bb815Sopenharmony_ciassert (/]/.exec("]")[0] === "]"); 322425bb815Sopenharmony_ciassert (/\]/u.exec("]")[0] === "]"); 323425bb815Sopenharmony_ci 324425bb815Sopenharmony_citry { 325425bb815Sopenharmony_ci new RegExp("]", 'u').exec("]"); 326425bb815Sopenharmony_ci assert (false); 327425bb815Sopenharmony_ci} catch (e) { 328425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 329425bb815Sopenharmony_ci} 330425bb815Sopenharmony_ci 331425bb815Sopenharmony_ciassert (/(?=)*/.exec("")[0] === ""); 332425bb815Sopenharmony_ciassert (/(?=)+/.exec("")[0] === ""); 333425bb815Sopenharmony_ciassert (/(?=){1,2}/.exec("")[0] === ""); 334425bb815Sopenharmony_ci 335425bb815Sopenharmony_citry { 336425bb815Sopenharmony_ci new RegExp("(?=)*", 'u'); 337425bb815Sopenharmony_ci assert (false); 338425bb815Sopenharmony_ci} catch (e) { 339425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 340425bb815Sopenharmony_ci} 341425bb815Sopenharmony_ci 342425bb815Sopenharmony_citry { 343425bb815Sopenharmony_ci new RegExp("(?=)+", 'u'); 344425bb815Sopenharmony_ci assert (false); 345425bb815Sopenharmony_ci} catch (e) { 346425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 347425bb815Sopenharmony_ci} 348425bb815Sopenharmony_ci 349425bb815Sopenharmony_citry { 350425bb815Sopenharmony_ci new RegExp("(?=){1,2}", 'u'); 351425bb815Sopenharmony_ci assert (false); 352425bb815Sopenharmony_ci} catch (e) { 353425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 354425bb815Sopenharmony_ci} 355425bb815Sopenharmony_ci 356425bb815Sopenharmony_citry { 357425bb815Sopenharmony_ci new RegExp("(?=){2,1}", ''); 358425bb815Sopenharmony_ci assert (false); 359425bb815Sopenharmony_ci} catch (e) { 360425bb815Sopenharmony_ci assert (e instanceof SyntaxError); 361425bb815Sopenharmony_ci} 362