Skip to content

Commit c9364ed

Browse files
committed
add tests
1 parent 232a33c commit c9364ed

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

tests/compat/tests.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,9 @@ GLOBAL.tests = {
17471747
'esnext.promise.with-resolvers': [PROMISES_SUPPORT, function () {
17481748
return Promise.withResolvers;
17491749
}],
1750+
'esnext.regexp.escape': function () {
1751+
return RegExp.escape;
1752+
},
17501753
'esnext.set.add-all': function () {
17511754
return Set.prototype.addAll;
17521755
},

tests/entries/unit.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
819819
ok(typeof load(NS, 'reflect/has-own-metadata') == 'function');
820820
ok(typeof load(NS, 'reflect/metadata') == 'function');
821821
ok(load(NS, 'promise/try')(() => 42) instanceof load(NS, 'promise'));
822+
ok(load(NS, 'regexp/escape')('10$') === '\\x310\\$');
822823
ok(load(NS, 'set/add-all')(new Set([1, 2, 3]), 4, 5).size === 5);
823824
ok(load(NS, 'set/delete-all')(new Set([1, 2, 3]), 4, 5) === false);
824825
ok(load(NS, 'set/every')(new Set([1, 2, 3]), it => typeof it == 'number'));
@@ -953,6 +954,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
953954
load('proposals/promise-with-resolvers');
954955
load('proposals/reflect-metadata');
955956
load('proposals/regexp-dotall-flag');
957+
load('proposals/regexp-escaping');
956958
load('proposals/regexp-named-groups');
957959
load('proposals/relative-indexing-method');
958960
load('proposals/seeded-random');
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { createConversionChecker } from '../helpers/helpers.js';
2+
3+
QUnit.test('RegExp.escape', assert => {
4+
const { escape } = RegExp;
5+
assert.isFunction(escape);
6+
assert.arity(escape, 1);
7+
assert.name(escape, 'escape');
8+
assert.looksNative(escape);
9+
assert.nonEnumerable(RegExp, 'escape');
10+
11+
assert.same(escape('10$'), '\\x310\\$', '10$');
12+
assert.same(escape('abcdefg_123456'), 'abcdefg_123456', 'abcdefg_123456');
13+
assert.same(
14+
escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`'),
15+
'\\(\\)\\{\\}\\[\\]\\|\\,\\.\\?\\*\\+\\-\\^\\$\\=\\<\\>\\\\\\/\\#\\&\\!\\%\\:\\;\\@\\~\\\'\\"\\`',
16+
'(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`',
17+
);
18+
19+
const checker = createConversionChecker('10$');
20+
assert.same(escape(checker), '\\x310\\$', 'checker result');
21+
assert.same(checker.$valueOf, 0, 'checker valueOf calls');
22+
assert.same(checker.$toString, 1, 'checker toString calls');
23+
24+
if (typeof Symbol == 'function' && !Symbol.sham) {
25+
assert.throws(() => escape(Symbol('thrower')), TypeError, 'throws on symbol');
26+
}
27+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import escape from 'core-js-pure/full/regexp/escape';
2+
import Symbol from 'core-js-pure/es/symbol';
3+
import { createConversionChecker } from '../helpers/helpers.js';
4+
5+
QUnit.test('RegExp.escape', assert => {
6+
assert.isFunction(escape);
7+
assert.arity(escape, 1);
8+
assert.name(escape, 'escape');
9+
10+
assert.same(escape('10$'), '\\x310\\$', '10$');
11+
assert.same(escape('abcdefg_123456'), 'abcdefg_123456', 'abcdefg_123456');
12+
assert.same(
13+
escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`'),
14+
'\\(\\)\\{\\}\\[\\]\\|\\,\\.\\?\\*\\+\\-\\^\\$\\=\\<\\>\\\\\\/\\#\\&\\!\\%\\:\\;\\@\\~\\\'\\"\\`',
15+
'(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`',
16+
);
17+
18+
const checker = createConversionChecker('10$');
19+
assert.same(escape(checker), '\\x310\\$', 'checker result');
20+
assert.same(checker.$valueOf, 0, 'checker valueOf calls');
21+
assert.same(checker.$toString, 1, 'checker toString calls');
22+
23+
if (!Symbol.sham) {
24+
assert.throws(() => escape(Symbol('thrower')), TypeError, 'throws on symbol');
25+
}
26+
});

0 commit comments

Comments
 (0)