Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Sep 30, 2023
1 parent 232a33c commit c9364ed
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/compat/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,9 @@ GLOBAL.tests = {
'esnext.promise.with-resolvers': [PROMISES_SUPPORT, function () {
return Promise.withResolvers;
}],
'esnext.regexp.escape': function () {
return RegExp.escape;
},
'esnext.set.add-all': function () {
return Set.prototype.addAll;
},
Expand Down
2 changes: 2 additions & 0 deletions tests/entries/unit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
ok(typeof load(NS, 'reflect/has-own-metadata') == 'function');
ok(typeof load(NS, 'reflect/metadata') == 'function');
ok(load(NS, 'promise/try')(() => 42) instanceof load(NS, 'promise'));
ok(load(NS, 'regexp/escape')('10$') === '\\x310\\$');
ok(load(NS, 'set/add-all')(new Set([1, 2, 3]), 4, 5).size === 5);
ok(load(NS, 'set/delete-all')(new Set([1, 2, 3]), 4, 5) === false);
ok(load(NS, 'set/every')(new Set([1, 2, 3]), it => typeof it == 'number'));
Expand Down Expand Up @@ -953,6 +954,7 @@ for (PATH of ['core-js-pure', 'core-js']) {
load('proposals/promise-with-resolvers');
load('proposals/reflect-metadata');
load('proposals/regexp-dotall-flag');
load('proposals/regexp-escaping');
load('proposals/regexp-named-groups');
load('proposals/relative-indexing-method');
load('proposals/seeded-random');
Expand Down
27 changes: 27 additions & 0 deletions tests/unit-global/esnext.regexp.escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createConversionChecker } from '../helpers/helpers.js';

QUnit.test('RegExp.escape', assert => {
const { escape } = RegExp;
assert.isFunction(escape);
assert.arity(escape, 1);
assert.name(escape, 'escape');
assert.looksNative(escape);
assert.nonEnumerable(RegExp, 'escape');

assert.same(escape('10$'), '\\x310\\$', '10$');
assert.same(escape('abcdefg_123456'), 'abcdefg_123456', 'abcdefg_123456');
assert.same(
escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`'),
'\\(\\)\\{\\}\\[\\]\\|\\,\\.\\?\\*\\+\\-\\^\\$\\=\\<\\>\\\\\\/\\#\\&\\!\\%\\:\\;\\@\\~\\\'\\"\\`',
'(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`',
);

const checker = createConversionChecker('10$');
assert.same(escape(checker), '\\x310\\$', 'checker result');
assert.same(checker.$valueOf, 0, 'checker valueOf calls');
assert.same(checker.$toString, 1, 'checker toString calls');

if (typeof Symbol == 'function' && !Symbol.sham) {
assert.throws(() => escape(Symbol('thrower')), TypeError, 'throws on symbol');
}
});
26 changes: 26 additions & 0 deletions tests/unit-pure/esnext.regexp.escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import escape from 'core-js-pure/full/regexp/escape';
import Symbol from 'core-js-pure/es/symbol';
import { createConversionChecker } from '../helpers/helpers.js';

QUnit.test('RegExp.escape', assert => {
assert.isFunction(escape);
assert.arity(escape, 1);
assert.name(escape, 'escape');

assert.same(escape('10$'), '\\x310\\$', '10$');
assert.same(escape('abcdefg_123456'), 'abcdefg_123456', 'abcdefg_123456');
assert.same(
escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`'),
'\\(\\)\\{\\}\\[\\]\\|\\,\\.\\?\\*\\+\\-\\^\\$\\=\\<\\>\\\\\\/\\#\\&\\!\\%\\:\\;\\@\\~\\\'\\"\\`',
'(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`',
);

const checker = createConversionChecker('10$');
assert.same(escape(checker), '\\x310\\$', 'checker result');
assert.same(checker.$valueOf, 0, 'checker valueOf calls');
assert.same(checker.$toString, 1, 'checker toString calls');

if (!Symbol.sham) {
assert.throws(() => escape(Symbol('thrower')), TypeError, 'throws on symbol');
}
});

0 comments on commit c9364ed

Please sign in to comment.