Debian Codegraph @

js/src/tests/test262/built-ins/RegExp/escape/not-escaped.js

raw
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-regexp.escape
7 description: Numbers and alphabetic characters are 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: . * + ? ^ $ | ( ) [ ] { } \
13
14 features: [RegExp.escape]
15 ---*/
16
17 const asciiletter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
18 const decimaldigits = '0123456789';
19
20 assert.sameValue(RegExp.escape(''), '', 'the empty string is not escaped');
21
22 asciiletter.split('').forEach(char => {
23 assert.sameValue(RegExp.escape(`.${char}`), `\\.${char}`, `ASCII letter ${char} is not escaped`);
24 });
25
26 assert.sameValue(RegExp.escape(`.${asciiletter}`), `\\.${asciiletter}`, 'ASCII letters are not escaped');
27
28 decimaldigits.split('').forEach(char => {
29 assert.sameValue(RegExp.escape(`.${char}`), `\\.${char}`, `decimal digit ${char} is not escaped`);
30 });
31
32 assert.sameValue(RegExp.escape(`.${decimaldigits}`), `\\.${decimaldigits}`, 'decimal digits are not escaped');
33
34 assert.sameValue(RegExp.escape('.a1b2c3D4E5F6'), '\\.a1b2c3D4E5F6', 'mixed string with ASCII letters and decimal digits is not escaped');
35
36 reportCompare(0, 0);