file_path
stringlengths 3
280
| file_language
stringclasses 66
values | content
stringlengths 1
1.04M
| repo_name
stringlengths 5
92
| repo_stars
int64 0
154k
| repo_description
stringlengths 0
402
| repo_primary_language
stringclasses 108
values | developer_username
stringlengths 1
25
| developer_name
stringlengths 0
30
| developer_company
stringlengths 0
82
|
|---|---|---|---|---|---|---|---|---|---|
tests/unit-pure/es.number.max-safe-integer.js
|
JavaScript
|
import MAX_SAFE_INTEGER from 'core-js-pure/es/number/max-safe-integer';
QUnit.test('Number.MAX_SAFE_INTEGER', assert => {
assert.same(MAX_SAFE_INTEGER, 2 ** 53 - 1, 'Is 2^53 - 1');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.number.min-safe-integer.js
|
JavaScript
|
import MIN_SAFE_INTEGER from 'core-js-pure/es/number/min-safe-integer';
QUnit.test('Number.MIN_SAFE_INTEGER', assert => {
assert.same(MIN_SAFE_INTEGER, -(2 ** 53) + 1, 'Is -2^53 + 1');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.number.parse-float.js
|
JavaScript
|
import { WHITESPACES } from '../helpers/constants.js';
import parseFloat from 'core-js-pure/es/number/parse-float';
QUnit.test('Number.parseFloat', assert => {
assert.isFunction(parseFloat);
assert.arity(parseFloat, 1);
assert.same(parseFloat('0'), 0);
assert.same(parseFloat(' 0'), 0);
assert.same(parseFloat('+0'), 0);
assert.same(parseFloat(' +0'), 0);
assert.same(parseFloat('-0'), -0);
assert.same(parseFloat(' -0'), -0);
assert.same(parseFloat(`${ WHITESPACES }+0`), 0);
assert.same(parseFloat(`${ WHITESPACES }-0`), -0);
assert.same(parseFloat(null), NaN);
assert.same(parseFloat(undefined), NaN);
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
const symbol = Symbol('Number.parseFloat test');
assert.throws(() => parseFloat(symbol), 'throws on symbol argument');
assert.throws(() => parseFloat(Object(symbol)), 'throws on boxed symbol argument');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.number.parse-int.js
|
JavaScript
|
/* eslint-disable prefer-numeric-literals -- required for testing */
import { WHITESPACES } from '../helpers/constants.js';
import parseInt from 'core-js-pure/es/number/parse-int';
QUnit.test('Number.parseInt', assert => {
assert.isFunction(parseInt);
assert.arity(parseInt, 2);
for (let radix = 2; radix <= 36; ++radix) {
assert.same(parseInt('10', radix), radix, `radix ${ radix }`);
}
const strings = ['01', '08', '10', '42'];
for (const string of strings) {
assert.same(parseInt(string), parseInt(string, 10), `default radix is 10: ${ string }`);
}
assert.same(parseInt('0x16'), parseInt('0x16', 16), 'default radix is 16: 0x16');
assert.same(parseInt(' 0x16'), parseInt('0x16', 16), 'ignores leading whitespace #1');
assert.same(parseInt(' 42'), parseInt('42', 10), 'ignores leading whitespace #2');
assert.same(parseInt(' 08'), parseInt('08', 10), 'ignores leading whitespace #3');
assert.same(parseInt(`${ WHITESPACES }08`), parseInt('08', 10), 'ignores leading whitespace #4');
assert.same(parseInt(`${ WHITESPACES }0x16`), parseInt('0x16', 16), 'ignores leading whitespace #5');
const fakeZero = {
valueOf() {
return 0;
},
};
assert.same(parseInt('08', fakeZero), parseInt('08', 10), 'valueOf #1');
assert.same(parseInt('0x16', fakeZero), parseInt('0x16', 16), 'valueOf #2');
assert.same(parseInt('-0xF'), -15, 'signed hex #1');
assert.same(parseInt('-0xF', 16), -15, 'signed hex #2');
assert.same(parseInt('+0xF'), 15, 'signed hex #3');
assert.same(parseInt('+0xF', 16), 15, 'signed hex #4');
assert.same(parseInt('10', -4294967294), 2, 'radix uses ToUint32');
assert.same(parseInt(null), NaN);
assert.same(parseInt(undefined), NaN);
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
const symbol = Symbol('Number.parseInt test');
assert.throws(() => parseInt(symbol), 'throws on symbol argument');
assert.throws(() => parseInt(Object(symbol)), 'throws on boxed symbol argument');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.number.to-exponential.js
|
JavaScript
|
import toExponential from 'core-js-pure/es/number/virtual/to-exponential';
QUnit.test('Number#toExponential', assert => {
assert.isFunction(toExponential);
assert.same(toExponential.call(0.00008, 3), '8.000e-5');
assert.same(toExponential.call(0.9, 0), '9e-1');
assert.same(toExponential.call(1.255, 2), '1.25e+0');
assert.same(toExponential.call(1843654265.0774949, 5), '1.84365e+9');
assert.same(toExponential.call(1000000000000000128.0, 0), '1e+18');
assert.same(toExponential.call(1), '1e+0');
assert.same(toExponential.call(1, 0), '1e+0');
assert.same(toExponential.call(1, 1), '1.0e+0');
assert.same(toExponential.call(1, 1.1), '1.0e+0');
assert.same(toExponential.call(1, 0.9), '1e+0');
assert.same(toExponential.call(1, '0'), '1e+0');
assert.same(toExponential.call(1, '1'), '1.0e+0');
assert.same(toExponential.call(1, '1.1'), '1.0e+0');
assert.same(toExponential.call(1, '0.9'), '1e+0');
assert.same(toExponential.call(1, NaN), '1e+0');
assert.same(toExponential.call(1, 'some string'), '1e+0');
assert.notThrows(() => toExponential.call(1, -0.1) === '1e+0');
assert.same(toExponential.call(new Number(1)), '1e+0');
assert.same(toExponential.call(new Number(1), 0), '1e+0');
assert.same(toExponential.call(new Number(1), 1), '1.0e+0');
assert.same(toExponential.call(new Number(1), 1.1), '1.0e+0');
assert.same(toExponential.call(new Number(1), 0.9), '1e+0');
assert.same(toExponential.call(new Number(1), '0'), '1e+0');
assert.same(toExponential.call(new Number(1), '1'), '1.0e+0');
assert.same(toExponential.call(new Number(1), '1.1'), '1.0e+0');
assert.same(toExponential.call(new Number(1), '0.9'), '1e+0');
assert.same(toExponential.call(new Number(1), NaN), '1e+0');
assert.same(toExponential.call(new Number(1), 'some string'), '1e+0');
assert.notThrows(() => toExponential.call(new Number(1), -0.1) === '1e+0');
assert.same(toExponential.call(NaN), 'NaN');
assert.same(toExponential.call(NaN, 0), 'NaN');
assert.same(toExponential.call(NaN, 1), 'NaN');
assert.same(toExponential.call(NaN, 1.1), 'NaN');
assert.same(toExponential.call(NaN, 0.9), 'NaN');
assert.same(toExponential.call(NaN, '0'), 'NaN');
assert.same(toExponential.call(NaN, '1'), 'NaN');
assert.same(toExponential.call(NaN, '1.1'), 'NaN');
assert.same(toExponential.call(NaN, '0.9'), 'NaN');
assert.same(toExponential.call(NaN, NaN), 'NaN');
assert.same(toExponential.call(NaN, 'some string'), 'NaN');
assert.notThrows(() => toExponential.call(NaN, -0.1) === 'NaN');
assert.same(toExponential.call(new Number(1e21)), '1e+21');
assert.same(toExponential.call(new Number(1e21), 0), '1e+21');
assert.same(toExponential.call(new Number(1e21), 1), '1.0e+21');
assert.same(toExponential.call(new Number(1e21), 1.1), '1.0e+21');
assert.same(toExponential.call(new Number(1e21), 0.9), '1e+21');
assert.same(toExponential.call(new Number(1e21), '0'), '1e+21');
assert.same(toExponential.call(new Number(1e21), '1'), '1.0e+21');
assert.same(toExponential.call(new Number(1e21), '1.1'), '1.0e+21');
assert.same(toExponential.call(new Number(1e21), '0.9'), '1e+21');
assert.same(toExponential.call(new Number(1e21), NaN), '1e+21');
assert.same(toExponential.call(new Number(1e21), 'some string'), '1e+21');
assert.same(toExponential.call(5, 19), '5.0000000000000000000e+0');
// ported from tests262, the license: https://github.com/tc39/test262/blob/main/LICENSE
assert.same(toExponential.call(123.456, 0), '1e+2');
assert.same(toExponential.call(123.456, 1), '1.2e+2');
assert.same(toExponential.call(123.456, 2), '1.23e+2');
assert.same(toExponential.call(123.456, 3), '1.235e+2');
assert.same(toExponential.call(123.456, 4), '1.2346e+2');
assert.same(toExponential.call(123.456, 5), '1.23456e+2');
assert.same(toExponential.call(123.456, 6), '1.234560e+2');
assert.same(toExponential.call(123.456, 7), '1.2345600e+2');
// assert.same(toExponential.call(123.456, 17), '1.23456000000000003e+2');
// assert.same(toExponential.call(123.456, 20), '1.23456000000000003070e+2');
assert.same(toExponential.call(-123.456, 0), '-1e+2');
assert.same(toExponential.call(-123.456, 1), '-1.2e+2');
assert.same(toExponential.call(-123.456, 2), '-1.23e+2');
assert.same(toExponential.call(-123.456, 3), '-1.235e+2');
assert.same(toExponential.call(-123.456, 4), '-1.2346e+2');
assert.same(toExponential.call(-123.456, 5), '-1.23456e+2');
assert.same(toExponential.call(-123.456, 6), '-1.234560e+2');
assert.same(toExponential.call(-123.456, 7), '-1.2345600e+2');
// assert.same(toExponential.call(-123.456, 17), '-1.23456000000000003e+2');
// assert.same(toExponential.call(-123.456, 20), '-1.23456000000000003070e+2');
assert.same(toExponential.call(0.0001, 0), '1e-4');
assert.same(toExponential.call(0.0001, 1), '1.0e-4');
assert.same(toExponential.call(0.0001, 2), '1.00e-4');
assert.same(toExponential.call(0.0001, 3), '1.000e-4');
assert.same(toExponential.call(0.0001, 4), '1.0000e-4');
// assert.same(toExponential.call(0.0001, 16), '1.0000000000000000e-4');
// assert.same(toExponential.call(0.0001, 17), '1.00000000000000005e-4');
// assert.same(toExponential.call(0.0001, 18), '1.000000000000000048e-4');
// assert.same(toExponential.call(0.0001, 19), '1.0000000000000000479e-4');
// assert.same(toExponential.call(0.0001, 20), '1.00000000000000004792e-4');
assert.same(toExponential.call(0.9999, 0), '1e+0');
assert.same(toExponential.call(0.9999, 1), '1.0e+0');
assert.same(toExponential.call(0.9999, 2), '1.00e+0');
assert.same(toExponential.call(0.9999, 3), '9.999e-1');
assert.same(toExponential.call(0.9999, 4), '9.9990e-1');
// assert.same(toExponential.call(0.9999, 16), '9.9990000000000001e-1');
// assert.same(toExponential.call(0.9999, 17), '9.99900000000000011e-1');
// assert.same(toExponential.call(0.9999, 18), '9.999000000000000110e-1');
// assert.same(toExponential.call(0.9999, 19), '9.9990000000000001101e-1');
// assert.same(toExponential.call(0.9999, 20), '9.99900000000000011013e-1');
assert.same(toExponential.call(25, 0), '3e+1'); // FF86- and Chrome 49-50 bugs
assert.same(toExponential.call(12345, 3), '1.235e+4'); // FF86- and Chrome 49-50 bugs
assert.same(toExponential.call(Number.prototype, 0), '0e+0', 'Number.prototype, 0');
assert.same(toExponential.call(0, 0), '0e+0', '0, 0');
assert.same(toExponential.call(-0, 0), '0e+0', '-0, 0');
assert.same(toExponential.call(0, -0), '0e+0', '0, -0');
assert.same(toExponential.call(-0, -0), '0e+0', '-0, -0');
assert.same(toExponential.call(0, 1), '0.0e+0', '0 and 1');
assert.same(toExponential.call(0, 2), '0.00e+0', '0 and 2');
assert.same(toExponential.call(0, 7), '0.0000000e+0', '0 and 7');
assert.same(toExponential.call(0, 20), '0.00000000000000000000e+0', '0 and 20');
assert.same(toExponential.call(-0, 1), '0.0e+0', '-0 and 1');
assert.same(toExponential.call(-0, 2), '0.00e+0', '-0 and 2');
assert.same(toExponential.call(-0, 7), '0.0000000e+0', '-0 and 7');
assert.same(toExponential.call(-0, 20), '0.00000000000000000000e+0', '-0 and 20');
assert.same(toExponential.call(NaN, 1000), 'NaN', 'NaN check before fractionDigits check');
assert.same(toExponential.call(Infinity, 1000), 'Infinity', 'Infinity check before fractionDigits check');
assert.notThrows(() => toExponential.call(new Number(1e21), -0.1) === '1e+21');
assert.throws(() => toExponential.call(1.0, -101), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => toExponential.call(1.0, 101), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => toExponential.call({}, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toExponential.call('123', 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toExponential.call(false, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toExponential.call(null, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toExponential.call(undefined, 1), TypeError, '? thisNumberValue(this value)');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.number.to-fixed.js
|
JavaScript
|
import toFixed from 'core-js-pure/es/number/to-fixed';
QUnit.test('Number#toFixed', assert => {
assert.isFunction(toFixed);
assert.same(toFixed(0.00008, 3), '0.000');
assert.same(toFixed(0.9, 0), '1');
assert.same(toFixed(1.255, 2), '1.25');
assert.same(toFixed(1843654265.0774949, 5), '1843654265.07749');
assert.same(toFixed(1000000000000000128, 0), '1000000000000000128');
assert.same(toFixed(1), '1');
assert.same(toFixed(1, 0), '1');
assert.same(toFixed(1, 1), '1.0');
assert.same(toFixed(1, 1.1), '1.0');
assert.same(toFixed(1, 0.9), '1');
assert.same(toFixed(1, '0'), '1');
assert.same(toFixed(1, '1'), '1.0');
assert.same(toFixed(1, '1.1'), '1.0');
assert.same(toFixed(1, '0.9'), '1');
assert.same(toFixed(1, NaN), '1');
assert.same(toFixed(1, 'some string'), '1');
assert.notThrows(() => toFixed(1, -0.1) === '1');
assert.same(toFixed(Object(1)), '1');
assert.same(toFixed(Object(1), 0), '1');
assert.same(toFixed(Object(1), 1), '1.0');
assert.same(toFixed(Object(1), 1.1), '1.0');
assert.same(toFixed(Object(1), 0.9), '1');
assert.same(toFixed(Object(1), '0'), '1');
assert.same(toFixed(Object(1), '1'), '1.0');
assert.same(toFixed(Object(1), '1.1'), '1.0');
assert.same(toFixed(Object(1), '0.9'), '1');
assert.same(toFixed(Object(1), NaN), '1');
assert.same(toFixed(Object(1), 'some string'), '1');
assert.notThrows(() => toFixed(Object(1), -0.1) === '1');
assert.same(toFixed(NaN), 'NaN');
assert.same(toFixed(NaN, 0), 'NaN');
assert.same(toFixed(NaN, 1), 'NaN');
assert.same(toFixed(NaN, 1.1), 'NaN');
assert.same(toFixed(NaN, 0.9), 'NaN');
assert.same(toFixed(NaN, '0'), 'NaN');
assert.same(toFixed(NaN, '1'), 'NaN');
assert.same(toFixed(NaN, '1.1'), 'NaN');
assert.same(toFixed(NaN, '0.9'), 'NaN');
assert.same(toFixed(NaN, NaN), 'NaN');
assert.same(toFixed(NaN, 'some string'), 'NaN');
assert.notThrows(() => toFixed(NaN, -0.1) === 'NaN');
assert.same(toFixed(1e21), String(1e21));
assert.same(toFixed(1e21, 0), String(1e21));
assert.same(toFixed(1e21, 1), String(1e21));
assert.same(toFixed(1e21, 1.1), String(1e21));
assert.same(toFixed(1e21, 0.9), String(1e21));
assert.same(toFixed(1e21, '0'), String(1e21));
assert.same(toFixed(1e21, '1'), String(1e21));
assert.same(toFixed(1e21, '1.1'), String(1e21));
assert.same(toFixed(1e21, '0.9'), String(1e21));
assert.same(toFixed(1e21, NaN), String(1e21));
assert.same(toFixed(1e21, 'some string'), String(1e21));
assert.notThrows(() => toFixed(1e21, -0.1) === String(1e21));
assert.throws(() => toFixed(1, -101), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => toFixed(1, 101), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => toFixed(NaN, Infinity), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => toFixed({}, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed('123', 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed(false, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed(null, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed(undefined, 1), TypeError, '? thisNumberValue(this value)');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.number.to-precision.js
|
JavaScript
|
import toPrecision from 'core-js-pure/es/number/to-precision';
QUnit.test('Number#toPrecision', assert => {
assert.isFunction(toPrecision);
assert.same(toPrecision(0.00008, 3), '0.0000800', '0.00008.toPrecision(3)');
assert.same(toPrecision(1.255, 2), '1.3', '1.255.toPrecision(2)');
assert.same(toPrecision(1843654265.0774949, 13), '1843654265.077', '1843654265.0774949.toPrecision(13)');
assert.same(toPrecision(NaN, 1), 'NaN', 'If x is NaN, return the String "NaN".');
assert.same(toPrecision(123.456), '123.456', 'If precision is undefined, return ! ToString(x).');
assert.same(toPrecision(123.456, undefined), '123.456', 'If precision is undefined, return ! ToString(x).');
assert.throws(() => toPrecision(0.9, 0), RangeError, 'If p < 1 or p > 21, throw a RangeError exception.');
assert.throws(() => toPrecision(0.9, 101), RangeError, 'If p < 1 or p > 21, throw a RangeError exception.');
assert.throws(() => toPrecision({}, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toPrecision('123', 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toPrecision(false, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toPrecision(null, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toPrecision(undefined, 1), TypeError, '? thisNumberValue(this value)');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.assign.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import defineProperty from 'core-js-pure/es/object/define-property';
import keys from 'core-js-pure/es/object/keys';
import assign from 'core-js-pure/es/object/assign';
QUnit.test('Object.assign', assert => {
assert.isFunction(assign);
let object = { q: 1 };
assert.same(object, assign(object, { bar: 2 }), 'assign return target');
assert.same(object.bar, 2, 'assign define properties');
assert.deepEqual(assign({}, { q: 1 }, { w: 2 }), { q: 1, w: 2 });
assert.deepEqual(assign({}, 'qwe'), { 0: 'q', 1: 'w', 2: 'e' });
assert.throws(() => assign(null, { q: 1 }), TypeError);
assert.throws(() => assign(undefined, { q: 1 }), TypeError);
let string = assign('qwe', { q: 1 });
assert.same(typeof string, 'object');
assert.same(String(string), 'qwe');
assert.same(string.q, 1);
assert.same(assign({}, { valueOf: 42 }).valueOf, 42, 'IE enum keys bug');
if (DESCRIPTORS) {
object = { baz: 1 };
assign(object, defineProperty({}, 'bar', {
get() {
return this.baz + 1;
},
}));
assert.same(object.bar, undefined, "assign don't copy descriptors");
object = { a: 'a' };
const c = Symbol('c');
const d = Symbol('d');
object[c] = 'c';
defineProperty(object, 'b', { value: 'b' });
defineProperty(object, d, { value: 'd' });
const object2 = assign({}, object);
assert.same(object2.a, 'a', 'a');
assert.same(object2.b, undefined, 'b');
assert.same(object2[c], 'c', 'c');
assert.same(object2[d], undefined, 'd');
try {
assert.same(Function('assign', `
return assign({ b: 1 }, { get a() {
delete this.b;
}, b: 2 });
`)(assign).b, 1);
} catch { /* empty */ }
try {
assert.same(Function('assign', `
return assign({ b: 1 }, { get a() {
Object.defineProperty(this, "b", {
value: 4,
enumerable: false
});
}, b: 2 });
`)(assign).b, 1);
} catch { /* empty */ }
}
string = 'abcdefghijklmnopqrst';
const result = {};
for (let i = 0, { length } = string; i < length; ++i) {
const chr = string.charAt(i);
result[chr] = chr;
}
assert.same(keys(assign({}, result)).join(''), string);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.create.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
import getOwnPropertyNames from 'core-js-pure/es/object/get-own-property-names';
import create from 'core-js-pure/es/object/create';
QUnit.test('Object.create', assert => {
function getPropertyNames(object) {
let result = [];
do {
result = result.concat(getOwnPropertyNames(object));
} while (object = getPrototypeOf(object));
return result;
}
assert.isFunction(create);
assert.arity(create, 2);
let object = { q: 1 };
assert.true({}.isPrototypeOf.call(object, create(object)));
assert.same(create(object).q, 1);
function C() {
return this.a = 1;
}
assert.true(create(new C()) instanceof C);
assert.same(C.prototype, getPrototypeOf(getPrototypeOf(create(new C()))));
assert.same(create(new C()).a, 1);
assert.same(create({}, { a: { value: 42 } }).a, 42);
object = create(null, { w: { value: 2 } });
assert.same(object, Object(object));
assert.false('toString' in object);
assert.same(object.w, 2);
assert.deepEqual(getPropertyNames(create(null)), []);
});
QUnit.test('Object.create.sham flag', assert => {
assert.same(create.sham, DESCRIPTORS ? undefined : true);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.define-getter.js
|
JavaScript
|
/* eslint-disable id-match -- unification with global tests */
import { DESCRIPTORS, STRICT } from '../helpers/constants.js';
import __defineGetter__ from 'core-js-pure/es/object/define-getter';
import __defineSetter__ from 'core-js-pure/es/object/define-setter';
if (DESCRIPTORS) {
QUnit.test('Object#__defineGetter__', assert => {
assert.isFunction(__defineGetter__);
const object = {};
assert.same(__defineGetter__(object, 'key', () => 42), undefined, 'void');
assert.same(object.key, 42, 'works');
__defineSetter__(object, 'key', function () {
this.foo = 43;
});
object.key = 44;
assert.same(object.key, 42, 'works with setter #1');
assert.same(object.foo, 43, 'works with setter #2');
if (STRICT) {
assert.throws(() => __defineGetter__(null, 1, () => { /* empty */ }), TypeError, 'Throws on null as `this`');
assert.throws(() => __defineGetter__(undefined, 1, () => { /* empty */ }), TypeError, 'Throws on undefined as `this`');
}
});
}
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.define-properties.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import defineProperties from 'core-js-pure/es/object/define-properties';
QUnit.test('Object.defineProperties', assert => {
assert.isFunction(defineProperties);
assert.arity(defineProperties, 2);
const source = {};
const result = defineProperties(source, { q: { value: 42 }, w: { value: 33 } });
assert.same(result, source);
assert.same(result.q, 42);
assert.same(result.w, 33);
if (DESCRIPTORS) {
// eslint-disable-next-line prefer-arrow-callback -- required for testing
assert.same(defineProperties(function () { /* empty */ }, { prototype: {
value: 42,
writable: false,
} }).prototype, 42, 'function prototype with non-writable descriptor');
}
});
QUnit.test('Object.defineProperties.sham flag', assert => {
assert.same(defineProperties.sham, DESCRIPTORS ? undefined : true);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.define-property.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import create from 'core-js-pure/es/object/create';
import defineProperty from 'core-js-pure/es/object/define-property';
QUnit.test('Object.defineProperty', assert => {
assert.isFunction(defineProperty);
assert.arity(defineProperty, 3);
const source = {};
const result = defineProperty(source, 'q', {
value: 42,
});
assert.same(result, source);
assert.same(result.q, 42);
if (DESCRIPTORS) {
// eslint-disable-next-line prefer-arrow-callback -- required for testing
assert.same(defineProperty(function () { /* empty */ }, 'prototype', {
value: 42,
writable: false,
}).prototype, 42, 'function prototype with non-writable descriptor');
}
assert.throws(() => defineProperty(42, 1, {}));
assert.throws(() => defineProperty({}, create(null), {}));
assert.throws(() => defineProperty({}, 1, 1));
});
QUnit.test('Object.defineProperty.sham flag', assert => {
assert.same(defineProperty.sham, DESCRIPTORS ? undefined : true);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.define-setter.js
|
JavaScript
|
/* eslint-disable id-match -- unification with global tests */
import { DESCRIPTORS, STRICT } from '../helpers/constants.js';
import __defineGetter__ from 'core-js-pure/es/object/define-getter';
import __defineSetter__ from 'core-js-pure/es/object/define-setter';
if (DESCRIPTORS) {
QUnit.test('Object#__defineSetter__', assert => {
assert.isFunction(__defineSetter__);
let object = {};
assert.same(__defineSetter__(object, 'key', function () {
this.foo = 43;
}), undefined, 'void');
object.key = 44;
assert.same(object.foo, 43, 'works');
object = {};
__defineSetter__(object, 'key', function () {
this.foo = 43;
});
__defineGetter__(object, 'key', () => 42);
object.key = 44;
assert.same(object.key, 42, 'works with getter #1');
assert.same(object.foo, 43, 'works with getter #2');
if (STRICT) {
assert.throws(() => __defineSetter__(null, 1, () => { /* empty */ }), TypeError, 'Throws on null as `this`');
assert.throws(() => __defineSetter__(undefined, 1, () => { /* empty */ }), TypeError, 'Throws on undefined as `this`');
}
});
}
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.entries.js
|
JavaScript
|
import assign from 'core-js-pure/es/object/assign';
import create from 'core-js-pure/es/object/create';
import entries from 'core-js-pure/es/object/entries';
QUnit.test('Object.entries', assert => {
assert.isFunction(entries);
assert.arity(entries, 1);
assert.name(entries, 'entries');
assert.deepEqual(entries({ q: 1, w: 2, e: 3 }), [['q', 1], ['w', 2], ['e', 3]]);
assert.deepEqual(entries(new String('qwe')), [['0', 'q'], ['1', 'w'], ['2', 'e']]);
assert.deepEqual(entries(assign(create({ q: 1, w: 2, e: 3 }), { a: 4, s: 5, d: 6 })), [['a', 4], ['s', 5], ['d', 6]]);
assert.deepEqual(entries({ valueOf: 42 }), [['valueOf', 42]], 'IE enum keys bug');
try {
assert.deepEqual(Function('entries', `
return entries({ a: 1, get b() {
delete this.c;
return 2;
}, c: 3 });
`)(entries), [['a', 1], ['b', 2]]);
} catch { /* empty */ }
try {
assert.deepEqual(Function('entries', `
return entries({ a: 1, get b() {
Object.defineProperty(this, "c", {
value: 4,
enumerable: false
});
return 2
}, c: 3 });
`)(entries), [['a', 1], ['b', 2]]);
} catch { /* empty */ }
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.freeze.js
|
JavaScript
|
import ownKeys from 'core-js-pure/es/reflect/own-keys';
import keys from 'core-js-pure/es/object/keys';
import getOwnPropertyNames from 'core-js-pure/es/object/get-own-property-names';
import getOwnPropertySymbols from 'core-js-pure/es/object/get-own-property-symbols';
import freeze from 'core-js-pure/es/object/freeze';
QUnit.test('Object.freeze', assert => {
assert.isFunction(freeze);
assert.arity(freeze, 1);
const data = [42, 'foo', false, null, undefined, {}];
for (const value of data) {
assert.notThrows(() => freeze(value) || true, `accept ${ {}.toString.call(value).slice(8, -1) }`);
assert.same(freeze(value), value, `returns target on ${ {}.toString.call(value).slice(8, -1) }`);
}
const results = [];
for (const key in freeze({})) results.push(key);
assert.arrayEqual(results, []);
assert.arrayEqual(keys(freeze({})), []);
assert.arrayEqual(getOwnPropertyNames(freeze({})), []);
assert.arrayEqual(getOwnPropertySymbols(freeze({})), []);
assert.arrayEqual(ownKeys(freeze({})), []);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.from-entries.js
|
JavaScript
|
import { createIterable } from '../helpers/helpers.js';
import Set from 'core-js-pure/es/set';
import fromEntries from 'core-js-pure/es/object/from-entries';
QUnit.test('Object.fromEntries', assert => {
assert.isFunction(fromEntries);
assert.arity(fromEntries, 1);
assert.name(fromEntries, 'fromEntries');
assert.true(fromEntries([]) instanceof Object);
assert.same(fromEntries([['foo', 1]]).foo, 1);
assert.same(fromEntries(createIterable([['bar', 2]])).bar, 2);
class Unit {
constructor(id) {
this.id = id;
}
toString() {
return `unit${ this.id }`;
}
}
const units = new Set([new Unit(101), new Unit(102), new Unit(103)]);
const object = fromEntries(units.entries());
assert.same(object.unit101.id, 101);
assert.same(object.unit102.id, 102);
assert.same(object.unit103.id, 103);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.get-own-property-descriptor.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import getOwnPropertyDescriptor from 'core-js-pure/es/object/get-own-property-descriptor';
QUnit.test('Object.getOwnPropertyDescriptor', assert => {
assert.isFunction(getOwnPropertyDescriptor);
assert.arity(getOwnPropertyDescriptor, 2);
assert.deepEqual(getOwnPropertyDescriptor({ q: 42 }, 'q'), {
writable: true,
enumerable: true,
configurable: true,
value: 42,
});
assert.same(getOwnPropertyDescriptor({}, 'toString'), undefined);
const primitives = [42, 'foo', false];
for (const value of primitives) {
assert.notThrows(() => getOwnPropertyDescriptor(value) || true, `accept ${ typeof value }`);
}
assert.throws(() => getOwnPropertyDescriptor(null), TypeError, 'throws on null');
assert.throws(() => getOwnPropertyDescriptor(undefined), TypeError, 'throws on undefined');
});
QUnit.test('Object.getOwnPropertyDescriptor.sham flag', assert => {
assert.same(getOwnPropertyDescriptor.sham, DESCRIPTORS ? undefined : true);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.get-own-property-descriptors.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import create from 'core-js-pure/es/object/create';
import getOwnPropertyDescriptors from 'core-js-pure/es/object/get-own-property-descriptors';
QUnit.test('Object.getOwnPropertyDescriptors', assert => {
assert.isFunction(getOwnPropertyDescriptors);
const object = create({ q: 1 }, { e: { value: 3 } });
object.w = 2;
const symbol = Symbol('4');
object[symbol] = 4;
const descriptors = getOwnPropertyDescriptors(object);
assert.same(descriptors.q, undefined);
assert.deepEqual(descriptors.w, {
enumerable: true,
configurable: true,
writable: true,
value: 2,
});
if (DESCRIPTORS) {
assert.deepEqual(descriptors.e, {
enumerable: false,
configurable: false,
writable: false,
value: 3,
});
} else {
assert.deepEqual(descriptors.e, {
enumerable: true,
configurable: true,
writable: true,
value: 3,
});
}
assert.same(descriptors[symbol].value, 4);
});
QUnit.test('Object.getOwnPropertyDescriptors.sham flag', assert => {
assert.same(getOwnPropertyDescriptors.sham, DESCRIPTORS ? undefined : true);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.get-own-property-names.js
|
JavaScript
|
import { includes } from '../helpers/helpers.js';
import freeze from 'core-js-pure/es/object/freeze';
import getOwnPropertyNames from 'core-js-pure/es/object/get-own-property-names';
QUnit.test('Object.getOwnPropertyNames', assert => {
assert.isFunction(getOwnPropertyNames);
assert.arity(getOwnPropertyNames, 1);
function F1() {
this.w = 1;
}
function F2() {
this.toString = 1;
}
F1.prototype.q = F2.prototype.q = 1;
const names = getOwnPropertyNames([1, 2, 3]);
assert.same(names.length, 4);
assert.true(includes(names, '0'));
assert.true(includes(names, '1'));
assert.true(includes(names, '2'));
assert.true(includes(names, 'length'));
assert.deepEqual(getOwnPropertyNames(new F1()), ['w']);
assert.deepEqual(getOwnPropertyNames(new F2()), ['toString']);
assert.true(includes(getOwnPropertyNames(Array.prototype), 'toString'));
assert.true(includes(getOwnPropertyNames(Object.prototype), 'toString'));
assert.true(includes(getOwnPropertyNames(Object.prototype), 'constructor'));
assert.deepEqual(getOwnPropertyNames(freeze({})), [], 'frozen');
const primitives = [42, 'foo', false];
for (const value of primitives) {
assert.notThrows(() => getOwnPropertyNames(value), `accept ${ typeof value }`);
}
assert.throws(() => getOwnPropertyNames(null), TypeError, 'throws on null');
assert.throws(() => getOwnPropertyNames(undefined), TypeError, 'throws on undefined');
/* Chakra bug
if (typeof document != 'undefined' && document.createElement) {
assert.notThrows(() => {
const iframe = document.createElement('iframe');
iframe.src = 'http://example.com';
document.documentElement.appendChild(iframe);
const window = iframe.contentWindow;
document.documentElement.removeChild(iframe);
return getOwnPropertyNames(window);
}, 'IE11 bug with iframe and window');
}
*/
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.get-own-property-symbols.js
|
JavaScript
|
import create from 'core-js-pure/es/object/create';
import getOwnPropertyNames from 'core-js-pure/es/object/get-own-property-names';
import getOwnPropertySymbols from 'core-js-pure/es/object/get-own-property-symbols';
import Symbol from 'core-js-pure/es/symbol';
QUnit.test('Object.getOwnPropertySymbols', assert => {
assert.isFunction(getOwnPropertySymbols);
const prototype = { q: 1, w: 2, e: 3 };
prototype[Symbol('getOwnPropertySymbols test 1')] = 42;
prototype[Symbol('getOwnPropertySymbols test 2')] = 43;
assert.deepEqual(getOwnPropertyNames(prototype).sort(), ['e', 'q', 'w']);
assert.same(getOwnPropertySymbols(prototype).length, 2);
const object = create(prototype);
object.a = 1;
object.s = 2;
object.d = 3;
object[Symbol('getOwnPropertySymbols test 3')] = 44;
assert.deepEqual(getOwnPropertyNames(object).sort(), ['a', 'd', 's']);
assert.same(getOwnPropertySymbols(object).length, 1);
assert.same(getOwnPropertySymbols(Object.prototype).length, 0);
const primitives = [42, 'foo', false];
for (const value of primitives) {
assert.notThrows(() => getOwnPropertySymbols(value), `accept ${ typeof value }`);
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.get-prototype-of.js
|
JavaScript
|
import { CORRECT_PROTOTYPE_GETTER } from '../helpers/constants.js';
import create from 'core-js-pure/es/object/create';
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
QUnit.test('Object.getPrototypeOf', assert => {
assert.isFunction(getPrototypeOf);
assert.arity(getPrototypeOf, 1);
assert.same(getPrototypeOf({}), Object.prototype);
assert.same(getPrototypeOf([]), Array.prototype);
function F() { /* empty */ }
assert.same(getPrototypeOf(new F()), F.prototype);
const object = { q: 1 };
assert.same(getPrototypeOf(create(object)), object);
assert.same(getPrototypeOf(create(null)), null);
assert.same(getPrototypeOf(getPrototypeOf({})), null);
function Foo() { /* empty */ }
Foo.prototype.foo = 'foo';
function Bar() { /* empty */ }
Bar.prototype = create(Foo.prototype);
Bar.prototype.constructor = Bar;
assert.same(getPrototypeOf(Bar.prototype).foo, 'foo');
const primitives = [42, 'foo', false];
for (const value of primitives) {
assert.notThrows(() => getPrototypeOf(value), `accept ${ typeof value }`);
}
assert.throws(() => getPrototypeOf(null), TypeError, 'throws on null');
assert.throws(() => getPrototypeOf(undefined), TypeError, 'throws on undefined');
assert.same(getPrototypeOf('foo'), String.prototype);
});
QUnit.test('Object.getPrototypeOf.sham flag', assert => {
assert.same(getPrototypeOf.sham, CORRECT_PROTOTYPE_GETTER ? undefined : true);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.group-by.js
|
JavaScript
|
import { createIterable } from '../helpers/helpers.js';
import groupBy from 'core-js-pure/es/object/group-by';
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
import entries from 'core-js-pure/es/object/entries';
import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Object.groupBy', assert => {
assert.isFunction(groupBy);
assert.arity(groupBy, 2);
assert.name(groupBy, 'groupBy');
assert.same(getPrototypeOf(groupBy([], it => it)), null);
assert.deepEqual(entries(groupBy([], it => it)), []);
assert.deepEqual(entries(groupBy([1, 2], it => it ** 2)), [['1', [1]], ['4', [2]]]);
assert.deepEqual(entries(groupBy([1, 2, 1], it => it ** 2)), [['1', [1, 1]], ['4', [2]]]);
assert.deepEqual(entries(groupBy(createIterable([1, 2]), it => it ** 2)), [['1', [1]], ['4', [2]]]);
assert.deepEqual(entries(groupBy('qwe', it => it)), [['q', ['q']], ['w', ['w']], ['e', ['e']]], 'iterable string');
const element = {};
groupBy([element], function (it, i) {
assert.same(arguments.length, 2);
assert.same(it, element);
assert.same(i, 0);
});
const even = Symbol('even');
const odd = Symbol('odd');
const grouped = groupBy([1, 2, 3, 4, 5, 6], num => {
if (num % 2 === 0) return even;
return odd;
});
assert.deepEqual(grouped[even], [2, 4, 6]);
assert.deepEqual(grouped[odd], [1, 3, 5]);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.has-own.js
|
JavaScript
|
import create from 'core-js-pure/es/object/create';
import hasOwn from 'core-js-pure/es/object/has-own';
QUnit.test('Object.hasOwn', assert => {
assert.isFunction(hasOwn);
assert.arity(hasOwn, 2);
assert.name(hasOwn, 'hasOwn');
assert.true(hasOwn({ q: 42 }, 'q'));
assert.false(hasOwn({ q: 42 }, 'w'));
assert.false(hasOwn(create({ q: 42 }), 'q'));
assert.true(hasOwn(Object.prototype, 'hasOwnProperty'));
let called = false;
try {
hasOwn(null, { toString() { called = true; } });
} catch { /* empty */ }
assert.false(called, 'modern behaviour');
assert.throws(() => hasOwn(null, 'foo'), TypeError, 'throws on null');
assert.throws(() => hasOwn(undefined, 'foo'), TypeError, 'throws on undefined');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.is-extensible.js
|
JavaScript
|
import isExtensible from 'core-js-pure/es/object/is-extensible';
QUnit.test('Object.isExtensible', assert => {
assert.isFunction(isExtensible);
assert.arity(isExtensible, 1);
const primitives = [42, 'string', false, null, undefined];
for (const value of primitives) {
assert.notThrows(() => isExtensible(value) || true, `accept ${ value }`);
assert.false(isExtensible(value), `returns false on ${ value }`);
}
assert.true(isExtensible({}));
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.is-frozen.js
|
JavaScript
|
import isFrozen from 'core-js-pure/es/object/is-frozen';
QUnit.test('Object.isFrozen', assert => {
assert.isFunction(isFrozen);
assert.arity(isFrozen, 1);
const primitives = [42, 'string', false, null, undefined];
for (const value of primitives) {
assert.notThrows(() => isFrozen(value) || true, `accept ${ value }`);
assert.true(isFrozen(value), `returns true on ${ value }`);
}
assert.false(isFrozen({}));
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.is-sealed.js
|
JavaScript
|
import isSealed from 'core-js-pure/es/object/is-sealed';
QUnit.test('Object.isSealed', assert => {
assert.isFunction(isSealed);
assert.arity(isSealed, 1);
const primitives = [42, 'string', false, null, undefined];
for (const value of primitives) {
assert.notThrows(() => isSealed(value) || true, `accept ${ value }`);
assert.true(isSealed(value), `returns true on ${ value }`);
}
assert.false(isSealed({}));
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.is.js
|
JavaScript
|
import is from 'core-js-pure/es/object/is';
QUnit.test('Object.is', assert => {
assert.isFunction(is);
assert.true(is(1, 1), '1 is 1');
assert.true(is(NaN, NaN), '1 is 1');
assert.false(is(0, -0), '0 is not -0');
assert.false(is({}, {}), '{} is not {}');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.keys.js
|
JavaScript
|
import { includes } from '../helpers/helpers.js';
import keys from 'core-js-pure/es/object/keys';
QUnit.test('Object.keys', assert => {
assert.isFunction(keys);
assert.arity(keys, 1);
function F1() {
this.w = 1;
}
function F2() {
this.toString = 1;
}
F1.prototype.q = F2.prototype.q = 1;
assert.deepEqual(keys([1, 2, 3]), ['0', '1', '2']);
assert.deepEqual(keys(new F1()), ['w']);
assert.deepEqual(keys(new F2()), ['toString']);
assert.false(includes(keys(Array.prototype), 'push'));
const primitives = [42, 'foo', false];
for (const value of primitives) {
assert.notThrows(() => keys(value), `accept ${ typeof value }`);
}
assert.throws(() => keys(null), TypeError, 'throws on null');
assert.throws(() => keys(undefined), TypeError, 'throws on undefined');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.lookup-getter.js
|
JavaScript
|
/* eslint-disable id-match -- unification with global tests */
import { DESCRIPTORS, STRICT } from '../helpers/constants.js';
import create from 'core-js-pure/es/object/create';
import __defineGetter__ from 'core-js-pure/es/object/define-getter';
import __lookupGetter__ from 'core-js-pure/es/object/lookup-getter';
if (DESCRIPTORS) {
QUnit.test('Object#__lookupGetter__', assert => {
assert.isFunction(__lookupGetter__);
assert.same(__lookupGetter__({}, 'key'), undefined, 'empty object');
assert.same(__lookupGetter__({ key: 42 }, 'key'), undefined, 'data descriptor');
const object = {};
function getter() { /* empty */ }
__defineGetter__(object, 'key', getter);
assert.same(__lookupGetter__(object, 'key'), getter, 'own getter');
assert.same(__lookupGetter__(create(object), 'key'), getter, 'proto getter');
assert.same(__lookupGetter__(create(object), 'foo'), undefined, 'empty proto');
if (STRICT) {
assert.throws(() => __lookupGetter__(null, 1, () => { /* empty */ }), TypeError, 'Throws on null as `this`');
assert.throws(() => __lookupGetter__(undefined, 1, () => { /* empty */ }), TypeError, 'Throws on undefined as `this`');
}
});
}
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.lookup-setter.js
|
JavaScript
|
/* eslint-disable id-match -- unification with global tests */
import { DESCRIPTORS, STRICT } from '../helpers/constants.js';
import create from 'core-js-pure/es/object/create';
import __defineSetter__ from 'core-js-pure/es/object/define-setter';
import __lookupSetter__ from 'core-js-pure/es/object/lookup-setter';
if (DESCRIPTORS) {
QUnit.test('Object#__lookupSetter__', assert => {
assert.isFunction(__lookupSetter__);
assert.same(__lookupSetter__({}, 'key'), undefined, 'empty object');
assert.same(__lookupSetter__({ key: 42 }, 'key'), undefined, 'data descriptor');
const object = {};
function setter() { /* empty */ }
__defineSetter__(object, 'key', setter);
assert.same(__lookupSetter__(object, 'key'), setter, 'own getter');
assert.same(__lookupSetter__(create(object), 'key'), setter, 'proto getter');
assert.same(__lookupSetter__(create(object), 'foo'), undefined, 'empty proto');
if (STRICT) {
assert.throws(() => __lookupSetter__(null, 1, () => { /* empty */ }), TypeError, 'Throws on null as `this`');
assert.throws(() => __lookupSetter__(undefined, 1, () => { /* empty */ }), TypeError, 'Throws on undefined as `this`');
}
});
}
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.prevent-extensions.js
|
JavaScript
|
import ownKeys from 'core-js-pure/es/reflect/own-keys';
import keys from 'core-js-pure/es/object/keys';
import getOwnPropertyNames from 'core-js-pure/es/object/get-own-property-names';
import getOwnPropertySymbols from 'core-js-pure/es/object/get-own-property-symbols';
import preventExtensions from 'core-js-pure/es/object/prevent-extensions';
QUnit.test('Object.preventExtensions', assert => {
assert.isFunction(preventExtensions);
assert.arity(preventExtensions, 1);
const data = [42, 'foo', false, null, undefined, {}];
for (const value of data) {
assert.notThrows(() => preventExtensions(value) || true, `accept ${ {}.toString.call(value).slice(8, -1) }`);
assert.same(preventExtensions(value), value, `returns target on ${ {}.toString.call(value).slice(8, -1) }`);
}
const results = [];
for (const key in preventExtensions({})) results.push(key);
assert.arrayEqual(results, []);
assert.arrayEqual(keys(preventExtensions({})), []);
assert.arrayEqual(getOwnPropertyNames(preventExtensions({})), []);
assert.arrayEqual(getOwnPropertySymbols(preventExtensions({})), []);
assert.arrayEqual(ownKeys(preventExtensions({})), []);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.seal.js
|
JavaScript
|
import ownKeys from 'core-js-pure/es/reflect/own-keys';
import keys from 'core-js-pure/es/object/keys';
import getOwnPropertyNames from 'core-js-pure/es/object/get-own-property-names';
import getOwnPropertySymbols from 'core-js-pure/es/object/get-own-property-symbols';
import seal from 'core-js-pure/es/object/seal';
QUnit.test('Object.seal', assert => {
assert.isFunction(seal);
assert.arity(seal, 1);
const data = [42, 'foo', false, null, undefined, {}];
for (const value of data) {
assert.notThrows(() => seal(value) || true, `accept ${ {}.toString.call(value).slice(8, -1) }`);
assert.same(seal(value), value, `returns target on ${ {}.toString.call(value).slice(8, -1) }`);
}
const results = [];
for (const key in seal({})) results.push(key);
assert.arrayEqual(results, []);
assert.arrayEqual(keys(seal({})), []);
assert.arrayEqual(getOwnPropertyNames(seal({})), []);
assert.arrayEqual(getOwnPropertySymbols(seal({})), []);
assert.arrayEqual(ownKeys(seal({})), []);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.set-prototype-of.js
|
JavaScript
|
import { PROTO } from '../helpers/constants.js';
import setPrototypeOf from 'core-js-pure/es/object/set-prototype-of';
if (PROTO) QUnit.test('Object.setPrototypeOf', assert => {
assert.isFunction(setPrototypeOf);
assert.true('apply' in setPrototypeOf({}, Function.prototype), 'Parent properties in target');
assert.same(setPrototypeOf({ a: 2 }, {
b() {
return this.a ** 2;
},
}).b(), 4, 'Child and parent properties in target');
const object = {};
assert.same(setPrototypeOf(object, { a: 1 }), object, 'setPrototypeOf return target');
assert.false('toString' in setPrototypeOf({}, null), 'Can set null as prototype');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.object.values.js
|
JavaScript
|
import assign from 'core-js-pure/es/object/assign';
import create from 'core-js-pure/es/object/create';
import values from 'core-js-pure/es/object/values';
QUnit.test('Object.values', assert => {
assert.isFunction(values);
assert.arity(values, 1);
assert.name(values, 'values');
assert.deepEqual(values({ q: 1, w: 2, e: 3 }), [1, 2, 3]);
assert.deepEqual(values(new String('qwe')), ['q', 'w', 'e']);
assert.deepEqual(values(assign(create({ q: 1, w: 2, e: 3 }), { a: 4, s: 5, d: 6 })), [4, 5, 6]);
assert.deepEqual(values({ valueOf: 42 }), [42], 'IE enum keys bug');
try {
assert.deepEqual(Function('values', `
return values({ a: 1, get b() {
delete this.c;
return 2;
}, c: 3 });
`)(values), [1, 2]);
} catch { /* empty */ }
try {
assert.deepEqual(Function('values', `
return values({ a: 1, get b() {
Object.defineProperty(this, "c", {
value: 4,
enumerable: false
});
return 2;
}, c: 3 });
`)(values), [1, 2]);
} catch { /* empty */ }
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.parse-float.js
|
JavaScript
|
import { WHITESPACES } from '../helpers/constants.js';
import parseFloat from 'core-js-pure/es/parse-float';
QUnit.test('parseFloat', assert => {
assert.isFunction(parseFloat);
assert.arity(parseFloat, 1);
assert.same(parseFloat('0'), 0);
assert.same(parseFloat(' 0'), 0);
assert.same(parseFloat('+0'), 0);
assert.same(parseFloat(' +0'), 0);
assert.same(parseFloat('-0'), -0);
assert.same(parseFloat(' -0'), -0);
assert.same(parseFloat(`${ WHITESPACES }+0`), 0);
assert.same(parseFloat(`${ WHITESPACES }-0`), -0);
assert.same(parseFloat(null), NaN);
assert.same(parseFloat(undefined), NaN);
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
const symbol = Symbol('parseFloat test');
assert.throws(() => parseFloat(symbol), 'throws on symbol argument');
assert.throws(() => parseFloat(Object(symbol)), 'throws on boxed symbol argument');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.parse-int.js
|
JavaScript
|
/* eslint-disable prefer-numeric-literals -- required for testing */
import { WHITESPACES } from '../helpers/constants.js';
import parseInt from 'core-js-pure/es/parse-int';
QUnit.test('parseInt', assert => {
assert.isFunction(parseInt);
assert.arity(parseInt, 2);
for (let radix = 2; radix <= 36; ++radix) {
assert.same(parseInt('10', radix), radix, `radix ${ radix }`);
}
const strings = ['01', '08', '10', '42'];
for (const string of strings) {
assert.same(parseInt(string), parseInt(string, 10), `default radix is 10: ${ string }`);
}
assert.same(parseInt('0x16'), parseInt('0x16', 16), 'default radix is 16: 0x16');
assert.same(parseInt(' 0x16'), parseInt('0x16', 16), 'ignores leading whitespace #1');
assert.same(parseInt(' 42'), parseInt('42', 10), 'ignores leading whitespace #2');
assert.same(parseInt(' 08'), parseInt('08', 10), 'ignores leading whitespace #3');
assert.same(parseInt(`${ WHITESPACES }08`), parseInt('08', 10), 'ignores leading whitespace #4');
assert.same(parseInt(`${ WHITESPACES }0x16`), parseInt('0x16', 16), 'ignores leading whitespace #5');
const fakeZero = {
valueOf() {
return 0;
},
};
assert.same(parseInt('08', fakeZero), parseInt('08', 10), 'valueOf #1');
assert.same(parseInt('0x16', fakeZero), parseInt('0x16', 16), 'valueOf #2');
assert.same(parseInt('-0xF'), -15, 'signed hex #1');
assert.same(parseInt('-0xF', 16), -15, 'signed hex #2');
assert.same(parseInt('+0xF'), 15, 'signed hex #3');
assert.same(parseInt('+0xF', 16), 15, 'signed hex #4');
assert.same(parseInt('10', -4294967294), 2, 'radix uses ToUint32');
assert.same(parseInt(null), NaN);
assert.same(parseInt(undefined), NaN);
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
const symbol = Symbol('parseInt test');
assert.throws(() => parseInt(symbol), 'throws on symbol argument');
assert.throws(() => parseInt(Object(symbol)), 'throws on boxed symbol argument');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.all-settled.js
|
JavaScript
|
import { createIterable } from '../helpers/helpers.js';
import $allSettled from 'core-js-pure/es/promise/all-settled';
import bind from 'core-js-pure/es/function/bind';
import getIteratorMethod from 'core-js-pure/es/get-iterator-method';
import Promise from 'core-js-pure/es/promise';
import Symbol from 'core-js-pure/es/symbol';
QUnit.test('Promise.allSettled', assert => {
assert.isFunction(Promise.allSettled);
assert.arity(Promise.allSettled, 1);
assert.true(Promise.allSettled([1, 2, 3]) instanceof Promise, 'returns a promise');
});
QUnit.test('Promise.allSettled, resolved', assert => {
return Promise.allSettled([
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3),
]).then(it => {
assert.deepEqual(it, [
{ value: 1, status: 'fulfilled' },
{ value: 2, status: 'fulfilled' },
{ value: 3, status: 'fulfilled' },
], 'resolved with a correct value');
});
});
QUnit.test('Promise.allSettled, resolved with rejection', assert => {
return Promise.allSettled([
Promise.resolve(1),
Promise.reject(2),
Promise.resolve(3),
]).then(it => {
assert.deepEqual(it, [
{ value: 1, status: 'fulfilled' },
{ reason: 2, status: 'rejected' },
{ value: 3, status: 'fulfilled' },
], 'resolved with a correct value');
});
});
QUnit.test('Promise.allSettled, rejected', assert => {
// eslint-disable-next-line promise/valid-params -- required for testing
return Promise.allSettled().then(() => {
assert.avoid();
}, () => {
assert.required('rejected as expected');
});
});
QUnit.test('Promise.allSettled, resolved with timeouts', assert => {
return Promise.allSettled([
Promise.resolve(1),
new Promise(resolve => setTimeout(() => resolve(2), 10)),
Promise.resolve(3),
]).then(it => {
assert.deepEqual(it, [
{ value: 1, status: 'fulfilled' },
{ value: 2, status: 'fulfilled' },
{ value: 3, status: 'fulfilled' },
], 'keeps correct mapping, even with delays');
});
});
QUnit.test('Promise.allSettled, subclassing', assert => {
const { allSettled, resolve } = Promise;
function SubPromise(executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
}
SubPromise.resolve = bind(resolve, Promise);
assert.true(allSettled.call(SubPromise, [1, 2, 3]) instanceof SubPromise, 'subclassing, `this` pattern');
function FakePromise1() { /* empty */ }
function FakePromise2(executor) {
executor(null, () => { /* empty */ });
}
function FakePromise3(executor) {
executor(() => { /* empty */ }, null);
}
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = bind(resolve, Promise);
assert.throws(() => {
allSettled.call(FakePromise1, [1, 2, 3]);
}, 'NewPromiseCapability validations, #1');
assert.throws(() => {
allSettled.call(FakePromise2, [1, 2, 3]);
}, 'NewPromiseCapability validations, #2');
assert.throws(() => {
allSettled.call(FakePromise3, [1, 2, 3]);
}, 'NewPromiseCapability validations, #3');
});
QUnit.test('Promise.allSettled, iterables', assert => {
const iterable = createIterable([1, 2, 3]);
Promise.allSettled(iterable).catch(() => { /* empty */ });
assert.true(iterable.received, 'works with iterables: iterator received');
assert.true(iterable.called, 'works with iterables: next called');
});
QUnit.test('Promise.allSettled, iterables 2', assert => {
const array = [];
let done = false;
// eslint-disable-next-line es/no-nonstandard-array-prototype-properties -- legacy FF case
array['@@iterator'] = undefined;
array[Symbol.iterator] = function () {
done = true;
return getIteratorMethod([]).call(this);
};
Promise.allSettled(array);
assert.true(done);
});
QUnit.test('Promise.allSettled, iterator closing', assert => {
const { resolve } = Promise;
let done = false;
try {
Promise.resolve = function () {
throw new Error();
};
Promise.allSettled(createIterable([1, 2, 3], {
return() {
done = true;
},
})).catch(() => { /* empty */ });
} catch { /* empty */ }
Promise.resolve = resolve;
assert.true(done, 'iteration closing');
});
QUnit.test('Promise.allSettled, without constructor context', assert => {
const { allSettled } = Promise;
assert.throws(() => allSettled([]), TypeError, 'Throws if called without a constructor context');
assert.throws(() => allSettled.call(null, []), TypeError, 'Throws if called with null as this');
});
QUnit.test('Promise.allSettled, method from direct entry, without constructor context', assert => {
return $allSettled([
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3),
]).then(it => {
assert.deepEqual(it, [
{ value: 1, status: 'fulfilled' },
{ value: 2, status: 'fulfilled' },
{ value: 3, status: 'fulfilled' },
], 'resolved with a correct value');
});
});
QUnit.test('Promise.allSettled, method from direct entry, with null context', assert => {
return $allSettled.call(null, [
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3),
]).then(it => {
assert.deepEqual(it, [
{ value: 1, status: 'fulfilled' },
{ value: 2, status: 'fulfilled' },
{ value: 3, status: 'fulfilled' },
], 'resolved with a correct value');
});
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.all.js
|
JavaScript
|
import { createIterable } from '../helpers/helpers.js';
import bind from 'core-js-pure/es/function/bind';
import getIteratorMethod from 'core-js-pure/es/get-iterator-method';
import Promise from 'core-js-pure/es/promise';
import Symbol from 'core-js-pure/es/symbol';
QUnit.test('Promise.all', assert => {
const { all } = Promise;
assert.isFunction(all);
assert.arity(all, 1);
assert.name(all, 'all');
assert.true(Promise.all([]) instanceof Promise, 'returns a promise');
});
QUnit.test('Promise.all, resolved', assert => {
return Promise.all([
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3),
]).then(it => {
assert.deepEqual(it, [1, 2, 3], 'resolved with a correct value');
});
});
QUnit.test('Promise.all, resolved with rejection', assert => {
return Promise.all([
Promise.resolve(1),
Promise.reject(2),
Promise.resolve(3),
]).then(() => {
assert.avoid();
}, error => {
assert.same(error, 2, 'rejected with a correct value');
});
});
QUnit.test('Promise.all, resolved with empty array', assert => {
return Promise.all([]).then(it => {
assert.deepEqual(it, [], 'resolved with a correct value');
});
});
QUnit.test('Promise.all, resolved with timeouts', assert => {
return Promise.all([
Promise.resolve(1),
new Promise(resolve => setTimeout(() => resolve(2), 10)),
Promise.resolve(3),
]).then(it => {
assert.deepEqual(it, [1, 2, 3], 'keeps correct mapping, even with delays');
});
});
QUnit.test('Promise.all, subclassing', assert => {
const { all, resolve } = Promise;
function SubPromise(executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
}
SubPromise.resolve = bind(resolve, Promise);
assert.true(all.call(SubPromise, [1, 2, 3]) instanceof SubPromise, 'subclassing, `this` pattern');
function FakePromise1() { /* empty */ }
function FakePromise2(executor) {
executor(null, () => { /* empty */ });
}
function FakePromise3(executor) {
executor(() => { /* empty */ }, null);
}
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = bind(resolve, Promise);
assert.throws(() => {
all.call(FakePromise1, [1, 2, 3]);
}, 'NewPromiseCapability validations, #1');
assert.throws(() => {
all.call(FakePromise2, [1, 2, 3]);
}, 'NewPromiseCapability validations, #2');
assert.throws(() => {
all.call(FakePromise3, [1, 2, 3]);
}, 'NewPromiseCapability validations, #3');
});
QUnit.test('Promise.all, iterables', assert => {
const iterable = createIterable([1, 2, 3]);
Promise.all(iterable).catch(() => { /* empty */ });
assert.true(iterable.received, 'works with iterables: iterator received');
assert.true(iterable.called, 'works with iterables: next called');
});
QUnit.test('Promise.all, iterables 2', assert => {
const array = [];
let done = false;
// eslint-disable-next-line es/no-nonstandard-array-prototype-properties -- legacy FF case
array['@@iterator'] = undefined;
array[Symbol.iterator] = function () {
done = true;
return getIteratorMethod([]).call(this);
};
Promise.all(array);
assert.true(done);
});
QUnit.test('Promise.all, iterator closing', assert => {
const { resolve } = Promise;
let done = false;
try {
Promise.resolve = function () {
throw new Error();
};
Promise.all(createIterable([1, 2, 3], {
return() {
done = true;
},
})).catch(() => { /* empty */ });
} catch { /* empty */ }
Promise.resolve = resolve;
assert.true(done, 'iteration closing');
});
QUnit.test('Promise.all, without constructor context', assert => {
const { all } = Promise;
assert.throws(() => all([]), TypeError, 'Throws if called without a constructor context');
assert.throws(() => all.call(null, []), TypeError, 'Throws if called with null as this');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.any.js
|
JavaScript
|
import { createIterable } from '../helpers/helpers.js';
import $any from 'core-js-pure/es/promise/any';
import AggregateError from 'core-js-pure/es/aggregate-error';
import bind from 'core-js-pure/es/function/bind';
import getIteratorMethod from 'core-js-pure/es/get-iterator-method';
import Promise from 'core-js-pure/es/promise';
import Symbol from 'core-js-pure/es/symbol';
QUnit.test('Promise.any', assert => {
assert.isFunction(Promise.any);
assert.arity(Promise.any, 1);
assert.true(Promise.any([1, 2, 3]) instanceof Promise, 'returns a promise');
});
QUnit.test('Promise.any, resolved', assert => {
return Promise.any([
Promise.resolve(1),
Promise.reject(2),
Promise.resolve(3),
]).then(it => {
assert.same(it, 1, 'resolved with a correct value');
});
});
QUnit.test('Promise.any, rejected #1', assert => {
return Promise.any([
Promise.reject(1),
Promise.reject(2),
Promise.reject(3),
]).then(() => {
assert.avoid();
}, error => {
assert.true(error instanceof AggregateError, 'instanceof AggregateError');
assert.deepEqual(error.errors, [1, 2, 3], 'rejected with a correct value');
});
});
QUnit.test('Promise.any, rejected #2', assert => {
// eslint-disable-next-line promise/valid-params -- required for testing
return Promise.any().then(() => {
assert.avoid();
}, () => {
assert.required('rejected as expected');
});
});
QUnit.test('Promise.any, rejected #3', assert => {
return Promise.any([]).then(() => {
assert.avoid();
}, error => {
assert.true(error instanceof AggregateError, 'instanceof AggregateError');
assert.deepEqual(error.errors, [], 'rejected with a correct value');
});
});
QUnit.test('Promise.any, resolved with timeout', assert => {
return Promise.any([
new Promise(resolve => setTimeout(() => resolve(1), 50)),
Promise.resolve(2),
]).then(it => {
assert.same(it, 2, 'resolved with a correct value');
});
});
QUnit.test('Promise.any, subclassing', assert => {
const { any, resolve } = Promise;
function SubPromise(executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
}
SubPromise.resolve = bind(resolve, Promise);
assert.true(any.call(SubPromise, [1, 2, 3]) instanceof SubPromise, 'subclassing, `this` pattern');
function FakePromise1() { /* empty */ }
function FakePromise2(executor) {
executor(null, () => { /* empty */ });
}
function FakePromise3(executor) {
executor(() => { /* empty */ }, null);
}
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = bind(resolve, Promise);
assert.throws(() => {
any.call(FakePromise1, [1, 2, 3]);
}, 'NewPromiseCapability validations, #1');
assert.throws(() => {
any.call(FakePromise2, [1, 2, 3]);
}, 'NewPromiseCapability validations, #2');
assert.throws(() => {
any.call(FakePromise3, [1, 2, 3]);
}, 'NewPromiseCapability validations, #3');
});
QUnit.test('Promise.any, iterables', assert => {
const iterable = createIterable([1, 2, 3]);
Promise.any(iterable).catch(() => { /* empty */ });
assert.true(iterable.received, 'works with iterables: iterator received');
assert.true(iterable.called, 'works with iterables: next called');
});
QUnit.test('Promise.any, empty iterables', assert => {
const array = [];
let done = false;
// eslint-disable-next-line es/no-nonstandard-array-prototype-properties -- legacy FF case
array['@@iterator'] = undefined;
array[Symbol.iterator] = function () {
done = true;
return getIteratorMethod([]).call(this);
};
return Promise.any(array).then(() => {
assert.avoid();
}, error => {
assert.true(error instanceof AggregateError, 'instanceof AggregateError');
assert.true(done, 'iterator called');
});
});
QUnit.test('Promise.any, iterator closing', assert => {
const { resolve } = Promise;
let done = false;
try {
Promise.resolve = function () {
throw new Error();
};
Promise.any(createIterable([1, 2, 3], {
return() {
done = true;
},
})).catch(() => { /* empty */ });
} catch { /* empty */ }
Promise.resolve = resolve;
assert.true(done, 'iteration closing');
});
QUnit.test('Promise.any, without constructor context', assert => {
const { any } = Promise;
assert.throws(() => any([]), TypeError, 'Throws if called without a constructor context');
assert.throws(() => any.call(null, []), TypeError, 'Throws if called with null as this');
});
QUnit.test('Promise.any, method from direct entry, without constructor context', assert => {
return $any([
Promise.resolve(1),
Promise.resolve(2),
]).then(it => {
assert.same(it, 1, 'resolved with a correct value');
});
});
QUnit.test('Promise.any, method from direct entry, with null context', assert => {
return $any.call(null, [
Promise.resolve(1),
Promise.resolve(2),
]).then(it => {
assert.same(it, 1, 'resolved with a correct value');
});
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.catch.js
|
JavaScript
|
import Promise from 'core-js-pure/es/promise';
import Symbol from 'core-js-pure/es/symbol';
QUnit.test('Promise#catch', assert => {
assert.isFunction(Promise.prototype.catch);
assert.nonEnumerable(Promise.prototype, 'catch');
let promise = new Promise(resolve => {
resolve(42);
});
const FakePromise1 = promise.constructor = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
const FakePromise2 = FakePromise1[Symbol.species] = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
assert.true(promise.catch(() => { /* empty */ }) instanceof FakePromise2, 'subclassing, @@species pattern');
promise = new Promise(resolve => {
resolve(42);
});
promise.constructor = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
assert.true(promise.catch(() => { /* empty */ }) instanceof Promise, 'subclassing, incorrect `this` pattern');
promise = new Promise(resolve => {
resolve(42);
});
const FakePromise3 = promise.constructor = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
FakePromise3[Symbol.species] = function () { /* empty */ };
assert.throws(() => {
promise.catch(() => { /* empty */ });
}, 'NewPromiseCapability validations, #1');
FakePromise3[Symbol.species] = function (executor) {
executor(null, () => { /* empty */ });
};
assert.throws(() => {
promise.catch(() => { /* empty */ });
}, 'NewPromiseCapability validations, #2');
FakePromise3[Symbol.species] = function (executor) {
executor(() => { /* empty */ }, null);
};
assert.throws(() => {
promise.catch(() => { /* empty */ });
}, 'NewPromiseCapability validations, #3');
assert.same(Promise.prototype.catch.call({
// eslint-disable-next-line unicorn/no-thenable -- required for testing
then(x, y) {
return y;
},
}, 42), 42, 'calling `.then`');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.constructor.js
|
JavaScript
|
import { DESCRIPTORS, GLOBAL, PROTO, STRICT } from '../helpers/constants.js';
import Promise from 'core-js-pure/es/promise';
import Symbol from 'core-js-pure/es/symbol';
import setPrototypeOf from 'core-js-pure/es/object/set-prototype-of';
import create from 'core-js-pure/es/object/create';
QUnit.test('Promise', assert => {
assert.isFunction(Promise);
new Promise(function (resolve, reject) {
assert.isFunction(resolve, 'resolver is function');
assert.isFunction(reject, 'rejector is function');
if (STRICT) assert.same(this, undefined, 'correct executor context');
});
assert.throws(() => {
// eslint-disable-next-line sonarjs/inconsistent-function-call -- required for testing
Promise();
}, 'throws w/o `new`');
});
if (DESCRIPTORS) QUnit.test('Promise operations order', assert => {
let $resolve, $resolve2;
assert.expect(1);
const EXPECTED_ORDER = 'DEHAFGBC';
const async = assert.async();
let result = '';
const promise1 = new Promise(resolve => {
$resolve = resolve;
});
$resolve({
// eslint-disable-next-line unicorn/no-thenable -- required for testing
then() {
result += 'A';
throw new Error();
},
});
promise1.catch(() => {
result += 'B';
});
promise1.catch(() => {
result += 'C';
assert.same(result, EXPECTED_ORDER);
async();
});
const promise2 = new Promise(resolve => {
$resolve2 = resolve;
});
// eslint-disable-next-line es/no-object-defineproperty, unicorn/no-thenable -- required for testing
$resolve2(Object.defineProperty({}, 'then', {
get() {
result += 'D';
throw new Error();
},
}));
result += 'E';
promise2.catch(() => {
result += 'F';
});
promise2.catch(() => {
result += 'G';
});
result += 'H';
setTimeout(() => {
if (!~result.indexOf('C')) {
assert.same(result, EXPECTED_ORDER);
async();
}
}, 1e3);
});
QUnit.test('Promise#then', assert => {
assert.isFunction(Promise.prototype.then);
assert.nonEnumerable(Promise.prototype, 'then');
let promise = new Promise(resolve => {
resolve(42);
});
const FakePromise1 = promise.constructor = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
const FakePromise2 = FakePromise1[Symbol.species] = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
assert.true(promise.then(() => { /* empty */ }) instanceof FakePromise2, 'subclassing, @@species pattern');
promise = new Promise(resolve => {
resolve(42);
});
promise.constructor = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
assert.true(promise.then(() => { /* empty */ }) instanceof Promise, 'subclassing, incorrect `this` pattern');
promise = new Promise(resolve => {
resolve(42);
});
const FakePromise3 = promise.constructor = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
FakePromise3[Symbol.species] = function () { /* empty */ };
assert.throws(() => {
promise.then(() => { /* empty */ });
}, 'NewPromiseCapability validations, #1');
FakePromise3[Symbol.species] = function (executor) {
executor(null, () => { /* empty */ });
};
assert.throws(() => {
promise.then(() => { /* empty */ });
}, 'NewPromiseCapability validations, #2');
FakePromise3[Symbol.species] = function (executor) {
executor(() => { /* empty */ }, null);
};
assert.throws(() => {
promise.then(() => { /* empty */ });
}, 'NewPromiseCapability validations, #3');
});
QUnit.test('Promise#@@toStringTag', assert => {
assert.same(Promise.prototype[Symbol.toStringTag], 'Promise', 'Promise::@@toStringTag is `Promise`');
assert.same(String(new Promise(() => { /* empty */ })), '[object Promise]', 'correct stringification');
});
if (PROTO) QUnit.test('Promise subclassing', assert => {
function SubPromise(executor) {
const self = new Promise(executor);
setPrototypeOf(self, SubPromise.prototype);
self.mine = 'subclass';
return self;
}
setPrototypeOf(SubPromise, Promise);
SubPromise.prototype = create(Promise.prototype);
SubPromise.prototype.constructor = SubPromise;
let promise1 = SubPromise.resolve(5);
assert.same(promise1.mine, 'subclass');
promise1 = promise1.then(it => {
assert.same(it, 5);
});
assert.same(promise1.mine, 'subclass');
let promise2 = new SubPromise(resolve => {
resolve(6);
});
assert.same(promise2.mine, 'subclass');
promise2 = promise2.then(it => {
assert.same(it, 6);
});
assert.same(promise2.mine, 'subclass');
const promise3 = SubPromise.all([promise1, promise2]);
assert.same(promise3.mine, 'subclass');
assert.true(promise3 instanceof Promise);
assert.true(promise3 instanceof SubPromise);
promise3.then(assert.async(), error => {
assert.avoid(error);
});
});
// qunit@2.5 strange bug
QUnit.skip('Unhandled rejection tracking', assert => {
let done = false;
const resume = assert.async();
if (GLOBAL.process) {
assert.expect(3);
function onunhandledrejection(reason, promise) {
process.removeListener('unhandledRejection', onunhandledrejection);
assert.same(promise, $promise, 'unhandledRejection, promise');
assert.same(reason, 42, 'unhandledRejection, reason');
$promise.catch(() => {
// empty
});
}
function onrejectionhandled(promise) {
process.removeListener('rejectionHandled', onrejectionhandled);
assert.same(promise, $promise, 'rejectionHandled, promise');
done || resume();
done = true;
}
process.on('unhandledRejection', onunhandledrejection);
process.on('rejectionHandled', onrejectionhandled);
} else {
if (GLOBAL.addEventListener) {
assert.expect(8);
function onunhandledrejection(it) {
assert.same(it.promise, $promise, 'addEventListener(unhandledrejection), promise');
assert.same(it.reason, 42, 'addEventListener(unhandledrejection), reason');
GLOBAL.removeEventListener('unhandledrejection', onunhandledrejection);
}
GLOBAL.addEventListener('rejectionhandled', onunhandledrejection);
function onrejectionhandled(it) {
assert.same(it.promise, $promise, 'addEventListener(rejectionhandled), promise');
assert.same(it.reason, 42, 'addEventListener(rejectionhandled), reason');
GLOBAL.removeEventListener('rejectionhandled', onrejectionhandled);
}
GLOBAL.addEventListener('rejectionhandled', onrejectionhandled);
} else assert.expect(4);
GLOBAL.onunhandledrejection = function (it) {
assert.same(it.promise, $promise, 'onunhandledrejection, promise');
assert.same(it.reason, 42, 'onunhandledrejection, reason');
setTimeout(() => {
$promise.catch(() => {
// empty
});
}, 1);
GLOBAL.onunhandledrejection = null;
};
GLOBAL.onrejectionhandled = function (it) {
assert.same(it.promise, $promise, 'onrejectionhandled, promise');
assert.same(it.reason, 42, 'onrejectionhandled, reason');
GLOBAL.onrejectionhandled = null;
done || resume();
done = true;
};
}
Promise.reject(43).catch(() => {
// empty
});
const $promise = Promise.reject(42);
setTimeout(() => {
done || resume();
done = true;
}, 3e3);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.finally.js
|
JavaScript
|
import Promise from 'core-js-pure/es/promise';
QUnit.test('Promise#finally', assert => {
assert.isFunction(Promise.prototype.finally);
assert.arity(Promise.prototype.finally, 1);
assert.nonEnumerable(Promise.prototype, 'finally');
assert.true(Promise.resolve(42).finally(() => { /* empty */ }) instanceof Promise, 'returns a promise');
});
QUnit.test('Promise#finally, resolved', assert => {
let called = 0;
let argument = null;
return Promise.resolve(42).finally(it => {
called++;
argument = it;
}).then(it => {
assert.same(it, 42, 'resolved with a correct value');
assert.same(called, 1, 'onFinally function called one time');
assert.same(argument, undefined, 'onFinally function called with a correct argument');
});
});
QUnit.test('Promise#finally, rejected', assert => {
let called = 0;
let argument = null;
return Promise.reject(42).finally(it => {
called++;
argument = it;
}).then(() => {
assert.avoid();
}, () => {
assert.same(called, 1, 'onFinally function called one time');
assert.same(argument, undefined, 'onFinally function called with a correct argument');
});
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.race.js
|
JavaScript
|
import { createIterable } from '../helpers/helpers.js';
import bind from 'core-js-pure/es/function/bind';
import getIteratorMethod from 'core-js-pure/es/get-iterator-method';
import Promise from 'core-js-pure/es/promise';
import Symbol from 'core-js-pure/es/symbol';
QUnit.test('Promise.race', assert => {
const { race } = Promise;
assert.isFunction(race);
assert.arity(race, 1);
assert.name(race, 'race');
assert.true(Promise.race([]) instanceof Promise, 'returns a promise');
});
QUnit.test('Promise.race, resolved', assert => {
return Promise.race([
Promise.resolve(1),
Promise.resolve(2),
]).then(it => {
assert.same(it, 1, 'resolved with a correct value');
});
});
QUnit.test('Promise.race, resolved with rejection', assert => {
return Promise.race([
Promise.reject(1),
Promise.resolve(2),
]).then(() => {
assert.avoid();
}, error => {
assert.same(error, 1, 'rejected with a correct value');
});
});
QUnit.test('Promise.race, resolved with timeouts', assert => {
return Promise.race([
new Promise(resolve => setTimeout(() => resolve(1), 50)),
Promise.resolve(2),
]).then(it => {
assert.same(it, 2, 'keeps correct mapping, even with delays');
});
});
QUnit.test('Promise.race, subclassing', assert => {
const { race, resolve } = Promise;
function SubPromise(executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
}
SubPromise.resolve = bind(resolve, Promise);
assert.true(race.call(SubPromise, [1, 2, 3]) instanceof SubPromise, 'subclassing, `this` pattern');
function FakePromise1() { /* empty */ }
function FakePromise2(executor) {
executor(null, () => { /* empty */ });
}
function FakePromise3(executor) {
executor(() => { /* empty */ }, null);
}
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = bind(resolve, Promise);
assert.throws(() => {
race.call(FakePromise1, [1, 2, 3]);
}, 'NewPromiseCapability validations, #1');
assert.throws(() => {
race.call(FakePromise2, [1, 2, 3]);
}, 'NewPromiseCapability validations, #2');
assert.throws(() => {
race.call(FakePromise3, [1, 2, 3]);
}, 'NewPromiseCapability validations, #3');
});
QUnit.test('Promise.race, iterables', assert => {
const iterable = createIterable([1, 2, 3]);
Promise.race(iterable).catch(() => { /* empty */ });
assert.true(iterable.received, 'works with iterables: iterator received');
assert.true(iterable.called, 'works with iterables: next called');
});
QUnit.test('Promise.race, iterables 2', assert => {
const array = [];
let done = false;
// eslint-disable-next-line es/no-nonstandard-array-prototype-properties -- legacy FF case
array['@@iterator'] = undefined;
array[Symbol.iterator] = function () {
done = true;
return getIteratorMethod([]).call(this);
};
Promise.race(array);
assert.true(done);
});
QUnit.test('Promise.race, iterator closing', assert => {
const { resolve } = Promise;
let done = false;
try {
Promise.resolve = function () {
throw new Error();
};
Promise.race(createIterable([1, 2, 3], {
return() {
done = true;
},
})).catch(() => { /* empty */ });
} catch { /* empty */ }
Promise.resolve = resolve;
assert.true(done, 'iteration closing');
});
QUnit.test('Promise.race, without constructor context', assert => {
const { race } = Promise;
assert.throws(() => race([]), TypeError, 'Throws if called without a constructor context');
assert.throws(() => race.call(null, []), TypeError, 'Throws if called with null as this');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.reject.js
|
JavaScript
|
import Promise from 'core-js-pure/es/promise';
QUnit.test('Promise.reject', assert => {
const { reject } = Promise;
assert.isFunction(reject);
assert.name(reject, 'reject');
});
QUnit.test('Promise.reject, rejects with value', assert => {
return Promise.reject(42)
.then(() => {
assert.avoid('Should not resolve');
}, error => {
assert.same(error, 42, 'rejected with correct reason');
});
});
QUnit.test('Promise.reject, rejects with undefined', assert => {
return Promise.reject()
.then(() => {
assert.avoid('Should not resolve');
}, error => {
assert.same(error, undefined, 'rejected with correct reason');
});
});
QUnit.test('Promise.reject, subclassing', assert => {
const { reject } = Promise;
function SubPromise(executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
}
assert.true(reject.call(SubPromise, 42) instanceof SubPromise, 'subclassing, `this` pattern');
function FakePromise1() { /* empty */ }
function FakePromise2(executor) {
executor(null, () => { /* empty */ });
}
function FakePromise3(executor) {
executor(() => { /* empty */ }, null);
}
assert.throws(() => {
reject.call(FakePromise1, 42);
}, 'NewPromiseCapability validations, #1');
assert.throws(() => {
reject.call(FakePromise2, 42);
}, 'NewPromiseCapability validations, #2');
assert.throws(() => {
reject.call(FakePromise3, 42);
}, 'NewPromiseCapability validations, #3');
});
QUnit.test('Promise.reject, without constructor context', assert => {
const { reject } = Promise;
assert.throws(() => reject(''), TypeError, 'Throws if called without a constructor context');
assert.throws(() => reject.call(null, ''), TypeError, 'Throws if called with null as this');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.resolve.js
|
JavaScript
|
import Promise from 'core-js-pure/es/promise';
import Symbol from 'core-js-pure/es/symbol';
QUnit.test('Promise.resolve', assert => {
const { resolve } = Promise;
assert.isFunction(resolve);
assert.true(Promise.resolve(42) instanceof Promise, 'returns a promise');
});
QUnit.test('Promise.resolve, resolves with value', assert => {
return Promise.resolve(42).then(result => {
assert.same(result, 42, 'resolved with a correct value');
});
});
QUnit.test('Promise.resolve, resolves with thenable', assert => {
const thenable = {
// eslint-disable-next-line unicorn/no-thenable -- safe
then(resolve) { resolve('foo'); },
};
return Promise.resolve(thenable).then(result => {
assert.same(result, 'foo', 'resolved with a correct value');
});
});
QUnit.test('Promise.resolve, returns input if input is already promise', assert => {
const p = Promise.resolve('ok');
assert.same(Promise.resolve(p), p, 'resolved with a correct value');
});
QUnit.test('Promise.resolve, resolves with undefined', assert => {
return Promise.resolve().then(result => {
assert.same(result, undefined, 'resolved with a correct value');
});
});
QUnit.test('Promise.resolve, subclassing', assert => {
const { resolve } = Promise;
function SubPromise(executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
}
SubPromise[Symbol.species] = function (executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
};
assert.true(resolve.call(SubPromise, 42) instanceof SubPromise, 'subclassing, `this` pattern');
function FakePromise1() { /* empty */ }
function FakePromise2(executor) {
executor(null, () => { /* empty */ });
}
function FakePromise3(executor) {
executor(() => { /* empty */ }, null);
}
assert.throws(() => {
resolve.call(FakePromise1, 42);
}, 'NewPromiseCapability validations, #1');
assert.throws(() => {
resolve.call(FakePromise2, 42);
}, 'NewPromiseCapability validations, #2');
assert.throws(() => {
resolve.call(FakePromise3, 42);
}, 'NewPromiseCapability validations, #3');
});
QUnit.test('Promise.resolve, without constructor context', assert => {
const { resolve } = Promise;
assert.throws(() => resolve(''), TypeError, 'Throws if called without a constructor context');
assert.throws(() => resolve.call(null, ''), TypeError, 'Throws if called with null as this');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.try.js
|
JavaScript
|
import $try from 'core-js-pure/es/promise/try';
import bind from 'core-js-pure/es/function/bind';
import Promise from 'core-js-pure/es/promise';
QUnit.test('Promise.try', assert => {
assert.isFunction(Promise.try);
assert.arity(Promise.try, 1);
assert.true(Promise.try(() => 42) instanceof Promise, 'returns a promise');
});
QUnit.test('Promise.try, resolved', assert => {
return Promise.try(() => 42).then(it => {
assert.same(it, 42, 'resolved with a correct value');
});
});
QUnit.test('Promise.try, resolved, with args', assert => {
return Promise.try((a, b) => Promise.resolve(a + b), 1, 2).then(it => {
assert.same(it, 3, 'resolved with a correct value');
});
});
QUnit.test('Promise.try, rejected', assert => {
return Promise.try(() => {
throw new Error();
}).then(() => {
assert.avoid();
}, () => {
assert.true(true, 'rejected as expected');
});
});
QUnit.test('Promise.try, subclassing', assert => {
const { try: promiseTry, resolve } = Promise;
function SubPromise(executor) {
executor(() => { /* empty */ }, () => { /* empty */ });
}
SubPromise.resolve = bind(resolve, Promise);
assert.true(promiseTry.call(SubPromise, () => 42) instanceof SubPromise, 'subclassing, `this` pattern');
function FakePromise1() { /* empty */ }
function FakePromise2(executor) {
executor(null, () => { /* empty */ });
}
function FakePromise3(executor) {
executor(() => { /* empty */ }, null);
}
FakePromise1.resolve = FakePromise2.resolve = FakePromise3.resolve = bind(resolve, Promise);
assert.throws(() => {
promiseTry.call(FakePromise1, () => 42);
}, 'NewPromiseCapability validations, #1');
assert.throws(() => {
promiseTry.call(FakePromise2, () => 42);
}, 'NewPromiseCapability validations, #2');
assert.throws(() => {
promiseTry.call(FakePromise3, () => 42);
}, 'NewPromiseCapability validations, #3');
});
QUnit.test('Promise.try, without constructor context', assert => {
const { try: promiseTry } = Promise;
assert.throws(() => promiseTry(() => 42), TypeError, 'Throws if called without a constructor context');
assert.throws(() => promiseTry.call(null, () => 42), TypeError, 'Throws if called with null as this');
});
QUnit.test('Promise.try, method from direct entry, without constructor context', assert => {
return $try(() => 123).then(it => {
assert.same(it, 123, 'resolved with a correct value');
});
});
QUnit.test('Promise.try, method from direct entry, with null context', assert => {
return $try.call(null, () => 'foo').then(it => {
assert.same(it, 'foo', 'resolved with a correct value');
});
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.promise.with-resolvers.js
|
JavaScript
|
import Promise from 'core-js-pure/es/promise';
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
QUnit.test('Promise.withResolvers', assert => {
const { withResolvers } = Promise;
assert.isFunction(withResolvers);
assert.arity(withResolvers, 0);
assert.name(withResolvers, 'withResolvers');
const d1 = Promise.withResolvers();
assert.same(getPrototypeOf(d1), Object.prototype, 'proto is Object.prototype');
assert.true(d1.promise instanceof Promise, 'promise is promise');
assert.isFunction(d1.resolve, 'resolve is function');
assert.isFunction(d1.reject, 'reject is function');
const promise = {};
const resolve = () => { /* empty */ };
let reject = () => { /* empty */ };
function P(exec) {
exec(resolve, reject);
return promise;
}
const d2 = withResolvers.call(P);
assert.same(d2.promise, promise, 'promise is promise #2');
assert.same(d2.resolve, resolve, 'resolve is resolve #2');
assert.same(d2.reject, reject, 'reject is reject #2');
reject = {};
assert.throws(() => withResolvers.call(P), TypeError, 'broken resolver');
assert.throws(() => withResolvers.call({}), TypeError, 'broken constructor #1');
assert.throws(() => withResolvers.call(null), TypeError, 'broken constructor #2');
});
QUnit.test('Promise.withResolvers, resolve', assert => {
const d = Promise.withResolvers();
d.resolve(42);
return d.promise.then(it => {
assert.same(it, 42, 'resolved as expected');
}, () => {
assert.avoid();
});
});
QUnit.test('Promise.withResolvers, reject', assert => {
const d = Promise.withResolvers();
d.reject(42);
return d.promise.then(() => {
assert.avoid();
}, error => {
assert.same(error, 42, 'rejected as expected');
});
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.apply.js
|
JavaScript
|
import apply from 'core-js-pure/es/reflect/apply';
QUnit.test('Reflect.apply', assert => {
assert.isFunction(apply);
assert.arity(apply, 3);
if ('name' in apply) {
assert.name(apply, 'apply');
}
assert.same(apply(Array.prototype.push, [1, 2], [3, 4, 5]), 5);
function F(a, b, c) {
return a + b + c;
}
F.apply = 42;
assert.same(apply(F, null, ['foo', 'bar', 'baz']), 'foobarbaz', 'works with redefined apply');
assert.throws(() => apply(42, null, []), TypeError, 'throws on primitive');
assert.throws(() => apply(() => { /* empty */ }, null), TypeError, 'throws without third argument');
assert.throws(() => apply(() => { /* empty */ }, null, '123'), TypeError, 'throws on primitive as third argument');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.construct.js
|
JavaScript
|
import construct from 'core-js-pure/es/reflect/construct';
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
QUnit.test('Reflect.construct', assert => {
assert.isFunction(construct);
assert.arity(construct, 2);
if ('name' in construct) {
assert.name(construct, 'construct');
}
function A(a, b, c) {
this.qux = a + b + c;
}
assert.same(construct(A, ['foo', 'bar', 'baz']).qux, 'foobarbaz', 'basic');
A.apply = 42;
assert.same(construct(A, ['foo', 'bar', 'baz']).qux, 'foobarbaz', 'works with redefined apply');
const instance = construct(function () {
this.x = 42;
}, [], Array);
assert.same(instance.x, 42, 'constructor with newTarget');
assert.true(instance instanceof Array, 'prototype with newTarget');
assert.throws(() => construct(42, []), TypeError, 'throws on primitive');
function B() { /* empty */ }
B.prototype = 42;
assert.notThrows(() => getPrototypeOf(construct(B, [])) === Object.prototype);
assert.notThrows(() => typeof construct(Date, []).getTime() == 'number', 'works with native constructors with 2 arguments');
assert.throws(() => construct(() => { /* empty */ }), 'throws when the second argument is not an object');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.define-property.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import getOwnPropertyDescriptor from 'core-js-pure/es/object/get-own-property-descriptor';
import create from 'core-js-pure/es/object/create';
import defineProperty from 'core-js-pure/es/reflect/define-property';
QUnit.test('Reflect.defineProperty', assert => {
assert.isFunction(defineProperty);
assert.arity(defineProperty, 3);
if ('name' in defineProperty) {
assert.name(defineProperty, 'defineProperty');
}
let object = {};
assert.true(defineProperty(object, 'foo', { value: 123 }));
assert.same(object.foo, 123);
if (DESCRIPTORS) {
object = {};
defineProperty(object, 'foo', {
value: 123,
enumerable: true,
});
assert.deepEqual(getOwnPropertyDescriptor(object, 'foo'), {
value: 123,
enumerable: true,
configurable: false,
writable: false,
});
assert.false(defineProperty(object, 'foo', {
value: 42,
}));
}
assert.throws(() => defineProperty(42, 'foo', {
value: 42,
}), TypeError, 'throws on primitive');
assert.throws(() => defineProperty(42, 1, {}));
assert.throws(() => defineProperty({}, create(null), {}));
assert.throws(() => defineProperty({}, 1, 1));
// ToPropertyDescriptor errors should throw, not return false
assert.throws(() => defineProperty({}, 'a', { get: 42 }), TypeError, 'throws on non-callable getter');
assert.throws(() => defineProperty({}, 'a', { set: 'str' }), TypeError, 'throws on non-callable setter');
assert.throws(() => defineProperty({}, 'a', { get: null }), TypeError, 'throws on null getter');
assert.throws(() => defineProperty({}, 'a', { get: false }), TypeError, 'throws on false getter');
if (DESCRIPTORS) {
assert.throws(() => defineProperty({}, 'a', { get() { /* empty */ }, value: 1 }), TypeError, 'throws on mixed accessor/data descriptor');
assert.true(defineProperty({}, 'a', { get: undefined }), 'undefined getter is valid');
}
});
QUnit.test('Reflect.defineProperty.sham flag', assert => {
assert.same(defineProperty.sham, DESCRIPTORS ? undefined : true);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.delete-property.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import { createConversionChecker } from '../helpers/helpers.js';
import keys from 'core-js-pure/es/object/keys';
import defineProperty from 'core-js-pure/es/object/define-property';
import deleteProperty from 'core-js-pure/es/reflect/delete-property';
QUnit.test('Reflect.deleteProperty', assert => {
assert.isFunction(deleteProperty);
assert.arity(deleteProperty, 2);
if ('name' in deleteProperty) {
assert.name(deleteProperty, 'deleteProperty');
}
const object = { bar: 456 };
assert.true(deleteProperty(object, 'bar'));
assert.same(keys(object).length, 0);
if (DESCRIPTORS) {
assert.false(deleteProperty(defineProperty({}, 'foo', {
value: 42,
}), 'foo'));
}
assert.throws(() => deleteProperty(42, 'foo'), TypeError, 'throws on primitive');
// ToPropertyKey should be called exactly once
const keyObj = createConversionChecker(1, 'bar');
deleteProperty({ bar: 1 }, keyObj);
assert.same(keyObj.$valueOf, 0, 'ToPropertyKey called once in Reflect.deleteProperty, #1');
assert.same(keyObj.$toString, 1, 'ToPropertyKey called once in Reflect.deleteProperty, #2');
// argument order: target should be validated before ToPropertyKey
const orderChecker = createConversionChecker(1, 'qux');
assert.throws(() => deleteProperty(42, orderChecker), TypeError, 'throws on primitive before ToPropertyKey');
assert.same(orderChecker.$toString, 0, 'ToPropertyKey not called before target validation in Reflect.deleteProperty');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.get-own-property-descriptor.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import getOwnPropertyDescriptor from 'core-js-pure/es/reflect/get-own-property-descriptor';
QUnit.test('Reflect.getOwnPropertyDescriptor', assert => {
assert.isFunction(getOwnPropertyDescriptor);
assert.arity(getOwnPropertyDescriptor, 2);
if ('name' in getOwnPropertyDescriptor) {
assert.name(getOwnPropertyDescriptor, 'getOwnPropertyDescriptor');
}
const object = { baz: 789 };
const descriptor = getOwnPropertyDescriptor(object, 'baz');
assert.same(descriptor.value, 789);
assert.throws(() => getOwnPropertyDescriptor(42, 'constructor'), TypeError, 'throws on primitive');
});
QUnit.test('Reflect.getOwnPropertyDescriptor.sham flag', assert => {
assert.same(getOwnPropertyDescriptor.sham, DESCRIPTORS ? undefined : true);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.get-prototype-of.js
|
JavaScript
|
import { CORRECT_PROTOTYPE_GETTER } from '../helpers/constants.js';
import getPrototypeOf from 'core-js-pure/es/reflect/get-prototype-of';
QUnit.test('Reflect.getPrototypeOf', assert => {
assert.isFunction(getPrototypeOf);
assert.arity(getPrototypeOf, 1);
if ('name' in getPrototypeOf) {
assert.name(getPrototypeOf, 'getPrototypeOf');
}
assert.same(getPrototypeOf([]), Array.prototype);
assert.throws(() => getPrototypeOf(42), TypeError, 'throws on primitive');
});
QUnit.test('Reflect.getPrototypeOf.sham flag', assert => {
assert.same(getPrototypeOf.sham, CORRECT_PROTOTYPE_GETTER ? undefined : true);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.get.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import { createConversionChecker } from '../helpers/helpers.js';
import create from 'core-js-pure/es/object/create';
import defineProperty from 'core-js-pure/es/object/define-property';
import get from 'core-js-pure/es/reflect/get';
QUnit.test('Reflect.get', assert => {
assert.isFunction(get);
if ('name' in get) {
assert.name(get, 'get');
}
assert.same(get({ qux: 987 }, 'qux'), 987);
if (DESCRIPTORS) {
const target = create(defineProperty({ z: 3 }, 'w', {
get() {
return this;
},
}), {
x: {
value: 1,
},
y: {
get() {
return this;
},
},
});
const receiver = {};
assert.same(get(target, 'x', receiver), 1, 'get x');
assert.same(get(target, 'y', receiver), receiver, 'get y');
assert.same(get(target, 'z', receiver), 3, 'get z');
assert.same(get(target, 'w', receiver), receiver, 'get w');
assert.same(get(target, 'u', receiver), undefined, 'get u');
// ToPropertyKey should be called exactly once even with prototype chain traversal
const keyObj = createConversionChecker(1, 'x');
get(create({ x: 42 }), keyObj, {});
assert.same(keyObj.$valueOf, 0, 'ToPropertyKey called once in Reflect.get, #1');
assert.same(keyObj.$toString, 1, 'ToPropertyKey called once in Reflect.get, #2');
}
assert.throws(() => get(42, 'constructor'), TypeError, 'throws on primitive');
// argument order: target should be validated before ToPropertyKey
const orderChecker = createConversionChecker(1, 'qux');
assert.throws(() => get(42, orderChecker), TypeError, 'throws on primitive before ToPropertyKey');
assert.same(orderChecker.$toString, 0, 'ToPropertyKey not called before target validation in Reflect.get');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.has.js
|
JavaScript
|
import has from 'core-js-pure/es/reflect/has';
QUnit.test('Reflect.has', assert => {
assert.isFunction(has);
assert.arity(has, 2);
if ('name' in has) {
assert.name(has, 'has');
}
const object = { qux: 987 };
assert.true(has(object, 'qux'));
assert.false(has(object, 'qwe'));
assert.true(has(object, 'toString'));
assert.throws(() => has(42, 'constructor'), TypeError, 'throws on primitive');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.is-extensible.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import preventExtensions from 'core-js-pure/es/object/prevent-extensions';
import isExtensible from 'core-js-pure/es/reflect/is-extensible';
QUnit.test('Reflect.isExtensible', assert => {
assert.isFunction(isExtensible);
assert.arity(isExtensible, 1);
if ('name' in isExtensible) {
assert.name(isExtensible, 'isExtensible');
}
assert.true(isExtensible({}));
if (DESCRIPTORS) {
assert.false(isExtensible(preventExtensions({})));
}
assert.throws(() => isExtensible(42), TypeError, 'throws on primitive');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.own-keys.js
|
JavaScript
|
import { includes } from '../helpers/helpers.js';
import Symbol from 'core-js-pure/es/symbol';
import create from 'core-js-pure/es/object/create';
import defineProperty from 'core-js-pure/es/object/define-property';
import ownKeys from 'core-js-pure/es/reflect/own-keys';
QUnit.test('Reflect.ownKeys', assert => {
assert.isFunction(ownKeys);
assert.arity(ownKeys, 1);
if ('name' in ownKeys) {
assert.name(ownKeys, 'ownKeys');
}
const object = { a: 1 };
defineProperty(object, 'b', {
value: 2,
});
object[Symbol('c')] = 3;
let keys = ownKeys(object);
assert.same(keys.length, 3, 'ownKeys return all own keys');
assert.true(includes(keys, 'a'), 'ownKeys return all own keys: simple');
assert.true(includes(keys, 'b'), 'ownKeys return all own keys: hidden');
assert.same(object[keys[2]], 3, 'ownKeys return all own keys: symbol');
keys = ownKeys(create(object));
assert.same(keys.length, 0, 'ownKeys return only own keys');
assert.throws(() => ownKeys(42), TypeError, 'throws on primitive');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.prevent-extensions.js
|
JavaScript
|
import { DESCRIPTORS, FREEZING } from '../helpers/constants.js';
import preventExtensions from 'core-js-pure/es/reflect/prevent-extensions';
import isExtensible from 'core-js-pure/es/object/is-extensible';
QUnit.test('Reflect.preventExtensions', assert => {
assert.isFunction(preventExtensions);
assert.arity(preventExtensions, 1);
if ('name' in preventExtensions) {
assert.name(preventExtensions, 'preventExtensions');
}
const object = {};
assert.true(preventExtensions(object));
if (DESCRIPTORS) {
assert.false(isExtensible(object));
}
assert.throws(() => preventExtensions(42), TypeError, 'throws on primitive');
});
QUnit.test('Reflect.preventExtensions.sham flag', assert => {
assert.same(preventExtensions.sham, FREEZING ? undefined : true);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.set-prototype-of.js
|
JavaScript
|
import { PROTO } from '../helpers/constants.js';
import setPrototypeOf from 'core-js-pure/es/reflect/set-prototype-of';
if (PROTO) QUnit.test('Reflect.setPrototypeOf', assert => {
assert.isFunction(setPrototypeOf);
if ('name' in setPrototypeOf) {
assert.name(setPrototypeOf, 'setPrototypeOf');
}
let object = {};
assert.true(setPrototypeOf(object, Array.prototype));
assert.true(object instanceof Array);
assert.throws(() => setPrototypeOf({}, 42), TypeError);
assert.throws(() => setPrototypeOf(42, {}), TypeError, 'throws on primitive');
object = {};
assert.false(setPrototypeOf(object, object), 'false on recursive __proto__');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.reflect.set.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import { createConversionChecker } from '../helpers/helpers.js';
import create from 'core-js-pure/es/object/create';
import defineProperty from 'core-js-pure/es/object/define-property';
import getOwnPropertyDescriptor from 'core-js-pure/es/object/get-own-property-descriptor';
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
import set from 'core-js-pure/es/reflect/set';
QUnit.test('Reflect.set', assert => {
assert.isFunction(set);
if ('name' in set) {
assert.name(set, 'set');
}
const object = {};
assert.true(set(object, 'quux', 654));
assert.same(object.quux, 654);
let target = {};
const receiver = {};
set(target, 'foo', 1, receiver);
assert.same(target.foo, undefined, 'target.foo === undefined');
assert.same(receiver.foo, 1, 'receiver.foo === 1');
if (DESCRIPTORS) {
defineProperty(receiver, 'bar', {
value: 0,
writable: true,
enumerable: false,
configurable: true,
});
set(target, 'bar', 1, receiver);
assert.same(receiver.bar, 1, 'receiver.bar === 1');
assert.false(getOwnPropertyDescriptor(receiver, 'bar').enumerable, 'enumerability not overridden');
let out;
target = create(defineProperty({ z: 3 }, 'w', {
set() {
out = this;
},
}), {
x: {
value: 1,
writable: true,
configurable: true,
},
y: {
set() {
out = this;
},
},
c: {
value: 1,
writable: false,
configurable: false,
},
});
assert.true(set(target, 'x', 2, target), 'set x');
assert.same(target.x, 2, 'set x');
out = null;
assert.true(set(target, 'y', 2, target), 'set y');
assert.same(out, target, 'set y');
assert.true(set(target, 'z', 4, target));
assert.same(target.z, 4, 'set z');
out = null;
assert.true(set(target, 'w', 1, target), 'set w');
assert.same(out, target, 'set w');
assert.true(set(target, 'u', 0, target), 'set u');
assert.same(target.u, 0, 'set u');
assert.false(set(target, 'c', 2, target), 'set c');
assert.same(target.c, 1, 'set c');
// https://github.com/zloirock/core-js/issues/392
let o = defineProperty({}, 'test', {
writable: false,
configurable: true,
});
assert.false(set(getPrototypeOf(o), 'test', 1, o));
// https://github.com/zloirock/core-js/issues/393
o = defineProperty({}, 'test', {
get() { /* empty */ },
});
assert.notThrows(() => !set(getPrototypeOf(o), 'test', 1, o));
o = defineProperty({}, 'test', {
// eslint-disable-next-line no-unused-vars -- required for testing
set(v) { /* empty */ },
});
assert.notThrows(() => !set(getPrototypeOf(o), 'test', 1, o));
assert.notThrows(() => !set(getPrototypeOf(o), 'test', 1, o));
// accessor descriptor with get: undefined, set: undefined on receiver should return false
const accessorReceiver = {};
defineProperty(accessorReceiver, 'prop', { get: undefined, set: undefined, configurable: true });
const accessorTarget = defineProperty({}, 'prop', { value: 1, writable: true, configurable: true });
assert.false(set(accessorTarget, 'prop', 2, accessorReceiver), 'accessor descriptor on receiver with undefined get/set');
// ToPropertyKey should be called exactly once
const keyObj = createConversionChecker(1, 'x');
set(create({ x: 42 }), keyObj, 1);
assert.same(keyObj.$valueOf, 0, 'ToPropertyKey called once in Reflect.set, #1');
assert.same(keyObj.$toString, 1, 'ToPropertyKey called once in Reflect.set, #2');
}
assert.throws(() => set(42, 'q', 42), TypeError, 'throws on primitive');
// Reflect.set should pass only { value: V } to [[DefineOwnProperty]] when updating existing data property
if (DESCRIPTORS) {
const obj = defineProperty({}, 'x', { value: 1, writable: true, enumerable: true, configurable: true });
assert.true(set(obj, 'x', 42), 'set existing writable property');
const desc = getOwnPropertyDescriptor(obj, 'x');
assert.same(desc.value, 42, 'value updated');
assert.true(desc.writable, 'writable preserved');
assert.true(desc.enumerable, 'enumerable preserved');
assert.true(desc.configurable, 'configurable preserved');
}
// argument order: target should be validated before ToPropertyKey
const orderChecker = createConversionChecker(1, 'qux');
assert.throws(() => set(42, orderChecker, 1), TypeError, 'throws on primitive before ToPropertyKey');
assert.same(orderChecker.$toString, 0, 'ToPropertyKey not called before target validation in Reflect.set');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.regexp.escape.js
|
JavaScript
|
/* eslint-disable @stylistic/max-len -- ok*/
import escape from 'core-js-pure/es/regexp/escape';
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'), '\\x61bcdefg_123456', 'abcdefg_123456');
assert.same(escape('Привет'), 'Привет', 'Привет');
assert.same(
escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`'),
'\\(\\)\\{\\}\\[\\]\\|\\x2c\\.\\?\\*\\+\\x2d\\^\\$\\x3d\\x3c\\x3e\\\\\\/\\x23\\x26\\x21\\x25\\x3a\\x3b\\x40\\x7e\\x27\\x22\\x60',
'(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`',
);
assert.same(
escape('\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF'),
'\\t\\n\\v\\f\\r\\x20\\xa0\\u1680\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000\\u2028\\u2029\\ufeff',
'whitespaces and control',
);
assert.same(escape('💩'), '💩', '💩');
assert.same(escape('\uD83D'), '\\ud83d', '\\ud83d');
assert.same(escape('\uDCA9'), '\\udca9', '\\udca9');
assert.same(escape('\uDCA9\uD83D'), '\\udca9\\ud83d', '\\udca9\\ud83d');
assert.throws(() => escape(42), TypeError, 'throws on non-string #1');
assert.throws(() => escape({}), TypeError, 'throws on non-string #2');
// Test262
// Copyright 2024 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the https://github.com/tc39/test262/blob/main/LICENSE file.
assert.same(escape('\u2028'), '\\u2028', 'line terminator \\u2028 is escaped correctly to \\\\u2028');
assert.same(escape('\u2029'), '\\u2029', 'line terminator \\u2029 is escaped correctly to \\\\u2029');
assert.same(escape('\u2028\u2029'), '\\u2028\\u2029', 'line terminators are escaped correctly');
assert.same(escape('\u2028a\u2029a'), '\\u2028a\\u2029a', 'mixed line terminators are escaped correctly');
assert.same(escape('.a/b'), '\\.a\\/b', 'mixed string with solidus character is escaped correctly');
assert.same(escape('/./'), '\\/\\.\\/', 'solidus character is escaped correctly - regexp similar');
assert.same(escape('./a\\/*b+c?d^e$f|g{2}h[i]j\\k'), '\\.\\/a\\\\\\/\\*b\\+c\\?d\\^e\\$f\\|g\\{2\\}h\\[i\\]j\\\\k', 'complex string with multiple special characters is escaped correctly');
assert.same(escape('/'), '\\/', 'solidus character is escaped correctly');
assert.same(escape('//'), '\\/\\/', 'solidus character is escaped correctly - multiple occurrences 1');
assert.same(escape('///'), '\\/\\/\\/', 'solidus character is escaped correctly - multiple occurrences 2');
assert.same(escape('////'), '\\/\\/\\/\\/', 'solidus character is escaped correctly - multiple occurrences 3');
assert.same(escape('.'), '\\.', 'dot character is escaped correctly');
assert.same(escape('*'), '\\*', 'asterisk character is escaped correctly');
assert.same(escape('+'), '\\+', 'plus character is escaped correctly');
assert.same(escape('?'), '\\?', 'question mark character is escaped correctly');
assert.same(escape('^'), '\\^', 'caret character is escaped correctly');
assert.same(escape('$'), '\\$', 'dollar character is escaped correctly');
assert.same(escape('|'), '\\|', 'pipe character is escaped correctly');
assert.same(escape('('), '\\(', 'open parenthesis character is escaped correctly');
assert.same(escape(')'), '\\)', 'close parenthesis character is escaped correctly');
assert.same(escape('['), '\\[', 'open bracket character is escaped correctly');
assert.same(escape(']'), '\\]', 'close bracket character is escaped correctly');
assert.same(escape('{'), '\\{', 'open brace character is escaped correctly');
assert.same(escape('}'), '\\}', 'close brace character is escaped correctly');
assert.same(escape('\\'), '\\\\', 'backslash character is escaped correctly');
const codePoints = String.fromCharCode(0x100, 0x200, 0x300);
assert.same(escape(codePoints), codePoints, 'characters are correctly not escaped');
assert.same(escape('你好'), '你好', 'Chinese characters are correctly not escaped');
assert.same(escape('こんにちは'), 'こんにちは', 'Japanese characters are correctly not escaped');
assert.same(escape('안녕하세요'), '안녕하세요', 'Korean characters are correctly not escaped');
assert.same(escape('Привет'), 'Привет', 'Cyrillic characters are correctly not escaped');
assert.same(escape('مرحبا'), 'مرحبا', 'Arabic characters are correctly not escaped');
assert.same(escape('हेलो'), 'हेलो', 'Devanagari characters are correctly not escaped');
assert.same(escape('Γειά σου'), 'Γειά\\x20σου', 'Greek characters are correctly not escaped');
assert.same(escape('שלום'), 'שלום', 'Hebrew characters are correctly not escaped');
assert.same(escape('สวัสดี'), 'สวัสดี', 'Thai characters are correctly not escaped');
assert.same(escape('नमस्ते'), 'नमस्ते', 'Hindi characters are correctly not escaped');
assert.same(escape('ሰላም'), 'ሰላም', 'Amharic characters are correctly not escaped');
assert.same(escape('हैलो'), 'हैलो', 'Hindi characters with diacritics are correctly not escaped');
assert.same(escape('안녕!'), '안녕\\x21', 'Korean character with special character is correctly escaped');
assert.same(escape('.hello\uD7FFworld'), '\\.hello\uD7FFworld', 'Mixed ASCII and Unicode characters are correctly escaped');
assert.same(escape('\uFEFF'), '\\ufeff', 'whitespace \\uFEFF is escaped correctly to \\uFEFF');
assert.same(escape('\u0020'), '\\x20', 'whitespace \\u0020 is escaped correctly to \\x20');
assert.same(escape('\u00A0'), '\\xa0', 'whitespace \\u00A0 is escaped correctly to \\xA0');
assert.same(escape('\u202F'), '\\u202f', 'whitespace \\u202F is escaped correctly to \\u202F');
assert.same(escape('\u0009'), '\\t', 'whitespace \\u0009 is escaped correctly to \\t');
assert.same(escape('\u000B'), '\\v', 'whitespace \\u000B is escaped correctly to \\v');
assert.same(escape('\u000C'), '\\f', 'whitespace \\u000C is escaped correctly to \\f');
assert.same(escape('\uFEFF\u0020\u00A0\u202F\u0009\u000B\u000C'), '\\ufeff\\x20\\xa0\\u202f\\t\\v\\f', 'whitespaces are escaped correctly');
// Escaping initial digits
assert.same(escape('1111'), '\\x31111', 'Initial decimal digit 1 is escaped');
assert.same(escape('2222'), '\\x32222', 'Initial decimal digit 2 is escaped');
assert.same(escape('3333'), '\\x33333', 'Initial decimal digit 3 is escaped');
assert.same(escape('4444'), '\\x34444', 'Initial decimal digit 4 is escaped');
assert.same(escape('5555'), '\\x35555', 'Initial decimal digit 5 is escaped');
assert.same(escape('6666'), '\\x36666', 'Initial decimal digit 6 is escaped');
assert.same(escape('7777'), '\\x37777', 'Initial decimal digit 7 is escaped');
assert.same(escape('8888'), '\\x38888', 'Initial decimal digit 8 is escaped');
assert.same(escape('9999'), '\\x39999', 'Initial decimal digit 9 is escaped');
assert.same(escape('0000'), '\\x30000', 'Initial decimal digit 0 is escaped');
// Escaping initial ASCII letters
assert.same(escape('aaa'), '\\x61aa', 'Initial ASCII letter a is escaped');
assert.same(escape('bbb'), '\\x62bb', 'Initial ASCII letter b is escaped');
assert.same(escape('ccc'), '\\x63cc', 'Initial ASCII letter c is escaped');
assert.same(escape('ddd'), '\\x64dd', 'Initial ASCII letter d is escaped');
assert.same(escape('eee'), '\\x65ee', 'Initial ASCII letter e is escaped');
assert.same(escape('fff'), '\\x66ff', 'Initial ASCII letter f is escaped');
assert.same(escape('ggg'), '\\x67gg', 'Initial ASCII letter g is escaped');
assert.same(escape('hhh'), '\\x68hh', 'Initial ASCII letter h is escaped');
assert.same(escape('iii'), '\\x69ii', 'Initial ASCII letter i is escaped');
assert.same(escape('jjj'), '\\x6ajj', 'Initial ASCII letter j is escaped');
assert.same(escape('kkk'), '\\x6bkk', 'Initial ASCII letter k is escaped');
assert.same(escape('lll'), '\\x6cll', 'Initial ASCII letter l is escaped');
assert.same(escape('mmm'), '\\x6dmm', 'Initial ASCII letter m is escaped');
assert.same(escape('nnn'), '\\x6enn', 'Initial ASCII letter n is escaped');
assert.same(escape('ooo'), '\\x6foo', 'Initial ASCII letter o is escaped');
assert.same(escape('ppp'), '\\x70pp', 'Initial ASCII letter p is escaped');
assert.same(escape('qqq'), '\\x71qq', 'Initial ASCII letter q is escaped');
assert.same(escape('rrr'), '\\x72rr', 'Initial ASCII letter r is escaped');
assert.same(escape('sss'), '\\x73ss', 'Initial ASCII letter s is escaped');
assert.same(escape('ttt'), '\\x74tt', 'Initial ASCII letter t is escaped');
assert.same(escape('uuu'), '\\x75uu', 'Initial ASCII letter u is escaped');
assert.same(escape('vvv'), '\\x76vv', 'Initial ASCII letter v is escaped');
assert.same(escape('www'), '\\x77ww', 'Initial ASCII letter w is escaped');
assert.same(escape('xxx'), '\\x78xx', 'Initial ASCII letter x is escaped');
assert.same(escape('yyy'), '\\x79yy', 'Initial ASCII letter y is escaped');
assert.same(escape('zzz'), '\\x7azz', 'Initial ASCII letter z is escaped');
assert.same(escape('AAA'), '\\x41AA', 'Initial ASCII letter A is escaped');
assert.same(escape('BBB'), '\\x42BB', 'Initial ASCII letter B is escaped');
assert.same(escape('CCC'), '\\x43CC', 'Initial ASCII letter C is escaped');
assert.same(escape('DDD'), '\\x44DD', 'Initial ASCII letter D is escaped');
assert.same(escape('EEE'), '\\x45EE', 'Initial ASCII letter E is escaped');
assert.same(escape('FFF'), '\\x46FF', 'Initial ASCII letter F is escaped');
assert.same(escape('GGG'), '\\x47GG', 'Initial ASCII letter G is escaped');
assert.same(escape('HHH'), '\\x48HH', 'Initial ASCII letter H is escaped');
assert.same(escape('III'), '\\x49II', 'Initial ASCII letter I is escaped');
assert.same(escape('JJJ'), '\\x4aJJ', 'Initial ASCII letter J is escaped');
assert.same(escape('KKK'), '\\x4bKK', 'Initial ASCII letter K is escaped');
assert.same(escape('LLL'), '\\x4cLL', 'Initial ASCII letter L is escaped');
assert.same(escape('MMM'), '\\x4dMM', 'Initial ASCII letter M is escaped');
assert.same(escape('NNN'), '\\x4eNN', 'Initial ASCII letter N is escaped');
assert.same(escape('OOO'), '\\x4fOO', 'Initial ASCII letter O is escaped');
assert.same(escape('PPP'), '\\x50PP', 'Initial ASCII letter P is escaped');
assert.same(escape('QQQ'), '\\x51QQ', 'Initial ASCII letter Q is escaped');
assert.same(escape('RRR'), '\\x52RR', 'Initial ASCII letter R is escaped');
assert.same(escape('SSS'), '\\x53SS', 'Initial ASCII letter S is escaped');
assert.same(escape('TTT'), '\\x54TT', 'Initial ASCII letter T is escaped');
assert.same(escape('UUU'), '\\x55UU', 'Initial ASCII letter U is escaped');
assert.same(escape('VVV'), '\\x56VV', 'Initial ASCII letter V is escaped');
assert.same(escape('WWW'), '\\x57WW', 'Initial ASCII letter W is escaped');
assert.same(escape('XXX'), '\\x58XX', 'Initial ASCII letter X is escaped');
assert.same(escape('YYY'), '\\x59YY', 'Initial ASCII letter Y is escaped');
assert.same(escape('ZZZ'), '\\x5aZZ', 'Initial ASCII letter Z is escaped');
// Mixed case with special characters
assert.same(escape('1+1'), '\\x31\\+1', 'Initial decimal digit 1 with special character is escaped');
assert.same(escape('2+2'), '\\x32\\+2', 'Initial decimal digit 2 with special character is escaped');
assert.same(escape('3+3'), '\\x33\\+3', 'Initial decimal digit 3 with special character is escaped');
assert.same(escape('4+4'), '\\x34\\+4', 'Initial decimal digit 4 with special character is escaped');
assert.same(escape('5+5'), '\\x35\\+5', 'Initial decimal digit 5 with special character is escaped');
assert.same(escape('6+6'), '\\x36\\+6', 'Initial decimal digit 6 with special character is escaped');
assert.same(escape('7+7'), '\\x37\\+7', 'Initial decimal digit 7 with special character is escaped');
assert.same(escape('8+8'), '\\x38\\+8', 'Initial decimal digit 8 with special character is escaped');
assert.same(escape('9+9'), '\\x39\\+9', 'Initial decimal digit 9 with special character is escaped');
assert.same(escape('0+0'), '\\x30\\+0', 'Initial decimal digit 0 with special character is escaped');
assert.same(escape('a*a'), '\\x61\\*a', 'Initial ASCII letter a with special character is escaped');
assert.same(escape('b*b'), '\\x62\\*b', 'Initial ASCII letter b with special character is escaped');
assert.same(escape('c*c'), '\\x63\\*c', 'Initial ASCII letter c with special character is escaped');
assert.same(escape('d*d'), '\\x64\\*d', 'Initial ASCII letter d with special character is escaped');
assert.same(escape('e*e'), '\\x65\\*e', 'Initial ASCII letter e with special character is escaped');
assert.same(escape('f*f'), '\\x66\\*f', 'Initial ASCII letter f with special character is escaped');
assert.same(escape('g*g'), '\\x67\\*g', 'Initial ASCII letter g with special character is escaped');
assert.same(escape('h*h'), '\\x68\\*h', 'Initial ASCII letter h with special character is escaped');
assert.same(escape('i*i'), '\\x69\\*i', 'Initial ASCII letter i with special character is escaped');
assert.same(escape('j*j'), '\\x6a\\*j', 'Initial ASCII letter j with special character is escaped');
assert.same(escape('k*k'), '\\x6b\\*k', 'Initial ASCII letter k with special character is escaped');
assert.same(escape('l*l'), '\\x6c\\*l', 'Initial ASCII letter l with special character is escaped');
assert.same(escape('m*m'), '\\x6d\\*m', 'Initial ASCII letter m with special character is escaped');
assert.same(escape('n*n'), '\\x6e\\*n', 'Initial ASCII letter n with special character is escaped');
assert.same(escape('o*o'), '\\x6f\\*o', 'Initial ASCII letter o with special character is escaped');
assert.same(escape('p*p'), '\\x70\\*p', 'Initial ASCII letter p with special character is escaped');
assert.same(escape('q*q'), '\\x71\\*q', 'Initial ASCII letter q with special character is escaped');
assert.same(escape('r*r'), '\\x72\\*r', 'Initial ASCII letter r with special character is escaped');
assert.same(escape('s*s'), '\\x73\\*s', 'Initial ASCII letter s with special character is escaped');
assert.same(escape('t*t'), '\\x74\\*t', 'Initial ASCII letter t with special character is escaped');
assert.same(escape('u*u'), '\\x75\\*u', 'Initial ASCII letter u with special character is escaped');
assert.same(escape('v*v'), '\\x76\\*v', 'Initial ASCII letter v with special character is escaped');
assert.same(escape('w*w'), '\\x77\\*w', 'Initial ASCII letter w with special character is escaped');
assert.same(escape('x*x'), '\\x78\\*x', 'Initial ASCII letter x with special character is escaped');
assert.same(escape('y*y'), '\\x79\\*y', 'Initial ASCII letter y with special character is escaped');
assert.same(escape('z*z'), '\\x7a\\*z', 'Initial ASCII letter z with special character is escaped');
assert.same(escape('A*A'), '\\x41\\*A', 'Initial ASCII letter A with special character is escaped');
assert.same(escape('B*B'), '\\x42\\*B', 'Initial ASCII letter B with special character is escaped');
assert.same(escape('C*C'), '\\x43\\*C', 'Initial ASCII letter C with special character is escaped');
assert.same(escape('D*D'), '\\x44\\*D', 'Initial ASCII letter D with special character is escaped');
assert.same(escape('E*E'), '\\x45\\*E', 'Initial ASCII letter E with special character is escaped');
assert.same(escape('F*F'), '\\x46\\*F', 'Initial ASCII letter F with special character is escaped');
assert.same(escape('G*G'), '\\x47\\*G', 'Initial ASCII letter G with special character is escaped');
assert.same(escape('H*H'), '\\x48\\*H', 'Initial ASCII letter H with special character is escaped');
assert.same(escape('I*I'), '\\x49\\*I', 'Initial ASCII letter I with special character is escaped');
assert.same(escape('J*J'), '\\x4a\\*J', 'Initial ASCII letter J with special character is escaped');
assert.same(escape('K*K'), '\\x4b\\*K', 'Initial ASCII letter K with special character is escaped');
assert.same(escape('L*L'), '\\x4c\\*L', 'Initial ASCII letter L with special character is escaped');
assert.same(escape('M*M'), '\\x4d\\*M', 'Initial ASCII letter M with special character is escaped');
assert.same(escape('N*N'), '\\x4e\\*N', 'Initial ASCII letter N with special character is escaped');
assert.same(escape('O*O'), '\\x4f\\*O', 'Initial ASCII letter O with special character is escaped');
assert.same(escape('P*P'), '\\x50\\*P', 'Initial ASCII letter P with special character is escaped');
assert.same(escape('Q*Q'), '\\x51\\*Q', 'Initial ASCII letter Q with special character is escaped');
assert.same(escape('R*R'), '\\x52\\*R', 'Initial ASCII letter R with special character is escaped');
assert.same(escape('S*S'), '\\x53\\*S', 'Initial ASCII letter S with special character is escaped');
assert.same(escape('T*T'), '\\x54\\*T', 'Initial ASCII letter T with special character is escaped');
assert.same(escape('U*U'), '\\x55\\*U', 'Initial ASCII letter U with special character is escaped');
assert.same(escape('V*V'), '\\x56\\*V', 'Initial ASCII letter V with special character is escaped');
assert.same(escape('W*W'), '\\x57\\*W', 'Initial ASCII letter W with special character is escaped');
assert.same(escape('X*X'), '\\x58\\*X', 'Initial ASCII letter X with special character is escaped');
assert.same(escape('Y*Y'), '\\x59\\*Y', 'Initial ASCII letter Y with special character is escaped');
assert.same(escape('Z*Z'), '\\x5a\\*Z', 'Initial ASCII letter Z with special character is escaped');
assert.same(escape('_'), '_', 'Single underscore character is not escaped');
assert.same(escape('__'), '__', 'Thunderscore character is not escaped');
assert.same(escape('hello_world'), '\\x68ello_world', 'String starting with ASCII letter and containing underscore is not escaped');
assert.same(escape('1_hello_world'), '\\x31_hello_world', 'String starting with digit and containing underscore is correctly escaped');
assert.same(escape('a_b_c'), '\\x61_b_c', 'String starting with ASCII letter and containing multiple underscores is correctly escaped');
assert.same(escape('3_b_4'), '\\x33_b_4', 'String starting with digit and containing multiple underscores is correctly escaped');
assert.same(escape('_hello'), '_hello', 'String starting with underscore and containing other characters is not escaped');
assert.same(escape('_1hello'), '_1hello', 'String starting with underscore and digit is not escaped');
assert.same(escape('_a_1_2'), '_a_1_2', 'String starting with underscore and mixed characters is not escaped');
// Specific surrogate points
assert.same(escape('\uD800'), '\\ud800', 'High surrogate \\uD800 is correctly escaped');
assert.same(escape('\uDBFF'), '\\udbff', 'High surrogate \\uDBFF is correctly escaped');
assert.same(escape('\uDC00'), '\\udc00', 'Low surrogate \\uDC00 is correctly escaped');
assert.same(escape('\uDFFF'), '\\udfff', 'Low surrogate \\uDFFF is correctly escaped');
// Leading Surrogates
const highSurrogatesGroup1 = '\uD800\uD801\uD802\uD803\uD804\uD805\uD806\uD807\uD808\uD809\uD80A\uD80B\uD80C\uD80D\uD80E\uD80F';
const highSurrogatesGroup2 = '\uD810\uD811\uD812\uD813\uD814\uD815\uD816\uD817\uD818\uD819\uD81A\uD81B\uD81C\uD81D\uD81E\uD81F';
const highSurrogatesGroup3 = '\uD820\uD821\uD822\uD823\uD824\uD825\uD826\uD827\uD828\uD829\uD82A\uD82B\uD82C\uD82D\uD82E\uD82F';
const highSurrogatesGroup4 = '\uD830\uD831\uD832\uD833\uD834\uD835\uD836\uD837\uD838\uD839\uD83A\uD83B\uD83C\uD83D\uD83E\uD83F';
const highSurrogatesGroup5 = '\uD840\uD841\uD842\uD843\uD844\uD845\uD846\uD847\uD848\uD849\uD84A\uD84B\uD84C\uD84D\uD84E\uD84F';
const highSurrogatesGroup6 = '\uD850\uD851\uD852\uD853\uD854\uD855\uD856\uD857\uD858\uD859\uD85A\uD85B\uD85C\uD85D\uD85E\uD85F';
const highSurrogatesGroup7 = '\uD860\uD861\uD862\uD863\uD864\uD865\uD866\uD867\uD868\uD869\uD86A\uD86B\uD86C\uD86D\uD86E\uD86F';
const highSurrogatesGroup8 = '\uD870\uD871\uD872\uD873\uD874\uD875\uD876\uD877\uD878\uD879\uD87A\uD87B\uD87C\uD87D\uD87E\uD87F';
const highSurrogatesGroup9 = '\uD880\uD881\uD882\uD883\uD884\uD885\uD886\uD887\uD888\uD889\uD88A\uD88B\uD88C\uD88D\uD88E\uD88F';
const highSurrogatesGroup10 = '\uD890\uD891\uD892\uD893\uD894\uD895\uD896\uD897\uD898\uD899\uD89A\uD89B\uD89C\uD89D\uD89E\uD89F';
const highSurrogatesGroup11 = '\uD8A0\uD8A1\uD8A2\uD8A3\uD8A4\uD8A5\uD8A6\uD8A7\uD8A8\uD8A9\uD8AA\uD8AB\uD8AC\uD8AD\uD8AE\uD8AF';
const highSurrogatesGroup12 = '\uD8B0\uD8B1\uD8B2\uD8B3\uD8B4\uD8B5\uD8B6\uD8B7\uD8B8\uD8B9\uD8BA\uD8BB\uD8BC\uD8BD\uD8BE\uD8BF';
const highSurrogatesGroup13 = '\uD8C0\uD8C1\uD8C2\uD8C3\uD8C4\uD8C5\uD8C6\uD8C7\uD8C8\uD8C9\uD8CA\uD8CB\uD8CC\uD8CD\uD8CE\uD8CF';
const highSurrogatesGroup14 = '\uD8D0\uD8D1\uD8D2\uD8D3\uD8D4\uD8D5\uD8D6\uD8D7\uD8D8\uD8D9\uD8DA\uD8DB\uD8DC\uD8DD\uD8DE\uD8DF';
const highSurrogatesGroup15 = '\uD8E0\uD8E1\uD8E2\uD8E3\uD8E4\uD8E5\uD8E6\uD8E7\uD8E8\uD8E9\uD8EA\uD8EB\uD8EC\uD8ED\uD8EE\uD8EF';
const highSurrogatesGroup16 = '\uD8F0\uD8F1\uD8F2\uD8F3\uD8F4\uD8F5\uD8F6\uD8F7\uD8F8\uD8F9\uD8FA\uD8FB\uD8FC\uD8FD\uD8FE\uD8FF';
assert.same(escape(highSurrogatesGroup1), '\\ud800\\ud801\\ud802\\ud803\\ud804\\ud805\\ud806\\ud807\\ud808\\ud809\\ud80a\\ud80b\\ud80c\\ud80d\\ud80e\\ud80f', 'High surrogates group 1 are correctly escaped');
assert.same(escape(highSurrogatesGroup2), '\\ud810\\ud811\\ud812\\ud813\\ud814\\ud815\\ud816\\ud817\\ud818\\ud819\\ud81a\\ud81b\\ud81c\\ud81d\\ud81e\\ud81f', 'High surrogates group 2 are correctly escaped');
assert.same(escape(highSurrogatesGroup3), '\\ud820\\ud821\\ud822\\ud823\\ud824\\ud825\\ud826\\ud827\\ud828\\ud829\\ud82a\\ud82b\\ud82c\\ud82d\\ud82e\\ud82f', 'High surrogates group 3 are correctly escaped');
assert.same(escape(highSurrogatesGroup4), '\\ud830\\ud831\\ud832\\ud833\\ud834\\ud835\\ud836\\ud837\\ud838\\ud839\\ud83a\\ud83b\\ud83c\\ud83d\\ud83e\\ud83f', 'High surrogates group 4 are correctly escaped');
assert.same(escape(highSurrogatesGroup5), '\\ud840\\ud841\\ud842\\ud843\\ud844\\ud845\\ud846\\ud847\\ud848\\ud849\\ud84a\\ud84b\\ud84c\\ud84d\\ud84e\\ud84f', 'High surrogates group 5 are correctly escaped');
assert.same(escape(highSurrogatesGroup6), '\\ud850\\ud851\\ud852\\ud853\\ud854\\ud855\\ud856\\ud857\\ud858\\ud859\\ud85a\\ud85b\\ud85c\\ud85d\\ud85e\\ud85f', 'High surrogates group 6 are correctly escaped');
assert.same(escape(highSurrogatesGroup7), '\\ud860\\ud861\\ud862\\ud863\\ud864\\ud865\\ud866\\ud867\\ud868\\ud869\\ud86a\\ud86b\\ud86c\\ud86d\\ud86e\\ud86f', 'High surrogates group 7 are correctly escaped');
assert.same(escape(highSurrogatesGroup8), '\\ud870\\ud871\\ud872\\ud873\\ud874\\ud875\\ud876\\ud877\\ud878\\ud879\\ud87a\\ud87b\\ud87c\\ud87d\\ud87e\\ud87f', 'High surrogates group 8 are correctly escaped');
assert.same(escape(highSurrogatesGroup9), '\\ud880\\ud881\\ud882\\ud883\\ud884\\ud885\\ud886\\ud887\\ud888\\ud889\\ud88a\\ud88b\\ud88c\\ud88d\\ud88e\\ud88f', 'High surrogates group 9 are correctly escaped');
assert.same(escape(highSurrogatesGroup10), '\\ud890\\ud891\\ud892\\ud893\\ud894\\ud895\\ud896\\ud897\\ud898\\ud899\\ud89a\\ud89b\\ud89c\\ud89d\\ud89e\\ud89f', 'High surrogates group 10 are correctly escaped');
assert.same(escape(highSurrogatesGroup11), '\\ud8a0\\ud8a1\\ud8a2\\ud8a3\\ud8a4\\ud8a5\\ud8a6\\ud8a7\\ud8a8\\ud8a9\\ud8aa\\ud8ab\\ud8ac\\ud8ad\\ud8ae\\ud8af', 'High surrogates group 11 are correctly escaped');
assert.same(escape(highSurrogatesGroup12), '\\ud8b0\\ud8b1\\ud8b2\\ud8b3\\ud8b4\\ud8b5\\ud8b6\\ud8b7\\ud8b8\\ud8b9\\ud8ba\\ud8bb\\ud8bc\\ud8bd\\ud8be\\ud8bf', 'High surrogates group 12 are correctly escaped');
assert.same(escape(highSurrogatesGroup13), '\\ud8c0\\ud8c1\\ud8c2\\ud8c3\\ud8c4\\ud8c5\\ud8c6\\ud8c7\\ud8c8\\ud8c9\\ud8ca\\ud8cb\\ud8cc\\ud8cd\\ud8ce\\ud8cf', 'High surrogates group 13 are correctly escaped');
assert.same(escape(highSurrogatesGroup14), '\\ud8d0\\ud8d1\\ud8d2\\ud8d3\\ud8d4\\ud8d5\\ud8d6\\ud8d7\\ud8d8\\ud8d9\\ud8da\\ud8db\\ud8dc\\ud8dd\\ud8de\\ud8df', 'High surrogates group 14 are correctly escaped');
assert.same(escape(highSurrogatesGroup15), '\\ud8e0\\ud8e1\\ud8e2\\ud8e3\\ud8e4\\ud8e5\\ud8e6\\ud8e7\\ud8e8\\ud8e9\\ud8ea\\ud8eb\\ud8ec\\ud8ed\\ud8ee\\ud8ef', 'High surrogates group 15 are correctly escaped');
assert.same(escape(highSurrogatesGroup16), '\\ud8f0\\ud8f1\\ud8f2\\ud8f3\\ud8f4\\ud8f5\\ud8f6\\ud8f7\\ud8f8\\ud8f9\\ud8fa\\ud8fb\\ud8fc\\ud8fd\\ud8fe\\ud8ff', 'High surrogates group 16 are correctly escaped');
// Trailing Surrogates
const lowSurrogatesGroup1 = '\uDC00\uDC01\uDC02\uDC03\uDC04\uDC05\uDC06\uDC07\uDC08\uDC09\uDC0A\uDC0B\uDC0C\uDC0D\uDC0E\uDC0F';
const lowSurrogatesGroup2 = '\uDC10\uDC11\uDC12\uDC13\uDC14\uDC15\uDC16\uDC17\uDC18\uDC19\uDC1A\uDC1B\uDC1C\uDC1D\uDC1E\uDC1F';
const lowSurrogatesGroup3 = '\uDC20\uDC21\uDC22\uDC23\uDC24\uDC25\uDC26\uDC27\uDC28\uDC29\uDC2A\uDC2B\uDC2C\uDC2D\uDC2E\uDC2F';
const lowSurrogatesGroup4 = '\uDC30\uDC31\uDC32\uDC33\uDC34\uDC35\uDC36\uDC37\uDC38\uDC39\uDC3A\uDC3B\uDC3C\uDC3D\uDC3E\uDC3F';
const lowSurrogatesGroup5 = '\uDC40\uDC41\uDC42\uDC43\uDC44\uDC45\uDC46\uDC47\uDC48\uDC49\uDC4A\uDC4B\uDC4C\uDC4D\uDC4E\uDC4F';
const lowSurrogatesGroup6 = '\uDC50\uDC51\uDC52\uDC53\uDC54\uDC55\uDC56\uDC57\uDC58\uDC59\uDC5A\uDC5B\uDC5C\uDC5D\uDC5E\uDC5F';
const lowSurrogatesGroup7 = '\uDC60\uDC61\uDC62\uDC63\uDC64\uDC65\uDC66\uDC67\uDC68\uDC69\uDC6A\uDC6B\uDC6C\uDC6D\uDC6E\uDC6F';
const lowSurrogatesGroup8 = '\uDC70\uDC71\uDC72\uDC73\uDC74\uDC75\uDC76\uDC77\uDC78\uDC79\uDC7A\uDC7B\uDC7C\uDC7D\uDC7E\uDC7F';
const lowSurrogatesGroup9 = '\uDC80\uDC81\uDC82\uDC83\uDC84\uDC85\uDC86\uDC87\uDC88\uDC89\uDC8A\uDC8B\uDC8C\uDC8D\uDC8E\uDC8F';
const lowSurrogatesGroup10 = '\uDC90\uDC91\uDC92\uDC93\uDC94\uDC95\uDC96\uDC97\uDC98\uDC99\uDC9A\uDC9B\uDC9C\uDC9D\uDC9E\uDC9F';
const lowSurrogatesGroup11 = '\uDCA0\uDCA1\uDCA2\uDCA3\uDCA4\uDCA5\uDCA6\uDCA7\uDCA8\uDCA9\uDCAA\uDCAB\uDCAC\uDCAD\uDCAE\uDCAF';
const lowSurrogatesGroup12 = '\uDCB0\uDCB1\uDCB2\uDCB3\uDCB4\uDCB5\uDCB6\uDCB7\uDCB8\uDCB9\uDCBA\uDCBB\uDCBC\uDCBD\uDCBE\uDCBF';
const lowSurrogatesGroup13 = '\uDCC0\uDCC1\uDCC2\uDCC3\uDCC4\uDCC5\uDCC6\uDCC7\uDCC8\uDCC9\uDCCA\uDCCB\uDCCC\uDCCD\uDCCE\uDCCF';
const lowSurrogatesGroup14 = '\uDCD0\uDCD1\uDCD2\uDCD3\uDCD4\uDCD5\uDCD6\uDCD7\uDCD8\uDCD9\uDCDA\uDCDB\uDCDC\uDCDD\uDCDE\uDCDF';
const lowSurrogatesGroup15 = '\uDCE0\uDCE1\uDCE2\uDCE3\uDCE4\uDCE5\uDCE6\uDCE7\uDCE8\uDCE9\uDCEA\uDCEB\uDCEC\uDCED\uDCEE\uDCEF';
const lowSurrogatesGroup16 = '\uDCF0\uDCF1\uDCF2\uDCF3\uDCF4\uDCF5\uDCF6\uDCF7\uDCF8\uDCF9\uDCFA\uDCFB\uDCFC\uDCFD\uDCFE\uDCFF';
assert.same(escape(lowSurrogatesGroup1), '\\udc00\\udc01\\udc02\\udc03\\udc04\\udc05\\udc06\\udc07\\udc08\\udc09\\udc0a\\udc0b\\udc0c\\udc0d\\udc0e\\udc0f', 'Low surrogates group 1 are correctly escaped');
assert.same(escape(lowSurrogatesGroup2), '\\udc10\\udc11\\udc12\\udc13\\udc14\\udc15\\udc16\\udc17\\udc18\\udc19\\udc1a\\udc1b\\udc1c\\udc1d\\udc1e\\udc1f', 'Low surrogates group 2 are correctly escaped');
assert.same(escape(lowSurrogatesGroup3), '\\udc20\\udc21\\udc22\\udc23\\udc24\\udc25\\udc26\\udc27\\udc28\\udc29\\udc2a\\udc2b\\udc2c\\udc2d\\udc2e\\udc2f', 'Low surrogates group 3 are correctly escaped');
assert.same(escape(lowSurrogatesGroup4), '\\udc30\\udc31\\udc32\\udc33\\udc34\\udc35\\udc36\\udc37\\udc38\\udc39\\udc3a\\udc3b\\udc3c\\udc3d\\udc3e\\udc3f', 'Low surrogates group 4 are correctly escaped');
assert.same(escape(lowSurrogatesGroup5), '\\udc40\\udc41\\udc42\\udc43\\udc44\\udc45\\udc46\\udc47\\udc48\\udc49\\udc4a\\udc4b\\udc4c\\udc4d\\udc4e\\udc4f', 'Low surrogates group 5 are correctly escaped');
assert.same(escape(lowSurrogatesGroup6), '\\udc50\\udc51\\udc52\\udc53\\udc54\\udc55\\udc56\\udc57\\udc58\\udc59\\udc5a\\udc5b\\udc5c\\udc5d\\udc5e\\udc5f', 'Low surrogates group 6 are correctly escaped');
assert.same(escape(lowSurrogatesGroup7), '\\udc60\\udc61\\udc62\\udc63\\udc64\\udc65\\udc66\\udc67\\udc68\\udc69\\udc6a\\udc6b\\udc6c\\udc6d\\udc6e\\udc6f', 'Low surrogates group 7 are correctly escaped');
assert.same(escape(lowSurrogatesGroup8), '\\udc70\\udc71\\udc72\\udc73\\udc74\\udc75\\udc76\\udc77\\udc78\\udc79\\udc7a\\udc7b\\udc7c\\udc7d\\udc7e\\udc7f', 'Low surrogates group 8 are correctly escaped');
assert.same(escape(lowSurrogatesGroup9), '\\udc80\\udc81\\udc82\\udc83\\udc84\\udc85\\udc86\\udc87\\udc88\\udc89\\udc8a\\udc8b\\udc8c\\udc8d\\udc8e\\udc8f', 'Low surrogates group 9 are correctly escaped');
assert.same(escape(lowSurrogatesGroup10), '\\udc90\\udc91\\udc92\\udc93\\udc94\\udc95\\udc96\\udc97\\udc98\\udc99\\udc9a\\udc9b\\udc9c\\udc9d\\udc9e\\udc9f', 'Low surrogates group 10 are correctly escaped');
assert.same(escape(lowSurrogatesGroup11), '\\udca0\\udca1\\udca2\\udca3\\udca4\\udca5\\udca6\\udca7\\udca8\\udca9\\udcaa\\udcab\\udcac\\udcad\\udcae\\udcaf', 'Low surrogates group 11 are correctly escaped');
assert.same(escape(lowSurrogatesGroup12), '\\udcb0\\udcb1\\udcb2\\udcb3\\udcb4\\udcb5\\udcb6\\udcb7\\udcb8\\udcb9\\udcba\\udcbb\\udcbc\\udcbd\\udcbe\\udcbf', 'Low surrogates group 12 are correctly escaped');
assert.same(escape(lowSurrogatesGroup13), '\\udcc0\\udcc1\\udcc2\\udcc3\\udcc4\\udcc5\\udcc6\\udcc7\\udcc8\\udcc9\\udcca\\udccb\\udccc\\udccd\\udcce\\udccf', 'Low surrogates group 13 are correctly escaped');
assert.same(escape(lowSurrogatesGroup14), '\\udcd0\\udcd1\\udcd2\\udcd3\\udcd4\\udcd5\\udcd6\\udcd7\\udcd8\\udcd9\\udcda\\udcdb\\udcdc\\udcdd\\udcde\\udcdf', 'Low surrogates group 14 are correctly escaped');
assert.same(escape(lowSurrogatesGroup15), '\\udce0\\udce1\\udce2\\udce3\\udce4\\udce5\\udce6\\udce7\\udce8\\udce9\\udcea\\udceb\\udcec\\udced\\udcee\\udcef', 'Low surrogates group 15 are correctly escaped');
assert.same(escape(lowSurrogatesGroup16), '\\udcf0\\udcf1\\udcf2\\udcf3\\udcf4\\udcf5\\udcf6\\udcf7\\udcf8\\udcf9\\udcfa\\udcfb\\udcfc\\udcfd\\udcfe\\udcff', 'Low surrogates group 16 are correctly escaped');
assert.same(escape('.a.b'), '\\.a\\.b', 'mixed string with dot character is escaped correctly');
assert.same(escape('.1+2'), '\\.1\\+2', 'mixed string with plus character is escaped correctly');
assert.same(escape('.a(b)c'), '\\.a\\(b\\)c', 'mixed string with parentheses is escaped correctly');
assert.same(escape('.a*b+c'), '\\.a\\*b\\+c', 'mixed string with asterisk and plus characters is escaped correctly');
assert.same(escape('.a?b^c'), '\\.a\\?b\\^c', 'mixed string with question mark and caret characters is escaped correctly');
assert.same(escape('.a{2}'), '\\.a\\{2\\}', 'mixed string with curly braces is escaped correctly');
assert.same(escape('.a|b'), '\\.a\\|b', 'mixed string with pipe character is escaped correctly');
assert.same(escape('.a\\b'), '\\.a\\\\b', 'mixed string with backslash is escaped correctly');
assert.same(escape('.a\\\\b'), '\\.a\\\\\\\\b', 'mixed string with backslash is escaped correctly');
assert.same(escape('.a^b'), '\\.a\\^b', 'mixed string with caret character is escaped correctly');
assert.same(escape('.a$b'), '\\.a\\$b', 'mixed string with dollar sign is escaped correctly');
assert.same(escape('.a[b]'), '\\.a\\[b\\]', 'mixed string with square brackets is escaped correctly');
assert.same(escape('.a.b(c)'), '\\.a\\.b\\(c\\)', 'mixed string with dot and parentheses is escaped correctly');
assert.same(escape('.a*b+c?d^e$f|g{2}h[i]j\\k'), '\\.a\\*b\\+c\\?d\\^e\\$f\\|g\\{2\\}h\\[i\\]j\\\\k', 'complex string with multiple special characters is escaped correctly');
assert.same(escape('^$\\.*+?()[]{}|'), '\\^\\$\\\\\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|', 'Syntax characters are correctly escaped');
assert.throws(() => escape(123), TypeError, 'non-string input (number) throws TypeError');
assert.throws(() => escape({}), TypeError, 'non-string input (object) throws TypeError');
assert.throws(() => escape([]), TypeError, 'non-string input (array) throws TypeError');
assert.throws(() => escape(null), TypeError, 'non-string input (null) throws TypeError');
assert.throws(() => escape(undefined), TypeError, 'non-string input (undefined) throws TypeError');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.set.difference.js
|
JavaScript
|
import { createIterable, createSetLike } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
// TODO: use /es/ in core-js@4
import Set from 'core-js-pure/full/set';
QUnit.test('Set#difference', assert => {
const { difference } = Set.prototype;
assert.isFunction(difference);
assert.arity(difference, 1);
assert.name(difference, 'difference');
assert.nonEnumerable(Set.prototype, 'difference');
const set = new Set([1]);
assert.notSame(set.difference(new Set()), set);
assert.deepEqual(from(new Set([1, 2, 3]).difference(new Set([4, 5]))), [1, 2, 3]);
assert.deepEqual(from(new Set([1, 2, 3]).difference(new Set([3, 4]))), [1, 2]);
assert.deepEqual(from(new Set([1, 2, 3]).difference(createSetLike([3, 4]))), [1, 2]);
assert.deepEqual(from(new Set([1, 2, 3]).difference(createSetLike([3, 4]))), [1, 2]);
// TODO: drop from core-js@4
assert.deepEqual(from(new Set([1, 2, 3]).difference([4, 5])), [1, 2, 3]);
assert.deepEqual(from(new Set([1, 2, 3]).difference([3, 4])), [1, 2]);
assert.deepEqual(from(new Set([1, 2, 3]).difference(createIterable([3, 4]))), [1, 2]);
assert.same(new Set([42, 43]).difference({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}).size, 0);
assert.throws(() => new Set().difference({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));
assert.throws(() => new Set([1, 2, 3]).difference(), TypeError);
assert.throws(() => difference.call({}, [1, 2, 3]), TypeError);
assert.throws(() => difference.call(undefined, [1, 2, 3]), TypeError);
assert.throws(() => difference.call(null, [1, 2, 3]), TypeError);
// A WebKit bug occurs when `this` is updated while Set.prototype.difference is being executed
// https://bugs.webkit.org/show_bug.cgi?id=288595
const values = [2];
const setLike = {
size: values.length,
has() { return true; },
keys() {
let index = 0;
return {
next() {
const done = index >= values.length;
if (baseSet.has(1)) baseSet.clear();
return { done, value: values[index++] };
},
};
},
};
const baseSet = new Set([1, 2, 3, 4]);
const result = baseSet.difference(setLike);
assert.deepEqual(from(result), [1, 3, 4], 'incorrect behavior when this updated while Set#difference is being executed');
// Mutation via has() in the size(O) <= otherRec.size branch should not skip elements
const mutatingSet = new Set([1, 2, 3]);
const mutatingResult = mutatingSet.difference({
size: 10,
has(v) {
if (v === 1) {
mutatingSet.delete(2);
return true;
}
return false;
},
keys() { return { next() { return { done: true }; } }; },
});
assert.deepEqual(from(mutatingResult), [2, 3], 'iterates copy, not live set in has() branch');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.set.intersection.js
|
JavaScript
|
import { createIterable, createSetLike } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
// TODO: use /es/ in core-js@4
import Set from 'core-js-pure/full/set';
QUnit.test('Set#intersection', assert => {
const { intersection } = Set.prototype;
assert.isFunction(intersection);
assert.arity(intersection, 1);
assert.name(intersection, 'intersection');
assert.nonEnumerable(Set.prototype, 'intersection');
const set = new Set([1]);
assert.notSame(set.intersection(new Set()), set);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(new Set([4, 5]))), []);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(new Set([2, 3, 4]))), [2, 3]);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(createSetLike([4, 5]))), []);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(createSetLike([2, 3, 4]))), [2, 3]);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(new Set([3, 2]))), [3, 2]);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(new Set([3, 2, 1]))), [1, 2, 3]);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(new Set([3, 2, 1, 0]))), [1, 2, 3]);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(createSetLike([3, 2]))), [3, 2]);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(createSetLike([3, 2, 1]))), [1, 2, 3]);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(createSetLike([3, 2, 1, 0]))), [1, 2, 3]);
// TODO: drop from core-js@4
assert.deepEqual(from(new Set([1, 2, 3]).intersection([4, 5])), []);
assert.deepEqual(from(new Set([1, 2, 3]).intersection([2, 3, 4])), [2, 3]);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(createIterable([2, 3, 4]))), [2, 3]);
assert.deepEqual(from(new Set([42, 43]).intersection({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
})), [42, 43]);
assert.throws(() => new Set().intersection({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));
assert.throws(() => new Set([1, 2, 3]).intersection(), TypeError);
assert.throws(() => intersection.call({}, [1, 2, 3]), TypeError);
assert.throws(() => intersection.call(undefined, [1, 2, 3]), TypeError);
assert.throws(() => intersection.call(null, [1, 2, 3]), TypeError);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.set.is-disjoint-from.js
|
JavaScript
|
import { createIterable, createSetLike } from '../helpers/helpers.js';
// TODO: use /es/ in core-js@4
import Set from 'core-js-pure/full/set';
QUnit.test('Set#isDisjointFrom', assert => {
const { isDisjointFrom } = Set.prototype;
assert.isFunction(isDisjointFrom);
assert.arity(isDisjointFrom, 1);
assert.name(isDisjointFrom, 'isDisjointFrom');
assert.nonEnumerable(Set.prototype, 'isDisjointFrom');
assert.true(new Set([1]).isDisjointFrom(new Set([2])));
assert.false(new Set([1]).isDisjointFrom(new Set([1])));
assert.true(new Set([1, 2, 3]).isDisjointFrom(new Set([4, 5, 6])));
assert.false(new Set([1, 2, 3]).isDisjointFrom(new Set([5, 4, 3])));
assert.true(new Set([1]).isDisjointFrom(createSetLike([2])));
assert.false(new Set([1]).isDisjointFrom(createSetLike([1])));
assert.true(new Set([1, 2, 3]).isDisjointFrom(createSetLike([4, 5, 6])));
assert.false(new Set([1, 2, 3]).isDisjointFrom(createSetLike([5, 4, 3])));
// TODO: drop from core-js@4
assert.true(new Set([1]).isDisjointFrom([2]));
assert.false(new Set([1]).isDisjointFrom([1]));
assert.true(new Set([1, 2, 3]).isDisjointFrom([4, 5, 6]));
assert.false(new Set([1, 2, 3]).isDisjointFrom([5, 4, 3]));
assert.true(new Set([1]).isDisjointFrom(createIterable([2])));
assert.false(new Set([1]).isDisjointFrom(createIterable([1])));
assert.false(new Set([42, 43]).isDisjointFrom({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));
assert.throws(() => new Set().isDisjointFrom({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));
let closed = false;
assert.false(new Set([1, 2, 3, 4]).isDisjointFrom({
size: 3,
has() { return true; },
keys() {
let index = 0;
return {
next() {
return { value: [5, 1, 6][index++], done: index > 3 };
},
return() {
closed = true;
return { done: true };
},
};
},
}));
assert.true(closed, 'iterator is closed on early exit');
assert.throws(() => new Set([1, 2, 3]).isDisjointFrom(), TypeError);
assert.throws(() => isDisjointFrom.call({}, [1, 2, 3]), TypeError);
assert.throws(() => isDisjointFrom.call(undefined, [1, 2, 3]), TypeError);
assert.throws(() => isDisjointFrom.call(null, [1, 2, 3]), TypeError);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.set.is-subset-of.js
|
JavaScript
|
import { createIterable, createSetLike } from '../helpers/helpers.js';
// TODO: use /es/ in core-js@4
import Set from 'core-js-pure/full/set';
QUnit.test('Set#isSubsetOf', assert => {
const { isSubsetOf } = Set.prototype;
assert.isFunction(isSubsetOf);
assert.arity(isSubsetOf, 1);
assert.name(isSubsetOf, 'isSubsetOf');
assert.nonEnumerable(Set.prototype, 'isSubsetOf');
assert.true(new Set([1]).isSubsetOf(new Set([1, 2, 3])));
assert.false(new Set([1]).isSubsetOf(new Set([2, 3, 4])));
assert.true(new Set([1, 2, 3]).isSubsetOf(new Set([5, 4, 3, 2, 1])));
assert.false(new Set([1, 2, 3]).isSubsetOf(new Set([5, 4, 3, 2])));
assert.true(new Set([1]).isSubsetOf(createSetLike([1, 2, 3])));
assert.false(new Set([1]).isSubsetOf(createSetLike([2, 3, 4])));
assert.true(new Set([1, 2, 3]).isSubsetOf(createSetLike([5, 4, 3, 2, 1])));
assert.false(new Set([1, 2, 3]).isSubsetOf(createSetLike([5, 4, 3, 2])));
// TODO: drop from core-js@4
assert.true(new Set([1]).isSubsetOf([1, 2, 3]));
assert.false(new Set([1]).isSubsetOf([2, 3, 4]));
assert.true(new Set([1, 2, 3]).isSubsetOf([5, 4, 3, 2, 1]));
assert.false(new Set([1, 2, 3]).isSubsetOf([5, 4, 3, 2]));
assert.true(new Set([1]).isSubsetOf(createIterable([1, 2, 3])));
assert.false(new Set([1]).isSubsetOf(createIterable([2, 3, 4])));
assert.true(new Set([42, 43]).isSubsetOf({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));
assert.throws(() => new Set().isSubsetOf({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));
assert.throws(() => new Set([1, 2, 3]).isSubsetOf(), TypeError);
assert.throws(() => isSubsetOf.call({}, [1, 2, 3]), TypeError);
assert.throws(() => isSubsetOf.call(undefined, [1, 2, 3]), TypeError);
assert.throws(() => isSubsetOf.call(null, [1, 2, 3]), TypeError);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.set.is-superset-of.js
|
JavaScript
|
import { createIterable, createSetLike } from '../helpers/helpers.js';
// TODO: use /es/ in core-js@4
import Set from 'core-js-pure/full/set';
QUnit.test('Set#isSupersetOf', assert => {
const { isSupersetOf } = Set.prototype;
assert.isFunction(isSupersetOf);
assert.arity(isSupersetOf, 1);
assert.name(isSupersetOf, 'isSupersetOf');
assert.nonEnumerable(Set.prototype, 'isSupersetOf');
assert.true(new Set([1, 2, 3]).isSupersetOf(new Set([1])));
assert.false(new Set([2, 3, 4]).isSupersetOf(new Set([1])));
assert.true(new Set([5, 4, 3, 2, 1]).isSupersetOf(new Set([1, 2, 3])));
assert.false(new Set([5, 4, 3, 2]).isSupersetOf(new Set([1, 2, 3])));
assert.true(new Set([1, 2, 3]).isSupersetOf(createSetLike([1])));
assert.false(new Set([2, 3, 4]).isSupersetOf(createSetLike([1])));
assert.true(new Set([5, 4, 3, 2, 1]).isSupersetOf(createSetLike([1, 2, 3])));
assert.false(new Set([5, 4, 3, 2]).isSupersetOf(createSetLike([1, 2, 3])));
// TODO: drop from core-js@4
assert.true(new Set([1, 2, 3]).isSupersetOf([1]));
assert.false(new Set([2, 3, 4]).isSupersetOf([1]));
assert.true(new Set([5, 4, 3, 2, 1]).isSupersetOf([1, 2, 3]));
assert.false(new Set([5, 4, 3, 2]).isSupersetOf([1, 2, 3]));
assert.true(new Set([1, 2, 3]).isSupersetOf(createIterable([1])));
assert.false(new Set([2, 3, 4]).isSupersetOf(createIterable([1])));
assert.false(new Set([42, 43]).isSupersetOf({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));
assert.throws(() => new Set().isSupersetOf({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));
let closed = false;
assert.false(new Set([1, 2, 3, 4]).isSupersetOf({
size: 3,
has() { return true; },
keys() {
let index = 0;
return {
next() {
return { value: [1, 5, 3][index++], done: index > 3 };
},
return() {
closed = true;
return { done: true };
},
};
},
}));
assert.true(closed, 'iterator is closed on early exit');
assert.throws(() => new Set([1, 2, 3]).isSupersetOf(), TypeError);
assert.throws(() => isSupersetOf.call({}, [1, 2, 3]), TypeError);
assert.throws(() => isSupersetOf.call(undefined, [1, 2, 3]), TypeError);
assert.throws(() => isSupersetOf.call(null, [1, 2, 3]), TypeError);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.set.js
|
JavaScript
|
/* eslint-disable sonarjs/no-element-overwrite -- required for testing */
import { createIterable, is, nativeSubclass } from '../helpers/helpers.js';
import { DESCRIPTORS } from '../helpers/constants.js';
import getIterator from 'core-js-pure/es/get-iterator';
import getIteratorMethod from 'core-js-pure/es/get-iterator-method';
import from from 'core-js-pure/es/array/from';
import freeze from 'core-js-pure/es/object/freeze';
import getOwnPropertyDescriptor from 'core-js-pure/es/object/get-own-property-descriptor';
import getOwnPropertyNames from 'core-js-pure/es/object/get-own-property-names';
import getOwnPropertySymbols from 'core-js-pure/es/object/get-own-property-symbols';
import keys from 'core-js-pure/es/object/keys';
import ownKeys from 'core-js-pure/es/reflect/own-keys';
import Symbol from 'core-js-pure/es/symbol';
import Map from 'core-js-pure/es/map';
import Set from 'core-js-pure/es/set';
QUnit.test('Set', assert => {
assert.isFunction(Set);
assert.true('add' in Set.prototype, 'add in Set.prototype');
assert.true('clear' in Set.prototype, 'clear in Set.prototype');
assert.true('delete' in Set.prototype, 'delete in Set.prototype');
assert.true('forEach' in Set.prototype, 'forEach in Set.prototype');
assert.true('has' in Set.prototype, 'has in Set.prototype');
assert.true(new Set() instanceof Set, 'new Set instanceof Set');
let set = new Set();
set.add(1);
set.add(2);
set.add(3);
set.add(2);
set.add(1);
assert.same(set.size, 3);
const result = [];
set.forEach(val => {
result.push(val);
});
assert.deepEqual(result, [1, 2, 3]);
assert.same(new Set(createIterable([1, 2, 3])).size, 3, 'Init from iterable');
assert.same(new Set([freeze({}), 1]).size, 2, 'Support frozen objects');
assert.same(new Set([NaN, NaN, NaN]).size, 1);
assert.deepEqual(from(new Set([3, 4]).add(2).add(1)), [3, 4, 2, 1]);
let done = false;
const { add } = Set.prototype;
Set.prototype.add = function () {
throw new Error();
};
try {
new Set(createIterable([null, 1, 2], {
return() {
return done = true;
},
}));
} catch { /* empty */ }
Set.prototype.add = add;
assert.true(done, '.return #throw');
const array = [];
done = false;
// eslint-disable-next-line es/no-nonstandard-array-prototype-properties -- legacy FF case
array['@@iterator'] = undefined;
array[Symbol.iterator] = function () {
done = true;
return getIteratorMethod([]).call(this);
};
new Set(array);
assert.true(done);
const object = {};
new Set().add(object);
if (DESCRIPTORS) {
const results = [];
for (const key in results) keys.push(key);
assert.arrayEqual(results, []);
assert.arrayEqual(keys(object), []);
}
assert.arrayEqual(getOwnPropertyNames(object), []);
if (getOwnPropertySymbols) assert.arrayEqual(getOwnPropertySymbols(object), []);
if (ownKeys) assert.arrayEqual(ownKeys(object), []);
if (nativeSubclass) {
const Subclass = nativeSubclass(Set);
assert.true(new Subclass() instanceof Subclass, 'correct subclassing with native classes #1');
assert.true(new Subclass() instanceof Set, 'correct subclassing with native classes #2');
assert.true(new Subclass().add(2).has(2), 'correct subclassing with native classes #3');
}
if (typeof ArrayBuffer == 'function') {
const buffer = new ArrayBuffer(8);
set = new Set([buffer]);
assert.true(set.has(buffer), 'works with ArrayBuffer keys');
}
});
QUnit.test('Set#add', assert => {
assert.isFunction(Set.prototype.add);
const array = [];
let set = new Set();
set.add(NaN);
set.add(2);
set.add(3);
set.add(2);
set.add(1);
set.add(array);
assert.same(set.size, 5);
const chain = set.add(NaN);
assert.same(chain, set);
assert.same(set.size, 5);
set.add(2);
assert.same(set.size, 5);
set.add(array);
assert.same(set.size, 5);
set.add([]);
assert.same(set.size, 6);
set.add(4);
assert.same(set.size, 7);
const frozen = freeze({});
set = new Set();
set.add(frozen);
assert.true(set.has(frozen));
});
QUnit.test('Set#clear', assert => {
assert.isFunction(Set.prototype.clear);
let set = new Set();
set.clear();
assert.same(set.size, 0);
set = new Set();
set.add(1);
set.add(2);
set.add(3);
set.add(2);
set.add(1);
set.clear();
assert.same(set.size, 0);
assert.false(set.has(1));
assert.false(set.has(2));
assert.false(set.has(3));
const frozen = freeze({});
set = new Set();
set.add(1);
set.add(frozen);
set.clear();
assert.same(set.size, 0, 'Support frozen objects');
assert.false(set.has(1));
assert.false(set.has(frozen));
});
QUnit.test('Set#delete', assert => {
assert.isFunction(Set.prototype.delete);
const array = [];
const set = new Set();
set.add(NaN);
set.add(2);
set.add(3);
set.add(2);
set.add(1);
set.add(array);
assert.same(set.size, 5);
assert.true(set.delete(NaN));
assert.same(set.size, 4);
assert.false(set.delete(4));
assert.same(set.size, 4);
set.delete([]);
assert.same(set.size, 4);
set.delete(array);
assert.same(set.size, 3);
const frozen = freeze({});
set.add(frozen);
assert.same(set.size, 4);
set.delete(frozen);
assert.same(set.size, 3);
});
QUnit.test('Set#forEach', assert => {
assert.isFunction(Set.prototype.forEach);
let result = [];
let count = 0;
let set = new Set();
set.add(1);
set.add(2);
set.add(3);
set.add(2);
set.add(1);
set.forEach(value => {
count++;
result.push(value);
});
assert.same(count, 3);
assert.deepEqual(result, [1, 2, 3]);
set = new Set();
set.add('0');
set.add('1');
set.add('2');
set.add('3');
result = '';
set.forEach(it => {
result += it;
if (it === '2') {
set.delete('2');
set.delete('3');
set.delete('1');
set.add('4');
}
});
assert.same(result, '0124');
set = new Set();
set.add('0');
result = '';
set.forEach(it => {
set.delete('0');
if (result !== '') throw new Error();
result += it;
});
assert.same(result, '0');
assert.throws(() => {
Set.prototype.forEach.call(new Map(), () => { /* empty */ });
}, 'non-generic');
});
QUnit.test('Set#has', assert => {
assert.isFunction(Set.prototype.has);
const array = [];
const frozen = freeze({});
const set = new Set();
set.add(NaN);
set.add(2);
set.add(3);
set.add(2);
set.add(1);
set.add(frozen);
set.add(array);
assert.true(set.has(NaN));
assert.true(set.has(array));
assert.true(set.has(frozen));
assert.true(set.has(2));
assert.false(set.has(4));
assert.false(set.has([]));
});
QUnit.test('Set#size', assert => {
const set = new Set();
set.add(1);
const { size } = set;
assert.same(typeof size, 'number', 'size is number');
assert.same(size, 1, 'size is correct');
if (DESCRIPTORS) {
const sizeDescriptor = getOwnPropertyDescriptor(Set.prototype, 'size');
const getter = sizeDescriptor && sizeDescriptor.get;
const setter = sizeDescriptor && sizeDescriptor.set;
assert.same(typeof getter, 'function', 'size is getter');
assert.same(typeof setter, 'undefined', 'size is not setter');
assert.throws(() => {
Set.prototype.size;
}, TypeError);
}
});
QUnit.test('Set & -0', assert => {
let set = new Set();
set.add(-0);
assert.same(set.size, 1);
assert.true(set.has(0));
assert.true(set.has(-0));
set.forEach(it => {
assert.false(is(it, -0));
});
set.delete(-0);
assert.same(set.size, 0);
set = new Set([-0]);
set.forEach(key => {
assert.false(is(key, -0));
});
set = new Set();
set.add(4);
set.add(3);
set.add(2);
set.add(1);
set.add(0);
assert.true(set.has(-0));
});
QUnit.test('Set#@@toStringTag', assert => {
assert.same(Set.prototype[Symbol.toStringTag], 'Set', 'Set::@@toStringTag is `Set`');
assert.same(String(new Set()), '[object Set]', 'correct stringification');
});
QUnit.test('Set Iterator', assert => {
const set = new Set();
set.add('a');
set.add('b');
set.add('c');
set.add('d');
const results = [];
const iterator = set.keys();
results.push(iterator.next().value);
assert.true(set.delete('a'));
assert.true(set.delete('b'));
assert.true(set.delete('c'));
set.add('e');
results.push(iterator.next().value, iterator.next().value);
assert.true(iterator.next().done);
set.add('f');
assert.true(iterator.next().done);
assert.deepEqual(results, ['a', 'd', 'e']);
});
QUnit.test('Set#keys', assert => {
assert.isFunction(Set.prototype.keys);
const set = new Set();
set.add('q');
set.add('w');
set.add('e');
const iterator = set.keys();
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Set Iterator');
assert.deepEqual(iterator.next(), {
value: 'q',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'w',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'e',
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});
QUnit.test('Set#values', assert => {
assert.isFunction(Set.prototype.values);
const set = new Set();
set.add('q');
set.add('w');
set.add('e');
const iterator = set.values();
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Set Iterator');
assert.deepEqual(iterator.next(), {
value: 'q',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'w',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'e',
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});
QUnit.test('Set#entries', assert => {
assert.isFunction(Set.prototype.entries);
const set = new Set();
set.add('q');
set.add('w');
set.add('e');
const iterator = set.entries();
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Set Iterator');
assert.deepEqual(iterator.next(), {
value: ['q', 'q'],
done: false,
});
assert.deepEqual(iterator.next(), {
value: ['w', 'w'],
done: false,
});
assert.deepEqual(iterator.next(), {
value: ['e', 'e'],
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});
QUnit.test('Set#@@iterator', assert => {
const set = new Set();
set.add('q');
set.add('w');
set.add('e');
const iterator = getIterator(set);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Set Iterator');
assert.same(String(iterator), '[object Set Iterator]');
assert.deepEqual(iterator.next(), {
value: 'q',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'w',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'e',
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.set.symmetric-difference.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import { createIterable, createSetLike } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
import defineProperty from 'core-js-pure/es/object/define-property';
// TODO: use /es/ in core-js@4
import Set from 'core-js-pure/full/set';
QUnit.test('Set#symmetricDifference', assert => {
const { symmetricDifference } = Set.prototype;
assert.isFunction(symmetricDifference);
assert.arity(symmetricDifference, 1);
assert.name(symmetricDifference, 'symmetricDifference');
assert.nonEnumerable(Set.prototype, 'symmetricDifference');
const set = new Set([1]);
assert.notSame(set.symmetricDifference(new Set()), set);
assert.deepEqual(from(new Set([1, 2, 3]).symmetricDifference(new Set([4, 5]))), [1, 2, 3, 4, 5]);
assert.deepEqual(from(new Set([1, 2, 3]).symmetricDifference(new Set([3, 4]))), [1, 2, 4]);
assert.deepEqual(from(new Set([1, 2, 3]).symmetricDifference(createSetLike([4, 5]))), [1, 2, 3, 4, 5]);
assert.deepEqual(from(new Set([1, 2, 3]).symmetricDifference(createSetLike([3, 4]))), [1, 2, 4]);
// TODO: drop from core-js@4
assert.deepEqual(from(new Set([1, 2, 3]).symmetricDifference([4, 5])), [1, 2, 3, 4, 5]);
assert.deepEqual(from(new Set([1, 2, 3]).symmetricDifference([3, 4])), [1, 2, 4]);
assert.deepEqual(from(new Set([1, 2, 3]).symmetricDifference(createIterable([4, 5]))), [1, 2, 3, 4, 5]);
assert.deepEqual(from(new Set([1, 2, 3]).symmetricDifference(createIterable([3, 4]))), [1, 2, 4]);
assert.throws(() => new Set([1, 2, 3]).symmetricDifference(), TypeError);
assert.throws(() => symmetricDifference.call({}, [1, 2, 3]), TypeError);
assert.throws(() => symmetricDifference.call(undefined, [1, 2, 3]), TypeError);
assert.throws(() => symmetricDifference.call(null, [1, 2, 3]), TypeError);
// Duplicate keys in other's iterator: value present in O should be removed idempotently
{
const baseSet = new Set([1, 2, 3]);
const setLike = {
size: 2,
has() { return false; },
keys() {
const vals = [2, 2];
let i = 0;
return { next() { return i < vals.length ? { done: false, value: vals[i++] } : { done: true }; } };
},
};
assert.deepEqual(from(baseSet.symmetricDifference(setLike)), [1, 3]);
}
{
// https://github.com/WebKit/WebKit/pull/27264/files#diff-7bdbbad7ceaa222787994f2db702dd45403fa98e14d6270aa65aaf09754dcfe0R8
const baseSet = new Set(['a', 'b', 'c', 'd', 'e']);
const values = ['f', 'g', 'h', 'i', 'j'];
const setLike = {
size: values.length,
has() { return true; },
keys() {
let index = 0;
return {
next() {
const done = index >= values.length;
if (!baseSet.has('f')) baseSet.add('f');
return { done, value: values[index++] };
},
};
},
};
assert.deepEqual(from(baseSet.symmetricDifference(setLike)), ['a', 'b', 'c', 'd', 'e', 'g', 'h', 'i', 'j']);
}
if (DESCRIPTORS) {
// Should get iterator record of a set-like object before cloning this
// https://bugs.webkit.org/show_bug.cgi?id=289430
const baseSet = new Set();
const setLike = {
size: 0,
has() { return true; },
keys() {
return defineProperty({}, 'next', { get() {
baseSet.clear();
baseSet.add(4);
return function () {
return { done: true };
};
} });
},
};
assert.deepEqual(from(baseSet.symmetricDifference(setLike)), [4]);
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.set.union.js
|
JavaScript
|
import { DESCRIPTORS } from '../helpers/constants.js';
import { createIterable, createSetLike } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
import defineProperty from 'core-js-pure/es/object/define-property';
// TODO: use /es/ in core-js@4
import Set from 'core-js-pure/full/set';
QUnit.test('Set#union', assert => {
const { union } = Set.prototype;
assert.isFunction(union);
assert.arity(union, 1);
assert.name(union, 'union');
assert.nonEnumerable(Set.prototype, 'union');
const set = new Set([1]);
assert.notSame(set.union(new Set()), set);
assert.deepEqual(from(new Set([1, 2, 3]).union(new Set([4, 5]))), [1, 2, 3, 4, 5]);
assert.deepEqual(from(new Set([1, 2, 3]).union(new Set([3, 4]))), [1, 2, 3, 4]);
assert.deepEqual(from(new Set([1, 2, 3]).union(createSetLike([4, 5]))), [1, 2, 3, 4, 5]);
assert.deepEqual(from(new Set([1, 2, 3]).union(createSetLike([3, 4]))), [1, 2, 3, 4]);
// TODO: drop from core-js@4
assert.deepEqual(from(new Set([1, 2, 3]).union([4, 5])), [1, 2, 3, 4, 5]);
assert.deepEqual(from(new Set([1, 2, 3]).union([3, 4])), [1, 2, 3, 4]);
assert.deepEqual(from(new Set([1, 2, 3]).union(createIterable([3, 4]))), [1, 2, 3, 4]);
assert.throws(() => new Set([1, 2, 3]).union(), TypeError);
assert.throws(() => union.call({}, [1, 2, 3]), TypeError);
assert.throws(() => union.call(undefined, [1, 2, 3]), TypeError);
assert.throws(() => union.call(null, [1, 2, 3]), TypeError);
if (DESCRIPTORS) {
// Should get iterator record of a set-like object before cloning this
// https://bugs.webkit.org/show_bug.cgi?id=289430
const baseSet = new Set();
const setLike = {
size: 0,
has() { return true; },
keys() {
return defineProperty({}, 'next', { get() {
baseSet.clear();
baseSet.add(4);
return function () {
return { done: true };
};
} });
},
};
assert.deepEqual(from(baseSet.union(setLike)), [4]);
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.anchor.js
|
JavaScript
|
import anchor from 'core-js-pure/es/string/anchor';
QUnit.test('String#anchor', assert => {
assert.isFunction(anchor);
assert.same(anchor('a', 'b'), '<a name="b">a</a>', 'lower case');
assert.same(anchor('a', '"'), '<a name=""">a</a>', 'escape quotes');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
const symbol = Symbol('anchor test');
assert.throws(() => anchor(symbol, 'b'), 'throws on symbol context');
assert.throws(() => anchor('a', symbol), 'throws on symbol argument');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.at-alternative.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import at from 'core-js-pure/es/string/at';
QUnit.test('String#at', assert => {
assert.isFunction(at);
assert.same('1', at('123', 0));
assert.same('2', at('123', 1));
assert.same('3', at('123', 2));
assert.same(undefined, at('123', 3));
assert.same('3', at('123', -1));
assert.same('2', at('123', -2));
assert.same('1', at('123', -3));
assert.same(undefined, at('123', -4));
assert.same('1', at('123', 0.4));
assert.same('1', at('123', 0.5));
assert.same('1', at('123', 0.6));
assert.same('1', at('1', NaN));
assert.same('1', at('1'));
assert.same('1', at('123', -0));
// TODO: disabled by default because of the conflict with old proposal
// assert.same('\uD842', at('𠮷'));
assert.same('1', at({ toString() { return '123'; } }, 0));
assert.throws(() => at(Symbol('at-alternative test'), 0), 'throws on symbol context');
if (STRICT) {
assert.throws(() => at(null, 0), TypeError);
assert.throws(() => at(undefined, 0), TypeError);
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.big.js
|
JavaScript
|
import big from 'core-js-pure/es/string/big';
QUnit.test('String#big', assert => {
assert.isFunction(big);
assert.same(big('a'), '<big>a</big>', 'lower case');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => big(Symbol('big test')), 'throws on symbol argument');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.blink.js
|
JavaScript
|
import blink from 'core-js-pure/es/string/blink';
QUnit.test('String#blink', assert => {
assert.isFunction(blink);
assert.same(blink('a'), '<blink>a</blink>', 'lower case');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => blink(Symbol('blink test')), 'throws on symbol context');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.bold.js
|
JavaScript
|
import bold from 'core-js-pure/es/string/bold';
QUnit.test('String#bold', assert => {
assert.isFunction(bold);
assert.same(bold('a'), '<b>a</b>', 'lower case');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => bold(Symbol('bold test')), 'throws on symbol context');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.code-point-at.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import codePointAt from 'core-js-pure/es/string/code-point-at';
QUnit.test('String#codePointAt', assert => {
assert.isFunction(codePointAt);
assert.same(codePointAt('abc\uD834\uDF06def', ''), 0x61);
assert.same(codePointAt('abc\uD834\uDF06def', '_'), 0x61);
assert.same(codePointAt('abc\uD834\uDF06def'), 0x61);
assert.same(codePointAt('abc\uD834\uDF06def', -Infinity), undefined);
assert.same(codePointAt('abc\uD834\uDF06def', -1), undefined);
assert.same(codePointAt('abc\uD834\uDF06def', -0), 0x61);
assert.same(codePointAt('abc\uD834\uDF06def', 0), 0x61);
assert.same(codePointAt('abc\uD834\uDF06def', 3), 0x1D306);
assert.same(codePointAt('abc\uD834\uDF06def', 4), 0xDF06);
assert.same(codePointAt('abc\uD834\uDF06def', 5), 0x64);
assert.same(codePointAt('abc\uD834\uDF06def', 42), undefined);
assert.same(codePointAt('abc\uD834\uDF06def', Infinity), undefined);
assert.same(codePointAt('abc\uD834\uDF06def', Infinity), undefined);
assert.same(codePointAt('abc\uD834\uDF06def', NaN), 0x61);
assert.same(codePointAt('abc\uD834\uDF06def', false), 0x61);
assert.same(codePointAt('abc\uD834\uDF06def', null), 0x61);
assert.same(codePointAt('abc\uD834\uDF06def', undefined), 0x61);
assert.same(codePointAt('\uD834\uDF06def', ''), 0x1D306);
assert.same(codePointAt('\uD834\uDF06def', '1'), 0xDF06);
assert.same(codePointAt('\uD834\uDF06def', '_'), 0x1D306);
assert.same(codePointAt('\uD834\uDF06def'), 0x1D306);
assert.same(codePointAt('\uD834\uDF06def', -1), undefined);
assert.same(codePointAt('\uD834\uDF06def', -0), 0x1D306);
assert.same(codePointAt('\uD834\uDF06def', 0), 0x1D306);
assert.same(codePointAt('\uD834\uDF06def', 1), 0xDF06);
assert.same(codePointAt('\uD834\uDF06def', 42), undefined);
assert.same(codePointAt('\uD834\uDF06def', false), 0x1D306);
assert.same(codePointAt('\uD834\uDF06def', null), 0x1D306);
assert.same(codePointAt('\uD834\uDF06def', undefined), 0x1D306);
assert.same(codePointAt('\uD834abc', ''), 0xD834);
assert.same(codePointAt('\uD834abc', '_'), 0xD834);
assert.same(codePointAt('\uD834abc'), 0xD834);
assert.same(codePointAt('\uD834abc', -1), undefined);
assert.same(codePointAt('\uD834abc', -0), 0xD834);
assert.same(codePointAt('\uD834abc', 0), 0xD834);
assert.same(codePointAt('\uD834abc', false), 0xD834);
assert.same(codePointAt('\uD834abc', NaN), 0xD834);
assert.same(codePointAt('\uD834abc', null), 0xD834);
assert.same(codePointAt('\uD834abc', undefined), 0xD834);
assert.same(codePointAt('\uDF06abc', ''), 0xDF06);
assert.same(codePointAt('\uDF06abc', '_'), 0xDF06);
assert.same(codePointAt('\uDF06abc'), 0xDF06);
assert.same(codePointAt('\uDF06abc', -1), undefined);
assert.same(codePointAt('\uDF06abc', -0), 0xDF06);
assert.same(codePointAt('\uDF06abc', 0), 0xDF06);
assert.same(codePointAt('\uDF06abc', false), 0xDF06);
assert.same(codePointAt('\uDF06abc', NaN), 0xDF06);
assert.same(codePointAt('\uDF06abc', null), 0xDF06);
assert.same(codePointAt('\uDF06abc', undefined), 0xDF06);
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => codePointAt(Symbol('codePointAt test'), 1), 'throws on symbol context');
}
if (STRICT) {
assert.throws(() => codePointAt(null, 0), TypeError);
assert.throws(() => codePointAt(undefined, 0), TypeError);
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.ends-with.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import endsWith from 'core-js-pure/es/string/ends-with';
QUnit.test('String#endsWith', assert => {
assert.isFunction(endsWith);
assert.true(endsWith('undefined'));
assert.false(endsWith('undefined', null));
assert.true(endsWith('abc', ''));
assert.true(endsWith('abc', 'c'));
assert.true(endsWith('abc', 'bc'));
assert.false(endsWith('abc', 'ab'));
assert.true(endsWith('abc', '', NaN));
assert.false(endsWith('abc', 'c', -1));
assert.true(endsWith('abc', 'a', 1));
assert.true(endsWith('abc', 'c', Infinity));
assert.true(endsWith('abc', 'a', true));
assert.false(endsWith('abc', 'c', 'x'));
assert.false(endsWith('abc', 'a', 'x'));
if (!Symbol.sham) {
const symbol = Symbol('endsWith test');
assert.throws(() => endsWith(symbol, 'b'), 'throws on symbol context');
assert.throws(() => endsWith('a', symbol), 'throws on symbol argument');
}
if (STRICT) {
assert.throws(() => endsWith(null, '.'), TypeError);
assert.throws(() => endsWith(undefined, '.'), TypeError);
}
const regexp = /./;
assert.throws(() => endsWith('/./', regexp), TypeError);
regexp[Symbol.match] = false;
assert.notThrows(() => endsWith('/./', regexp));
const object = {};
assert.notThrows(() => endsWith('[object Object]', object));
object[Symbol.match] = true;
assert.throws(() => endsWith('[object Object]', object), TypeError);
// side-effect ordering: ToString(searchString) should happen before ToIntegerOrInfinity(endPosition)
const order = [];
endsWith(
'abc',
{ toString() { order.push('search'); return 'c'; } },
{ valueOf() { order.push('pos'); return 3; } },
);
assert.deepEqual(order, ['search', 'pos'], 'ToString(searchString) before ToIntegerOrInfinity(endPosition)');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.fixed.js
|
JavaScript
|
import fixed from 'core-js-pure/es/string/fixed';
QUnit.test('String#fixed', assert => {
assert.isFunction(fixed);
assert.same(fixed('a'), '<tt>a</tt>', 'lower case');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => fixed(Symbol('fixed test')), 'throws on symbol context');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.fontcolor.js
|
JavaScript
|
import fontcolor from 'core-js-pure/es/string/fontcolor';
QUnit.test('String#fontcolor', assert => {
assert.isFunction(fontcolor);
assert.same(fontcolor('a', 'b'), '<font color="b">a</font>', 'lower case');
assert.same(fontcolor('a', '"'), '<font color=""">a</font>', 'escape quotes');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
const symbol = Symbol('fontcolor test');
assert.throws(() => fontcolor(symbol, 'b'), 'throws on symbol context');
assert.throws(() => fontcolor('a', symbol), 'throws on symbol argument');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.fontsize.js
|
JavaScript
|
import fontsize from 'core-js-pure/es/string/fontsize';
QUnit.test('String#fontsize', assert => {
assert.isFunction(fontsize);
assert.same(fontsize('a', 'b'), '<font size="b">a</font>', 'lower case');
assert.same(fontsize('a', '"'), '<font size=""">a</font>', 'escape quotes');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
const symbol = Symbol('fontsize test');
assert.throws(() => fontsize(symbol, 'b'), 'throws on symbol context');
assert.throws(() => fontsize('a', symbol), 'throws on symbol argument');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.from-code-point.js
|
JavaScript
|
/* eslint-disable prefer-spread -- required for testing */
import fromCodePoint from 'core-js-pure/es/string/from-code-point';
QUnit.test('String.fromCodePoint', assert => {
assert.isFunction(fromCodePoint);
assert.arity(fromCodePoint, 1);
if ('name' in fromCodePoint) {
assert.name(fromCodePoint, 'fromCodePoint');
}
assert.same(fromCodePoint(''), '\0');
assert.same(fromCodePoint(), '');
assert.same(fromCodePoint(-0), '\0');
assert.same(fromCodePoint(0), '\0');
assert.same(fromCodePoint(0x1D306), '\uD834\uDF06');
assert.same(fromCodePoint(0x1D306, 0x61, 0x1D307), '\uD834\uDF06a\uD834\uDF07');
assert.same(fromCodePoint(0x61, 0x62, 0x1D307), 'ab\uD834\uDF07');
assert.same(fromCodePoint(false), '\0');
assert.same(fromCodePoint(null), '\0');
assert.throws(() => fromCodePoint('_'), RangeError);
assert.throws(() => fromCodePoint('+Infinity'), RangeError);
assert.throws(() => fromCodePoint('-Infinity'), RangeError);
assert.throws(() => fromCodePoint(-1), RangeError);
assert.throws(() => fromCodePoint(0x10FFFF + 1), RangeError);
assert.throws(() => fromCodePoint(3.14), RangeError);
assert.throws(() => fromCodePoint(3e-2), RangeError);
assert.throws(() => fromCodePoint(-Infinity), RangeError);
assert.throws(() => fromCodePoint(Infinity), RangeError);
assert.throws(() => fromCodePoint(NaN), RangeError);
assert.throws(() => fromCodePoint(undefined), RangeError);
assert.throws(() => fromCodePoint({}), RangeError);
assert.throws(() => fromCodePoint(/./), RangeError);
let number = 0x60;
assert.same(fromCodePoint({
valueOf() {
return ++number;
},
}), 'a');
assert.same(number, 0x61);
// one code unit per symbol
let counter = 2 ** 15 * 3 / 2;
let result = [];
while (--counter >= 0) result.push(0);
// should not throw
fromCodePoint.apply(null, result);
counter = 2 ** 15 * 3 / 2;
result = [];
while (--counter >= 0) result.push(0xFFFF + 1);
// should not throw
fromCodePoint.apply(null, result);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.includes.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import includes from 'core-js-pure/es/string/includes';
QUnit.test('String#includes', assert => {
assert.isFunction(includes);
assert.false(includes('abc'));
assert.true(includes('aundefinedb'));
assert.true(includes('abcd', 'b', 1));
assert.false(includes('abcd', 'b', 2));
if (!Symbol.sham) {
const symbol = Symbol('includes test');
assert.throws(() => includes(symbol, 'b'), 'throws on symbol context');
assert.throws(() => includes('a', symbol), 'throws on symbol argument');
}
if (STRICT) {
assert.throws(() => includes(null, '.'), TypeError);
assert.throws(() => includes(undefined, '.'), TypeError);
}
const re = /./;
assert.throws(() => includes('/./', re), TypeError);
re[Symbol.match] = false;
assert.notThrows(() => includes('/./', re));
const O = {};
assert.notThrows(() => includes('[object Object]', O));
O[Symbol.match] = true;
assert.throws(() => includes('[object Object]', O), TypeError);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.is-well-formed.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import isWellFormed from 'core-js-pure/es/string/virtual/is-well-formed';
QUnit.test('String#isWellFormed', assert => {
assert.isFunction(isWellFormed);
assert.true(isWellFormed.call('a'), 'a');
assert.true(isWellFormed.call('abc'), 'abc');
assert.true(isWellFormed.call('💩'), '💩');
assert.true(isWellFormed.call('💩b'), '💩b');
assert.true(isWellFormed.call('a💩'), '💩');
assert.true(isWellFormed.call('a💩b'), 'a💩b');
assert.true(isWellFormed.call('💩a💩'), '💩a💩');
assert.true(!isWellFormed.call('\uD83D'), '\uD83D');
assert.true(!isWellFormed.call('\uDCA9'), '\uDCA9');
assert.true(!isWellFormed.call('\uDCA9\uD83D'), '\uDCA9\uD83D');
assert.true(!isWellFormed.call('a\uD83D'), 'a\uD83D');
assert.true(!isWellFormed.call('\uDCA9a'), '\uDCA9a');
assert.true(!isWellFormed.call('a\uD83Da'), 'a\uD83Da');
assert.true(!isWellFormed.call('a\uDCA9a'), 'a\uDCA9a');
assert.true(isWellFormed.call({
toString() {
return 'abc';
},
}), 'conversion #1');
assert.true(!isWellFormed.call({
toString() {
return '\uD83D';
},
}), 'conversion #2');
if (STRICT) {
assert.throws(() => isWellFormed.call(null), TypeError, 'coercible #1');
assert.throws(() => isWellFormed.call(undefined), TypeError, 'coercible #2');
}
assert.throws(() => isWellFormed.call(Symbol('isWellFormed test')), 'throws on symbol context');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.italics.js
|
JavaScript
|
import italics from 'core-js-pure/es/string/italics';
QUnit.test('String#italics', assert => {
assert.isFunction(italics);
assert.same(italics('a'), '<i>a</i>', 'lower case');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => italics(Symbol('italics test')), 'throws on symbol context');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.iterator.js
|
JavaScript
|
import getIterator from 'core-js-pure/es/get-iterator';
// import getIteratorMethod from 'core-js-pure/es/get-iterator-method';
import Symbol from 'core-js-pure/es/symbol';
import from from 'core-js-pure/es/array/from';
QUnit.test('String#@@iterator', assert => {
let iterator = getIterator('qwe');
assert.isIterator(iterator);
assert.same(iterator[Symbol.toStringTag], 'String Iterator');
assert.same(String(iterator), '[object String Iterator]');
assert.deepEqual(iterator.next(), {
value: 'q',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'w',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'e',
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
assert.same(from('𠮷𠮷𠮷').length, 3);
iterator = getIterator('𠮷𠮷𠮷');
assert.deepEqual(iterator.next(), {
value: '𠮷',
done: false,
});
assert.deepEqual(iterator.next(), {
value: '𠮷',
done: false,
});
assert.deepEqual(iterator.next(), {
value: '𠮷',
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
// early FF case with native method, but polyfilled `Symbol`
// assert.throws(() => getIteratorMethod('').call(Symbol()), 'throws on symbol context');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.link.js
|
JavaScript
|
import link from 'core-js-pure/es/string/link';
QUnit.test('String#link', assert => {
assert.isFunction(link);
assert.same(link('a', 'b'), '<a href="b">a</a>', 'lower case');
assert.same(link('a', '"'), '<a href=""">a</a>', 'escape quotes');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
const symbol = Symbol('link test');
assert.throws(() => link(symbol, 'b'), 'throws on symbol context');
assert.throws(() => link('a', symbol), 'throws on symbol argument');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.match-all.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import assign from 'core-js-pure/es/object/assign';
import matchAll from 'core-js-pure/es/string/match-all';
QUnit.test('String#matchAll', assert => {
assert.isFunction(matchAll);
let data = ['aabc', { toString() {
return 'aabc';
} }];
for (const target of data) {
const iterator = matchAll(target, /[ac]/g);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.deepEqual(iterator.next(), {
value: assign(['a'], {
input: 'aabc',
index: 0,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: assign(['a'], {
input: 'aabc',
index: 1,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: assign(['c'], {
input: 'aabc',
index: 3,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
}
let iterator = matchAll('1111a2b3cccc', /(\d)(\D)/g);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'RegExp String Iterator');
assert.same(String(iterator), '[object RegExp String Iterator]');
assert.deepEqual(iterator.next(), {
value: assign(['1a', '1', 'a'], {
input: '1111a2b3cccc',
index: 3,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: assign(['2b', '2', 'b'], {
input: '1111a2b3cccc',
index: 5,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: assign(['3c', '3', 'c'], {
input: '1111a2b3cccc',
index: 7,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
assert.throws(() => matchAll('1111a2b3cccc', /(\d)(\D)/), TypeError);
iterator = matchAll('1111a2b3cccc', '(\\d)(\\D)');
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.deepEqual(iterator.next(), {
value: assign(['1a', '1', 'a'], {
input: '1111a2b3cccc',
index: 3,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: assign(['2b', '2', 'b'], {
input: '1111a2b3cccc',
index: 5,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: assign(['3c', '3', 'c'], {
input: '1111a2b3cccc',
index: 7,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
/* IE8- issue
iterator = matchAll('abc', /\B/g);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.deepEqual(iterator.next(), {
value: assign([''], {
input: 'abc',
index: 1,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: assign([''], {
input: 'abc',
index: 2,
}),
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
*/
data = [null, undefined, NaN, 42, {}, []];
for (const target of data) {
assert.notThrows(() => matchAll('', target), `Not throws on ${ target } as the first argument`);
}
assert.throws(() => matchAll(Symbol('matchAll test'), /./), 'throws on symbol context');
if (STRICT) {
assert.throws(() => matchAll(null, /./g), TypeError, 'Throws on null as `this`');
assert.throws(() => matchAll(undefined, /./g), TypeError, 'Throws on undefined as `this`');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.pad-end.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import padEnd from 'core-js-pure/es/string/pad-end';
QUnit.test('String#padEnd', assert => {
assert.isFunction(padEnd);
assert.same(padEnd('abc', 5), 'abc ');
assert.same(padEnd('abc', 4, 'de'), 'abcd');
assert.same(padEnd('abc'), 'abc');
assert.same(padEnd('abc', 5, '_'), 'abc__');
assert.same(padEnd('', 0), '');
assert.same(padEnd('foo', 1), 'foo');
assert.same(padEnd('foo', 5, ''), 'foo');
const symbol = Symbol('padEnd test');
assert.throws(() => padEnd(symbol, 10, 'a'), 'throws on symbol context');
assert.throws(() => padEnd('a', 10, symbol), 'throws on symbol argument');
if (STRICT) {
assert.throws(() => padEnd(null, 0), TypeError);
assert.throws(() => padEnd(undefined, 0), TypeError);
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.pad-start.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import padStart from 'core-js-pure/es/string/pad-start';
QUnit.test('String#padStart', assert => {
assert.isFunction(padStart);
assert.same(padStart('abc', 5), ' abc');
assert.same(padStart('abc', 4, 'de'), 'dabc');
assert.same(padStart('abc'), 'abc');
assert.same(padStart('abc', 5, '_'), '__abc');
assert.same(padStart('', 0), '');
assert.same(padStart('foo', 1), 'foo');
assert.same(padStart('foo', 5, ''), 'foo');
const symbol = Symbol('padEnd test');
assert.throws(() => padStart(symbol, 10, 'a'), 'throws on symbol context');
assert.throws(() => padStart('a', 10, symbol), 'throws on symbol argument');
if (STRICT) {
assert.throws(() => padStart(null, 0), TypeError);
assert.throws(() => padStart(undefined, 0), TypeError);
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.raw.js
|
JavaScript
|
import raw from 'core-js-pure/es/string/raw';
QUnit.test('String.raw', assert => {
assert.isFunction(raw);
assert.arity(raw, 1);
if ('name' in raw) {
assert.name(raw, 'raw');
}
assert.same(raw({ raw: ['Hi\\n', '!'] }, 'Bob'), 'Hi\\nBob!', 'raw is array');
assert.same(raw({ raw: 'test' }, 0, 1, 2), 't0e1s2t', 'raw is string');
assert.same(raw({ raw: 'test' }, 0), 't0est', 'lacks substituting');
assert.same(raw({ raw: [] }), '', 'empty template');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
const symbol = Symbol('raw test');
assert.throws(() => raw({ raw: [symbol] }, 0), TypeError, 'throws on symbol #1');
assert.throws(() => raw({ raw: 'test' }, symbol), TypeError, 'throws on symbol #2');
}
assert.throws(() => raw({}), TypeError);
assert.throws(() => raw({ raw: null }), TypeError);
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.repeat.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import repeat from 'core-js-pure/es/string/repeat';
QUnit.test('String#repeat', assert => {
assert.isFunction(repeat);
assert.same(repeat('qwe', 3), 'qweqweqwe');
assert.same(repeat('qwe', 2.5), 'qweqwe');
assert.throws(() => repeat('qwe', -1), RangeError);
assert.throws(() => repeat('qwe', Infinity), RangeError);
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => repeat(Symbol('repeat test')), 'throws on symbol context');
}
if (STRICT) {
assert.throws(() => repeat(null, 1), TypeError);
assert.throws(() => repeat(undefined, 1), TypeError);
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.replace-all.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import replaceAll from 'core-js-pure/es/string/replace-all';
QUnit.test('String#replaceAll', assert => {
assert.isFunction(replaceAll);
assert.same(replaceAll('q=query+string+parameters', '+', ' '), 'q=query string parameters');
assert.same(replaceAll('foo', 'o', {}), 'f[object Object][object Object]');
assert.same(replaceAll('[object Object]x[object Object]', {}, 'y'), 'yxy');
assert.same(replaceAll({}, 'bject', 'lolo'), '[ololo Ololo]');
assert.same(replaceAll('aba', 'b', (search, i, string) => {
assert.same(search, 'b', '`search` is `b`');
assert.same(i, 1, '`i` is 1');
assert.same(string, 'aba', '`string` is `aba`');
return 'c';
}), 'aca');
const searcher = {
[Symbol.replace](O, replaceValue) {
assert.same(this, searcher, '`this` is `searcher`');
assert.same(String(O), 'aba', '`O` is `aba`');
assert.same(String(replaceValue), 'c', '`replaceValue` is `c`');
return 'foo';
},
};
assert.same(replaceAll('aba', searcher, 'c'), 'foo');
assert.same(replaceAll('aba', 'b'), 'aundefineda');
assert.same(replaceAll('xxx', '', '_'), '_x_x_x_');
assert.same(replaceAll('121314', '1', '$$'), '$2$3$4', '$$');
assert.same(replaceAll('121314', '1', '$&'), '121314', '$&');
assert.same(replaceAll('121314', '1', '$`'), '212312134', '$`');
assert.same(replaceAll('121314', '1', "$'"), '213142314344', "$'");
const symbol = Symbol('replaceAll test');
assert.throws(() => replaceAll(symbol, 'a', 'b'), 'throws on symbol context');
assert.throws(() => replaceAll('a', symbol, 'b'), 'throws on symbol argument 1');
assert.throws(() => replaceAll('a', 'b', symbol), 'throws on symbol argument 2');
if (STRICT) {
assert.throws(() => replaceAll(null, 'a', 'b'), TypeError);
assert.throws(() => replaceAll(undefined, 'a', 'b'), TypeError);
}
assert.throws(() => replaceAll('b.b.b.b.b', /\./, 'a'), TypeError);
assert.same(replaceAll('b.b.b.b.b', /\./g, 'a'), 'babababab');
const object = {};
assert.same(replaceAll('[object Object]', object, 'a'), 'a');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.small.js
|
JavaScript
|
import small from 'core-js-pure/es/string/small';
QUnit.test('String#small', assert => {
assert.isFunction(small);
assert.same(small('a'), '<small>a</small>', 'lower case');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => small(Symbol('small test')), 'throws on symbol context');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.starts-with.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import startsWith from 'core-js-pure/es/string/starts-with';
QUnit.test('String#startsWith', assert => {
assert.isFunction(startsWith);
assert.true(startsWith('undefined'));
assert.false(startsWith('undefined', null));
assert.true(startsWith('abc', ''));
assert.true(startsWith('abc', 'a'));
assert.true(startsWith('abc', 'ab'));
assert.false(startsWith('abc', 'bc'));
assert.true(startsWith('abc', '', NaN));
assert.true(startsWith('abc', 'a', -1));
assert.false(startsWith('abc', 'a', 1));
assert.false(startsWith('abc', 'a', Infinity));
assert.true(startsWith('abc', 'b', true));
assert.true(startsWith('abc', 'a', 'x'));
if (!Symbol.sham) {
const symbol = Symbol('startsWith test');
assert.throws(() => startsWith(symbol, 'b'), 'throws on symbol context');
assert.throws(() => startsWith('a', symbol), 'throws on symbol argument');
}
if (STRICT) {
assert.throws(() => startsWith(null, '.'), TypeError);
assert.throws(() => startsWith(undefined, '.'), TypeError);
}
const regexp = /./;
assert.throws(() => startsWith('/./', regexp), TypeError);
regexp[Symbol.match] = false;
assert.notThrows(() => startsWith('/./', regexp));
const object = {};
assert.notThrows(() => startsWith('[object Object]', object));
object[Symbol.match] = true;
assert.throws(() => startsWith('[object Object]', object), TypeError);
// side-effect ordering: ToString(searchString) should happen before ToIntegerOrInfinity(position)
const order = [];
startsWith(
'abc',
{ toString() { order.push('search'); return 'a'; } },
{ valueOf() { order.push('pos'); return 0; } },
);
assert.deepEqual(order, ['search', 'pos'], 'ToString(searchString) before ToIntegerOrInfinity(position)');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.strike.js
|
JavaScript
|
import strike from 'core-js-pure/es/string/strike';
QUnit.test('String#strike', assert => {
assert.isFunction(strike);
assert.same(strike('a'), '<strike>a</strike>', 'lower case');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => strike(Symbol('strike test')), 'throws on symbol context');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.sub.js
|
JavaScript
|
import sub from 'core-js-pure/es/string/sub';
QUnit.test('String#sub', assert => {
assert.isFunction(sub);
assert.same(sub('a'), '<sub>a</sub>', 'lower case');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => sub(Symbol('sub test')), 'throws on symbol context');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.substr.js
|
JavaScript
|
import substr from 'core-js-pure/es/string/substr';
import { STRICT } from '../helpers/constants.js';
QUnit.test('String#substr', assert => {
assert.isFunction(substr);
assert.same(substr('12345', 1, 3), '234');
assert.same(substr('ab', -1), 'b');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => substr(Symbol('substr test'), 1, 3), 'throws on symbol context');
}
if (STRICT) {
assert.throws(() => substr(null, 1, 3), TypeError, 'Throws on null as `this`');
assert.throws(() => substr(undefined, 1, 3), TypeError, 'Throws on undefined as `this`');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.sup.js
|
JavaScript
|
import sup from 'core-js-pure/es/string/sup';
QUnit.test('String#sup', assert => {
assert.isFunction(sup);
assert.same(sup('a'), '<sup>a</sup>', 'lower case');
/* eslint-disable es/no-symbol -- safe */
if (typeof Symbol == 'function') {
assert.throws(() => sup(Symbol('sup test')), 'throws on symbol context');
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.to-well-formed.js
|
JavaScript
|
import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import toWellFormed from 'core-js-pure/es/string/virtual/to-well-formed';
QUnit.test('String#toWellFormed', assert => {
assert.isFunction(toWellFormed);
assert.same(toWellFormed.call('a'), 'a', 'a');
assert.same(toWellFormed.call('abc'), 'abc', 'abc');
assert.same(toWellFormed.call('💩'), '💩', '💩');
assert.same(toWellFormed.call('💩b'), '💩b', '💩b');
assert.same(toWellFormed.call('a💩'), 'a💩', '💩');
assert.same(toWellFormed.call('a💩b'), 'a💩b', 'a💩b');
assert.same(toWellFormed.call('💩a💩'), '💩a💩');
assert.same(toWellFormed.call('\uD83D'), '\uFFFD', '\uD83D');
assert.same(toWellFormed.call('\uDCA9'), '\uFFFD', '\uDCA9');
assert.same(toWellFormed.call('\uDCA9\uD83D'), '\uFFFD\uFFFD', '\uDCA9\uD83D');
assert.same(toWellFormed.call('a\uD83D'), 'a\uFFFD', 'a\uFFFD');
assert.same(toWellFormed.call('\uDCA9a'), '\uFFFDa', '\uDCA9a');
assert.same(toWellFormed.call('a\uD83Da'), 'a\uFFFDa', 'a\uD83Da');
assert.same(toWellFormed.call('a\uDCA9a'), 'a\uFFFDa', 'a\uDCA9a');
assert.same(toWellFormed.call({
toString() {
return 'abc';
},
}), 'abc', 'conversion #1');
assert.same(toWellFormed.call(1), '1', 'conversion #2');
if (STRICT) {
assert.throws(() => toWellFormed.call(null), TypeError, 'coercible #1');
assert.throws(() => toWellFormed.call(undefined), TypeError, 'coercible #2');
}
assert.throws(() => toWellFormed.call(Symbol('toWellFormed test')), 'throws on symbol context');
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.trim-end.js
|
JavaScript
|
import { STRICT, WHITESPACES } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import trimEnd from 'core-js-pure/es/string/trim-end';
QUnit.test('String#trimEnd', assert => {
assert.isFunction(trimEnd);
assert.same(trimEnd(' \n q w e \n '), ' \n q w e', 'removes whitespaces at right side of string');
assert.same(trimEnd(WHITESPACES), '', 'removes all whitespaces');
assert.same(trimEnd('\u200B\u0085'), '\u200B\u0085', "shouldn't remove this symbols");
assert.throws(() => trimEnd(Symbol('trimEnd test')), 'throws on symbol context');
if (STRICT) {
assert.throws(() => trimEnd(null, 0), TypeError);
assert.throws(() => trimEnd(undefined, 0), TypeError);
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
| |
tests/unit-pure/es.string.trim-left.js
|
JavaScript
|
import { STRICT, WHITESPACES } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import trimLeft from 'core-js-pure/es/string/trim-left';
QUnit.test('String#trimLeft', assert => {
assert.isFunction(trimLeft);
assert.same(trimLeft(' \n q w e \n '), 'q w e \n ', 'removes whitespaces at left side of string');
assert.same(trimLeft(WHITESPACES), '', 'removes all whitespaces');
assert.same(trimLeft('\u200B\u0085'), '\u200B\u0085', "shouldn't remove this symbols");
assert.throws(() => trimLeft(Symbol('trimLeft test')), 'throws on symbol context');
if (STRICT) {
assert.throws(() => trimLeft(null, 0), TypeError);
assert.throws(() => trimLeft(undefined, 0), TypeError);
}
});
|
zloirock/core-js
| 25,418
|
Standard Library
|
JavaScript
|
zloirock
|
Denis Pushkarev
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.