| 1 |
// |reftest| shell-option(--enable-regexp-escape) skip-if(!RegExp.escape||!xulRuntime.shell) -- RegExp.escape is not enabled unconditionally, requires shell-options |
| 2 |
// Copyright (C) 2024 Leo Balter. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
esid: sec-encodeforregexescape |
| 7 |
description: Ensures the underscore character is not escaped |
| 8 |
info: | |
| 9 |
RegExp.escape ( string ) |
| 10 |
|
| 11 |
This method produces a new string in which certain characters have been escaped. |
| 12 |
These characters are: . * + ? ^ $ | ( ) [ ] { } \ , - = < > # & ! % : ; @ ~ ' ` " and white space or line terminators. |
| 13 |
features: [RegExp.escape] |
| 14 |
---*/ |
| 15 |
|
| 16 |
assert.sameValue(RegExp.escape('_'), '_', 'Single underscore character is not escaped'); |
| 17 |
assert.sameValue(RegExp.escape('__'), '__', 'Thunderscore character is not escaped'); |
| 18 |
assert.sameValue(RegExp.escape('hello_world'), '\\x68ello_world', 'String starting with ASCII letter and containing underscore is correctly escaped'); |
| 19 |
assert.sameValue(RegExp.escape('1_hello_world'), '\\x31_hello_world', 'String starting with digit and containing underscore is correctly escaped'); |
| 20 |
assert.sameValue(RegExp.escape('a_b_c'), '\\x61_b_c', 'String starting with ASCII letter and containing multiple underscores is correctly escaped'); |
| 21 |
assert.sameValue(RegExp.escape('3_b_4'), '\\x33_b_4', 'String starting with digit and containing multiple underscores is correctly escaped'); |
| 22 |
assert.sameValue(RegExp.escape('_hello'), '_hello', 'String starting with underscore and containing other characters is not escaped'); |
| 23 |
assert.sameValue(RegExp.escape('_1hello'), '_1hello', 'String starting with underscore and digit is not escaped'); |
| 24 |
assert.sameValue(RegExp.escape('_a_1_2'), '_a_1_2', 'String starting with underscore and mixed characters is not escaped'); |
| 25 |
|
| 26 |
reportCompare(0, 0); |