should produce a syntax error as whitespace results in two tokens
assert.same(parse('"abc"', reviver), 'abc', `15.12.1.1-g2-1 ${ note }`);
assert.throws(() => parse("'abc'", reviver), SyntaxError, `15.12.1.1-g2-2 ${ note }`);
assert.throws(() => parse('\\u0022abc\\u0022', reviver), SyntaxError, `15.12.1.1-g2-3 ${ note }`);
assert.throws(() => parse('"abc\'', reviver), SyntaxError, `15.12.1.1-g2-4 ${ note }`);
assert.same(parse('""', reviver), '', `15.12.1.1-g2-5 ${ note }`);
// invalid string characters should produce a syntax error
assert.throws(() => parse('"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007"', reviver), SyntaxError, `15.12.1.1-g4-1 ${ note }`);
assert.throws(() => parse('"\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f"', reviver), SyntaxError, `15.12.1.1-g4-2 ${ note }`);
assert.throws(() => parse('"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017"', reviver), SyntaxError, `15.12.1.1-g4-3 ${ note }`);
assert.throws(() => parse('"\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f"', reviver), SyntaxError, `15.12.1.1-g4-4 ${ note }`);
assert.same(parse('"\\u0058"', reviver), 'X', `15.12.1.1-g5-1 ${ note }`);
assert.throws(() => parse('"\\u005"', reviver), SyntaxError, `15.12.1.1-g5-2 ${ note }`);
assert.throws(() => parse('"\\u0X50"', reviver), SyntaxError, `15.12.1.1-g5-3 ${ note }`);
assert.same(parse('"\\/"', reviver), '/', `15.12.1.1-g6-1 ${ note }`);
assert.same(parse('"\\\\"', reviver), '\\', `15.12.1.1-g6-2 ${ note }`);
assert.same(parse('"\\b"', reviver), '\b', `15.12.1.1-g6-3 ${ note }`);
assert.same(parse('"\\f"', reviver), '\f', `15.12.1.1-g6-4 ${ note }`);
assert.same(parse('"\\n"', reviver), '\n', `15.12.1.1-g6-5 ${ note }`);
assert.same(parse('"\\r"', reviver), '\r', `15.12.1.1-g6-6 ${ note }`);
assert.same(parse('"\\t"', reviver), '\t', `15.12.1.1-g6-7 ${ note }`);
const nullChars = [
'"\u0000"',
'"\u0001"',
'"\u0002"',
'"\u0003"',
'"\u0004"',
'"\u0005"',
'"\u0006"',
'"\u0007"',
'"\u0008"',
'"\u0009"',
'"\u000A"',
'"\u000B"',
'"\u000C"',
'"\u000D"',
'"\u000E"',
'"\u000F"',
'"\u0010"',
'"\u0011"',
'"\u0012"',
'"\u0013"',
'"\u0014"',
'"\u0015"',
'"\u0016"',
'"\u0017"',
'"\u0018"',
'"\u0019"',
'"\u001A"',
'"\u001B"',
'"\u001C"',
'"\u001D"',
'"\u001E"',
'"\u001F"',
];
for (let i = 0; i < nullChars.length; i++) {
assert.throws(() => parse(`{${ nullChars[i] } : "John" }`, reviver), SyntaxError, `15.12.2-2-1-${ i } ${ note }`);
assert.throws(() => parse(`{${ nullChars[i] }name : "John" }`, reviver), SyntaxError, `15.12.2-2-2-${ i } ${ note }`);
assert.throws(() => parse(`{name${ nullChars[i] } : "John" }`, reviver), SyntaxError, `15.12.2-2-3-${ i } ${ note }`);
assert.throws(() => parse(`{${ nullChars[i] }name${ nullChars[i] } : "John" }`, reviver), SyntaxError, `15.12.2-2-4-${ i } ${ note }`);
assert.throws(() => parse(`{na${ nullChars[i] }me : "John" }`, reviver), SyntaxError, `15.12.2-2-5-${ i } ${ note }`);
assert.throws(() => parse(`{ "name" : ${ nullChars[i] } }`, reviver), SyntaxError, `15.12.2-2-6-${ i } ${ note }`);
assert.throws(() => parse(`{ "name" : ${ nullChars[i] }John }`, reviver), SyntaxError, `15.12.2-2-7-${ i } ${ note }`);
assert.throws(() => parse(`{ "name" : John${ nullChars[i] } }`, reviver), SyntaxError, `15.12.2-2-8-${ i } ${ note }`);
assert.throws(() => parse(`{ "name" : ${ nullChars[i] }John${ nullChars[i] } }`, reviver), SyntaxError, `15.12.2-2-9-${ i } ${ note }`);
assert.throws(() => parse(`{ "name" : Jo${ nullChars[i] }hn }`, reviver), SyntaxError, `15.12.2-2-10-${ i } ${ note }`);
}
if (REDEFINABLE_PROTO) {
// eslint-disable-next-line no-proto -- testing
assert.same(parse('{ "__proto__": 1, "__proto__": 2 }', reviver).__proto__, 2, `duplicate proto ${ note }`);
}
assert.throws(() => parse('\u16801', reviver), SyntaxError, `15.12.1.1-0-7-1 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u180e1', reviver), SyntaxError, `15.12.1.1-0-7-2 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u20001', reviver), SyntaxError, `15.12.1.1-0-7-3 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u20011', reviver), SyntaxError, `15.12.1.1-0-7-4 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u20021', reviver), SyntaxError, `15.12.1.1-0-7-5 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u20031', reviver), SyntaxError, `15.12.1.1-0-7-6 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u20041', reviver), SyntaxError, `15.12.1.1-0-7-7 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u20051', reviver), SyntaxError, `15.12.1.1-0-7-8 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u20061', reviver), SyntaxError, `15.12.1.1-0-7-9 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u20071', reviver), SyntaxError, `15.12.1.1-0-7-10 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u20081', reviver), SyntaxError, `15.12.1.1-0-7-11 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u20091', reviver), SyntaxError, `15.12.1.1-0-7-12 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u200a1', reviver), SyntaxError, `15.12.1.1-0-7-13 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u202f1', reviver), SyntaxError, `15.12.1.1-0-7-14 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u205f1', reviver), SyntaxError, `15.12.1.1-0-7-15 ${ note }`); // invalid whitespace
assert.throws(() => parse('\u30001', reviver), SyntaxError, `15.12.1.1-0-7-16 ${ note }`); // invalid whitespace
assert.same(parse('-0', reviver), -0, `negative-zero-1 ${ note }`);
assert.same(parse(' \n-0', reviver), -0, `negative-zero-2 ${ note }`);
assert.same(parse('-0 \t', reviver), -0, `negative-zero-3 ${ note }`);
assert.same(parse('\n\t -0\n ', reviver), -0, `negative-zero-4 ${ note }`);
assert.same(parse(-0, reviver), 0, `negative-zero-5 ${ note }`);
assert.throws(() => parse(undefined, reviver), SyntaxError, `undefined ${ note }`);
assert.throws(() => parse(Symbol('JSON.parse test'), reviver), TypeError, `symbol ${ note }`);
assert.same(parse(null, reviver), null, `null ${ note }`);
assert.same(parse(false, reviver), false, `false ${ note }`);
assert.same(parse(true, reviver), true, `true ${ note }`);
assert.same(parse(0, reviver), 0, `0 ${ note }`);
assert.same(parse(3.14, reviver), 3.14, `3.14 ${ note }`);
assert.same(parse({
toString() {
return '"string"';
},
valueOf() {
return '"default_or_number"';
},
}, reviver), 'string', `text-object ${ note }`);
assert.throws(() => parse({
toString: null,
valueOf() {
throw new EvalError('t262');
},
}, reviver), EvalError, `text-object-abrupt-1 ${ note }`);
assert.throws(() => parse({
toString() {
throw new EvalError('t262');
},
}, reviver), EvalError, `text-object-abrupt-2 ${ note }`);
}
// eslint-disable-next-line no-extend-native -- testing
Array.prototype[1] = 3;
const arr1 = parse('[1, 2]', function (key, value) {
if (key === '0') delete this[1];
return value;
});
delete Array.prototype[1];
assert.same(arr1[0], 1, 'reviver-array-get-prop-from-prototype-1');
assert.true(hasOwn(arr1, '1'), 'reviver-array-get-prop-from-prototype-2');
assert.same(arr1[1], 3, 'reviver-array-get-prop-from-prototype-3');
// eslint-disable-next-line no-extend-native -- testing
Object.prototype.b = 3;
const obj1 = parse('{"a": 1, "b": 2}', function (key, value) {
if (key === 'a') delete this.b;
return value;
});
delete Object.prototype.b;
assert.same(obj1.a, 1, 'reviver-object-get-prop-from-prototype-1');
assert.true(hasOwn(obj1, 'b'), 'reviver-object-get-prop-from-prototype-2');
assert.same(obj1.b, 3, 'reviver-object-get-prop-from-prototype-3');
if (DESCRIPTORS) {
const arr2 = parse('[1, 2]', function (key, value) {
if (key === '0') defineProperty(this, '1', { configurable: false });
if (key === '1') return 22;
return value;
});
assert.same(arr2[0], 1, 'reviver-array-non-configurable-prop-create-1');
assert.same(arr2[1], 2, 'reviver-array-non-configurable-prop-create-2');
const arr3 = parse('[1, 2]', function (key, value) {
if (key === '0') defineProperty(this, '1', { configurable: false });
if (key === '1') return;
return value;
});
assert.same(arr3[0], 1, 'reviver-array-non-configurable-prop-delete-1');
assert.true(hasOwn(arr3, '1'), 'reviver-array-non-configurable-prop-delete-2');
assert.same(arr3[1], 2, 'reviver-array-non-configurable-prop-delete-3');
const obj2 = parse('{"a": 1, "b": 2}', function (key, value) {
if (key === 'a') defineProperty(this, 'b', { configurable: false });
if (key === 'b') return 22;
return value;
});
assert.same(obj2.a, 1, 'reviver-object-non-configurable-prop-create-1');
assert.same(obj2.b, 2, 'reviver-object-non-configurable-prop-create-2');
const obj3 = parse('{"a": 1, "b": 2}', function (key, value) {
if (key === 'a') defineProperty(this, 'b', { configurable: false });
if (key === 'b') return;
return value;
});
assert.same(obj3.a, 1, 'reviver-object-non-configurable-prop-delete-1');
assert.true(hasOwn(obj3, 'b'), 'reviver-object-non-configurable-prop-delete-2');
assert.same(obj3.b, 2, 'reviver-object-non-configurable-prop-delete-3');
assert.throws(() => parse('[0,0]', function () {
defineProperty(this, '1', { get: () => { throw new EvalError('t262'); } });
}), EvalError, 'reviver-get-name-err');
}
assert.throws(() => parse('0', () => { throw new EvalError('t262'); }), EvalError, 'reviver-call-err');
// FF20- enumeration order issue
if (keys({ k: 1, 2: 3 })[0] === '2') {
const calls = [];
parse('{"p1":0,"p2":0,"p1":0,"2":0,"1":0}', (name, val) => {
calls.push(name);
return val;
});
// The empty string is the _rootName_ in JSON.parse
assert.arrayEqual(calls, ['1', '2', 'p1', 'p2', ''], 'reviver-call-order');
}
assert.throws(() => parse(), SyntaxError, 'no args');
});
QUnit.test('JSON.parse source access', assert => {
const spy = (k, v, { source: $source }) => source = $source;
let source;
parse('1234', spy);
assert.same(source, '1234', '1234');
parse('"1234"', spy);
assert.same(source, '"1234"', '"1234"');
parse('null', spy);
assert.same(source, 'null', 'null');
parse('true', spy);
assert.same(source, 'true', 'true');
parse('false', spy);
assert.same(source, 'false', 'false');
parse('{}', spy);
assert.same(source, undefined, '{}');
parse('[]', spy);
assert.same(source, undefined, '[]');
parse('9007199254740993', spy);
assert.same(source, '9007199254740993', '9007199254740993');
});
core-js-3.33.2/tests/unit-pure/esnext.json.raw-json.js 0000664 0000000 0000000 00000002250 14517762213 0022620 0 ustar 00root root 0000000 0000000 import { FREEZING } from '../helpers/constants.js';
import rawJSON from 'core-js-pure/actual/json/raw-json';
import stringify from 'core-js-pure/actual/json/stringify';
import isFrozen from 'core-js-pure/es/object/is-frozen';
import hasOwn from 'core-js-pure/es/object/has-own';
QUnit.test('JSON.rawJSON', assert => {
assert.isFunction(rawJSON);
assert.arity(rawJSON, 1);
assert.name(rawJSON, 'rawJSON');
const raw = rawJSON(1);
assert.true(hasOwn(raw, 'rawJSON'), 'own rawJSON');
assert.same(raw.rawJSON, '1', 'is string 1');
if (FREEZING) assert.true(isFrozen(raw), 'frozen');
assert.same(stringify(rawJSON('"qwe"')), '"qwe"');
assert.same(stringify(rawJSON('null')), 'null');
assert.same(stringify(rawJSON('true')), 'true');
assert.same(stringify(rawJSON('9007199254740993')), '9007199254740993');
assert.same(stringify({ key: rawJSON('9007199254740993') }), '{"key":9007199254740993}');
assert.same(stringify([rawJSON('9007199254740993')]), '[9007199254740993]');
assert.throws(() => rawJSON('"qwe'), SyntaxError, 'invalid 1');
assert.throws(() => rawJSON({}), SyntaxError, 'invalid 2');
assert.throws(() => rawJSON(''), SyntaxError, 'invalid 3');
});
core-js-3.33.2/tests/unit-pure/esnext.map.delete-all.js 0000664 0000000 0000000 00000002102 14517762213 0022670 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Map from 'core-js-pure/full/map';
QUnit.test('Map#deleteAll', assert => {
const { deleteAll } = Map.prototype;
assert.isFunction(deleteAll);
assert.arity(deleteAll, 0);
assert.nonEnumerable(Map.prototype, 'deleteAll');
let set = new Map([[1, 2], [2, 3], [3, 4]]);
assert.true(set.deleteAll(1, 2));
assert.deepEqual(from(set), [[3, 4]]);
set = new Map([[1, 2], [2, 3], [3, 4]]);
assert.false(set.deleteAll(3, 4));
assert.deepEqual(from(set), [[1, 2], [2, 3]]);
set = new Map([[1, 2], [2, 3], [3, 4]]);
assert.false(set.deleteAll(4, 5));
assert.deepEqual(from(set), [[1, 2], [2, 3], [3, 4]]);
set = new Map([[1, 2], [2, 3], [3, 4]]);
assert.true(set.deleteAll());
assert.deepEqual(from(set), [[1, 2], [2, 3], [3, 4]]);
assert.throws(() => deleteAll.call({ delete() { /* empty */ } }, 1, 2, 3));
assert.throws(() => deleteAll.call({}, 1, 2, 3), TypeError);
assert.throws(() => deleteAll.call(undefined, 1, 2, 3), TypeError);
assert.throws(() => deleteAll.call(null, 1, 2, 3), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.emplace.js 0000664 0000000 0000000 00000003657 14517762213 0022306 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#emplace', assert => {
const { emplace } = Map.prototype;
assert.isFunction(emplace);
assert.arity(emplace, 2);
assert.name(emplace, 'emplace');
assert.nonEnumerable(Map.prototype, 'emplace');
const map = new Map([['a', 2]]);
let handler = {
update(value, key, that) {
assert.same(this, handler, 'correct handler in callback');
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
assert.same(key, 'a', 'correct key in callback');
assert.same(that, map, 'correct map in callback');
return value ** 2;
},
insert() {
assert.avoid();
},
};
assert.same(map.emplace('a', handler), 4, 'returns a correct value');
handler = {
update() {
assert.avoid();
},
insert(key, that) {
assert.same(this, handler, 'correct handler in callback');
assert.same(arguments.length, 2, 'correct number of callback arguments');
assert.same(key, 'b', 'correct key in callback');
assert.same(that, map, 'correct map in callback');
return 3;
},
};
assert.same(map.emplace('b', handler), 3, 'returns a correct value');
assert.same(map.size, 2, 'correct size');
assert.same(map.get('a'), 4, 'correct result #1');
assert.same(map.get('b'), 3, 'correct result #2');
assert.same(new Map([['a', 2]]).emplace('b', { insert: () => 3 }), 3);
assert.same(new Map([['a', 2]]).emplace('a', { update: value => value ** 2 }), 4);
handler = { update() { /* empty */ }, insert() { /* empty */ } };
assert.throws(() => new Map().emplace('a'), TypeError);
assert.throws(() => emplace.call({}, 'a', handler), TypeError);
assert.throws(() => emplace.call([], 'a', handler), TypeError);
assert.throws(() => emplace.call(undefined, 'a', handler), TypeError);
assert.throws(() => emplace.call(null, 'a', handler), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.every.js 0000664 0000000 0000000 00000002523 14517762213 0022021 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#every', assert => {
const { every } = Map.prototype;
assert.isFunction(every);
assert.arity(every, 1);
assert.name(every, 'every');
assert.nonEnumerable(Map.prototype, 'every');
let map = new Map([[9, 1]]);
const context = {};
map.every(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 9, 'correct index in callback');
assert.same(that, map, 'correct link to map in callback');
assert.same(this, context, 'correct callback context');
}, context);
map = new Map([[0, 1], [1, 2], [2, 3]]);
assert.true(map.every(it => typeof it == 'number'));
assert.true(map.every(it => it < 4));
assert.false(map.every(it => it < 3));
assert.false(map.every(it => typeof it == 'string'));
assert.true(map.every(function () {
return +this === 1;
}, 1));
let result = '';
map.every((value, key) => result += key);
assert.same(result, '012');
assert.true(map.every((value, key, that) => that === map));
assert.throws(() => every.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => every.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => every.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.filter.js 0000664 0000000 0000000 00000002377 14517762213 0022163 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Map from 'core-js-pure/full/map';
QUnit.test('Map#filter', assert => {
const { filter } = Map.prototype;
assert.isFunction(filter);
assert.arity(filter, 1);
assert.name(filter, 'filter');
assert.nonEnumerable(Map.prototype, 'filter');
const map = new Map([[1, 2]]);
const context = {};
map.filter(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
assert.same(key, 1, 'correct key in callback');
assert.same(that, map, 'correct link to map in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.deepEqual(from(new Map([
['a', 1],
[1, 2],
['b', 3],
[2, 'q'],
['c', {}],
[3, 4],
['d', true],
[4, 5],
]).filter(it => typeof it == 'number')), [
['a', 1],
[1, 2],
['b', 3],
[3, 4],
[4, 5],
]);
assert.true(new Map().filter(it => it) instanceof Map);
assert.throws(() => filter.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => filter.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => filter.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.find-key.js 0000664 0000000 0000000 00000002003 14517762213 0022366 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#findKey', assert => {
const { findKey } = Map.prototype;
assert.isFunction(findKey);
assert.arity(findKey, 1);
assert.nonEnumerable(Map.prototype, 'findKey');
const set = new Map([[1, 2]]);
const context = {};
set.findKey(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
assert.same(key, 1, 'correct key in callback');
assert.same(that, set, 'correct link to set in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.same(new Map([[1, 2], [2, 3], [3, 4]]).findKey(it => it % 2), 2);
assert.same(new Map().findKey(it => it === 42), undefined);
assert.throws(() => findKey.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => findKey.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => findKey.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.find.js 0000664 0000000 0000000 00000001742 14517762213 0021611 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#find', assert => {
const { find } = Map.prototype;
assert.isFunction(find);
assert.arity(find, 1);
assert.nonEnumerable(Map.prototype, 'find');
const set = new Map([[1, 2]]);
const context = {};
set.find(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
assert.same(key, 1, 'correct key in callback');
assert.same(that, set, 'correct link to set in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.same(new Map([[1, 2], [2, 3], [3, 4]]).find(it => it % 2), 3);
assert.same(new Map().find(it => it === 42), undefined);
assert.throws(() => find.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => find.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => find.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.from.js 0000664 0000000 0000000 00000001755 14517762213 0021640 0 ustar 00root root 0000000 0000000 import { createIterable } from '../helpers/helpers.js';
import toArray from 'core-js-pure/es/array/from';
import Map from 'core-js-pure/full/map';
QUnit.test('Map.from', assert => {
const { from } = Map;
assert.isFunction(from);
assert.arity(from, 1);
assert.true(Map.from() instanceof Map);
assert.deepEqual(toArray(Map.from([])), []);
assert.deepEqual(toArray(Map.from([[1, 2]])), [[1, 2]]);
assert.deepEqual(toArray(Map.from([[1, 2], [2, 3], [1, 4]])), [[1, 4], [2, 3]]);
assert.deepEqual(toArray(Map.from(createIterable([[1, 2], [2, 3], [1, 4]]))), [[1, 4], [2, 3]]);
const pair = [1, 2];
const context = {};
Map.from([pair], function (element, index) {
assert.same(element, pair);
assert.same(index, 0);
assert.same(this, context);
return element;
}, context);
assert.throws(() => from([1, 2]));
let arg = null;
function F(it) {
return arg = it;
}
from.call(F, createIterable([1, 2, 3]), it => it ** 2);
assert.deepEqual(arg, [1, 4, 9]);
});
core-js-3.33.2/tests/unit-pure/esnext.map.group-by.js 0000664 0000000 0000000 00000001507 14517762213 0022434 0 ustar 00root root 0000000 0000000 import { createIterable } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
import Map from 'core-js-pure/full/map';
QUnit.test('Map.groupBy', assert => {
const { groupBy } = Map;
assert.isFunction(groupBy);
assert.arity(groupBy, 2);
assert.name(groupBy, 'groupBy');
assert.true(groupBy([], it => it) instanceof Map);
assert.deepEqual(from(groupBy([], it => it)), []);
assert.deepEqual(from(groupBy([1, 2], it => it ** 2)), [[1, [1]], [4, [2]]]);
assert.deepEqual(from(groupBy([1, 2, 1], it => it ** 2)), [[1, [1, 1]], [4, [2]]]);
assert.deepEqual(from(groupBy(createIterable([1, 2]), it => it ** 2)), [[1, [1]], [4, [2]]]);
const element = {};
groupBy([element], function (it, i) {
assert.same(arguments.length, 2);
assert.same(it, element);
assert.same(i, 0);
});
});
core-js-3.33.2/tests/unit-pure/esnext.map.includes.js 0000664 0000000 0000000 00000001467 14517762213 0022503 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#includes', assert => {
const { includes } = Map.prototype;
assert.isFunction(includes);
assert.name(includes, 'includes');
assert.arity(includes, 1);
assert.nonEnumerable(Map.prototype, 'includes');
const object = {};
const map = new Map([[1, 1], [2, 2], [3, 3], [4, -0], [5, object], [6, NaN]]);
assert.true(map.includes(1));
assert.true(map.includes(-0));
assert.true(map.includes(0));
assert.true(map.includes(object));
assert.false(map.includes(4));
assert.false(map.includes(-0.5));
assert.false(map.includes({}));
assert.true(map.includes(NaN));
assert.throws(() => includes.call({}, 1), TypeError);
assert.throws(() => includes.call(undefined, 1), TypeError);
assert.throws(() => includes.call(null, 1), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.key-by.js 0000664 0000000 0000000 00000001431 14517762213 0022064 0 ustar 00root root 0000000 0000000 import { createIterable } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
import Map from 'core-js-pure/full/map';
QUnit.test('Map.keyBy', assert => {
const { keyBy } = Map;
assert.isFunction(keyBy);
assert.arity(keyBy, 2);
assert.name(keyBy, 'keyBy');
assert.true(Map.keyBy([], it => it) instanceof Map);
assert.deepEqual(from(Map.keyBy([], it => it)), []);
assert.deepEqual(from(Map.keyBy([1, 2], it => it ** 2)), [[1, 1], [4, 2]]);
assert.deepEqual(from(Map.keyBy([1, 2, 1], it => it ** 2)), [[1, 1], [4, 2]]);
assert.deepEqual(from(Map.keyBy(createIterable([1, 2]), it => it ** 2)), [[1, 1], [4, 2]]);
const element = {};
Map.keyBy([element], it => assert.same(it, element));
// assert.throws(() => keyBy([1, 2], it => it));
});
core-js-3.33.2/tests/unit-pure/esnext.map.key-of.js 0000664 0000000 0000000 00000001427 14517762213 0022063 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#keyOf', assert => {
const { keyOf } = Map.prototype;
assert.isFunction(keyOf);
assert.arity(keyOf, 1);
assert.nonEnumerable(Map.prototype, 'keyOf');
const object = {};
const map = new Map([[1, 1], [2, 2], [3, 3], [4, -0], [5, object], [6, NaN]]);
assert.same(map.keyOf(1), 1);
assert.same(map.keyOf(-0), 4);
assert.same(map.keyOf(0), 4);
assert.same(map.keyOf(object), 5);
assert.same(map.keyOf(4), undefined);
assert.same(map.keyOf(-0.5), undefined);
assert.same(map.keyOf({}), undefined);
assert.same(map.keyOf(NaN), undefined);
assert.throws(() => keyOf.call({}, 1), TypeError);
assert.throws(() => keyOf.call(undefined, 1), TypeError);
assert.throws(() => keyOf.call(null, 1), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.map-keys.js 0000664 0000000 0000000 00000002544 14517762213 0022420 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Map from 'core-js-pure/full/map';
QUnit.test('Map#mapKeys', assert => {
const { mapKeys } = Map.prototype;
assert.isFunction(mapKeys);
assert.arity(mapKeys, 1);
assert.name(mapKeys, 'mapKeys');
assert.nonEnumerable(Map.prototype, 'mapKeys');
const map = new Map([[1, 2]]);
const context = {};
map.mapKeys(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
assert.same(key, 1, 'correct key in callback');
assert.same(that, map, 'correct link to map in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.true(new Map().mapKeys(it => it) instanceof Map);
assert.deepEqual(from(new Map([
['a', 1],
[1, 2],
['b', 3],
[2, 'q'],
['c', {}],
[3, 4],
['d', true],
[4, 5],
]).mapKeys((value, key) => `${ key }${ value }`)), [
['a1', 1],
['12', 2],
['b3', 3],
['2q', 'q'],
['c[object Object]', {}],
['34', 4],
['dtrue', true],
['45', 5],
]);
assert.throws(() => mapKeys.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => mapKeys.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => mapKeys.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.map-values.js 0000664 0000000 0000000 00000002600 14517762213 0022735 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Map from 'core-js-pure/full/map';
QUnit.test('Map#mapValues', assert => {
const { mapValues } = Map.prototype;
assert.isFunction(mapValues);
assert.arity(mapValues, 1);
assert.name(mapValues, 'mapValues');
assert.nonEnumerable(Map.prototype, 'mapValues');
const map = new Map([[1, 2]]);
const context = {};
map.mapValues(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
assert.same(key, 1, 'correct key in callback');
assert.same(that, map, 'correct link to map in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.true(new Map().mapValues(it => it) instanceof Map);
assert.deepEqual(from(new Map([
['a', 1],
[1, 2],
['b', 3],
[2, 'q'],
['c', {}],
[3, 4],
['d', true],
[4, 5],
]).mapValues((value, key) => `${ key }${ value }`)), [
['a', 'a1'],
[1, '12'],
['b', 'b3'],
[2, '2q'],
['c', 'c[object Object]'],
[3, '34'],
['d', 'dtrue'],
[4, '45'],
]);
assert.throws(() => mapValues.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => mapValues.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => mapValues.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.merge.js 0000664 0000000 0000000 00000001764 14517762213 0021774 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Map from 'core-js-pure/full/map';
QUnit.test('Map#merge', assert => {
const { merge } = Map.prototype;
assert.isFunction(merge);
assert.arity(merge, 1);
assert.name(merge, 'merge');
assert.nonEnumerable(Map.prototype, 'merge');
const map = new Map([[1, 2]]);
const result = map.merge([[3, 4]]);
assert.same(result, map);
assert.true(result instanceof Map);
assert.deepEqual(from(new Map([[1, 2], [3, 4]]).merge([[5, 6]])), [[1, 2], [3, 4], [5, 6]]);
assert.deepEqual(from(new Map([[1, 2], [3, 4]]).merge([[3, 5], [5, 6]])), [[1, 2], [3, 5], [5, 6]]);
assert.deepEqual(from(new Map([[1, 2], [3, 4]]).merge([])), [[1, 2], [3, 4]]);
assert.deepEqual(from(new Map([[1, 2], [3, 4]]).merge([[3, 5]], [[5, 6]])), [[1, 2], [3, 5], [5, 6]]);
assert.throws(() => merge.call({}, [[1, 2]]), TypeError);
assert.throws(() => merge.call(undefined, [[1, 2]]), TypeError);
assert.throws(() => merge.call(null, [[1, 2]]), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.of.js 0000664 0000000 0000000 00000001003 14517762213 0021263 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Map from 'core-js-pure/full/map';
QUnit.test('Map.of', assert => {
const { of } = Map;
assert.isFunction(of);
assert.arity(of, 0);
assert.true(Map.of() instanceof Map);
assert.deepEqual(from(Map.of([1, 2])), [[1, 2]]);
assert.deepEqual(from(Map.of([1, 2], [2, 3], [1, 4])), [[1, 4], [2, 3]]);
assert.throws(() => of(1));
let arg = null;
function F(it) {
return arg = it;
}
of.call(F, 1, 2, 3);
assert.deepEqual(arg, [1, 2, 3]);
});
core-js-3.33.2/tests/unit-pure/esnext.map.reduce.js 0000664 0000000 0000000 00000003430 14517762213 0022134 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#reduce', assert => {
const { reduce } = Map.prototype;
assert.isFunction(reduce);
assert.arity(reduce, 1);
assert.name(reduce, 'reduce');
assert.nonEnumerable(Map.prototype, 'reduce');
const set = new Map([['a', 1]]);
const accumulator = {};
set.reduce(function (memo, value, key, that) {
assert.same(arguments.length, 4, 'correct number of callback arguments');
assert.same(memo, accumulator, 'correct callback accumulator');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 'a', 'correct index in callback');
assert.same(that, set, 'correct link to set in callback');
}, accumulator);
assert.same(new Map([
['a', 1],
['b', 2],
['c', 3],
]).reduce(((a, b) => a + b), 1), 7, 'works with initial accumulator');
new Map([
['a', 1],
['b', 2],
]).reduce((memo, value, key) => {
assert.same(memo, 1, 'correct default accumulator');
assert.same(value, 2, 'correct start value without initial accumulator');
assert.same(key, 'b', 'correct start index without initial accumulator');
});
assert.same(new Map([
['a', 1],
['b', 2],
['c', 3],
]).reduce((a, b) => a + b), 6, 'works without initial accumulator');
let values = '';
let keys = '';
new Map([
['a', 1],
['b', 2],
['c', 3],
]).reduce((memo, value, key, s) => {
s.delete('b');
values += value;
keys += key;
}, 0);
assert.same(values, '13', 'correct order #1');
assert.same(keys, 'ac', 'correct order #2');
assert.throws(() => reduce.call({}, () => { /* empty */ }, 1), TypeError);
assert.throws(() => reduce.call(undefined, () => { /* empty */ }, 1), TypeError);
assert.throws(() => reduce.call(null, () => { /* empty */ }, 1), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.some.js 0000664 0000000 0000000 00000002540 14517762213 0021631 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#some', assert => {
const { some } = Map.prototype;
assert.isFunction(some);
assert.arity(some, 1);
assert.name(some, 'some');
assert.nonEnumerable(Map.prototype, 'some');
let map = new Map([[9, 1]]);
const context = {};
map.some(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 9, 'correct index in callback');
assert.same(that, map, 'correct link to map in callback');
assert.same(this, context, 'correct callback context');
}, context);
map = new Map([[0, 1], [1, '2'], [2, 3]]);
assert.true(map.some(it => typeof it == 'number'));
assert.true(map.some(it => it < 3));
assert.false(map.some(it => it < 0));
assert.true(map.some(it => typeof it == 'string'));
assert.false(map.some(function () {
return +this !== 1;
}, 1));
let result = '';
map.some((value, key) => {
result += key;
return false;
});
assert.same(result, '012');
assert.true(map.some((value, key, that) => that === map));
assert.throws(() => some.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => some.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => some.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.update-or-insert.js 0000664 0000000 0000000 00000003172 14517762213 0024072 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#updateOrInsert', assert => {
const { updateOrInsert } = Map.prototype;
assert.isFunction(updateOrInsert);
assert.arity(updateOrInsert, 2);
assert.nonEnumerable(Map.prototype, 'updateOrInsert');
const map = new Map([['a', 2]]);
assert.same(map.updateOrInsert('a', function (value) {
assert.same(arguments.length, 1, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
return value ** 2;
}, () => {
assert.avoid();
return 3;
}), 4, 'returns a correct value');
assert.same(map.updateOrInsert('b', value => {
assert.avoid();
return value ** 2;
}, function () {
assert.same(arguments.length, 0, 'correct number of callback arguments');
return 3;
}), 3, 'returns a correct value');
assert.same(map.size, 2, 'correct size');
assert.same(map.get('a'), 4, 'correct result #1');
assert.same(map.get('b'), 3, 'correct result #2');
assert.same(new Map([['a', 2]]).updateOrInsert('b', null, () => 3), 3);
assert.same(new Map([['a', 2]]).updateOrInsert('a', value => value ** 2), 4);
assert.throws(() => new Map().updateOrInsert('a'), TypeError);
assert.throws(() => updateOrInsert.call({}, 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
assert.throws(() => updateOrInsert.call([], 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
assert.throws(() => updateOrInsert.call(undefined, 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
assert.throws(() => updateOrInsert.call(null, 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.update.js 0000664 0000000 0000000 00000003564 14517762213 0022157 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#update', assert => {
const { update } = Map.prototype;
assert.isFunction(update);
assert.arity(update, 2);
assert.name(update, 'update');
assert.nonEnumerable(Map.prototype, 'update');
let map = new Map([[9, 2]]);
assert.same(map.update(9, function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
assert.same(key, 9, 'correct key in callback');
assert.same(that, map, 'correct link to map in callback');
return value * 2;
}), map, 'returns this');
assert.same(map.size, 1, 'correct size');
assert.same(map.get(9), 4, 'correct result');
map = new Map([[4, 5]]);
map.update(9, function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
assert.same(key, 9, 'correct key in callback');
assert.same(that, map, 'correct link to map in callback');
return value * 2;
}, function (key, that) {
assert.same(arguments.length, 2, 'correct number of thunk arguments');
assert.same(key, 9, 'correct key in thunk');
assert.same(that, map, 'correct link to map in thunk');
return 2;
});
assert.same(map.size, 2, 'correct size');
assert.same(map.get(4), 5, 'correct result #1');
assert.same(map.get(9), 4, 'correct result #2');
assert.throws(() => new Map([[9, 2]]).update(9), TypeError);
assert.throws(() => new Map().update(9, () => { /* empty */ }), TypeError);
assert.throws(() => update.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => update.call([], () => { /* empty */ }), TypeError);
assert.throws(() => update.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => update.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.map.upsert.js 0000664 0000000 0000000 00000003012 14517762213 0022203 0 ustar 00root root 0000000 0000000 import Map from 'core-js-pure/full/map';
QUnit.test('Map#upsert', assert => {
const { upsert } = Map.prototype;
assert.isFunction(upsert);
assert.arity(upsert, 2);
assert.nonEnumerable(Map.prototype, 'upsert');
const map = new Map([['a', 2]]);
assert.same(map.upsert('a', function (value) {
assert.same(arguments.length, 1, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
return value ** 2;
}, () => {
assert.avoid();
return 3;
}), 4, 'returns a correct value');
assert.same(map.upsert('b', value => {
assert.avoid();
return value ** 2;
}, function () {
assert.same(arguments.length, 0, 'correct number of callback arguments');
return 3;
}), 3, 'returns a correct value');
assert.same(map.size, 2, 'correct size');
assert.same(map.get('a'), 4, 'correct result #1');
assert.same(map.get('b'), 3, 'correct result #2');
assert.same(new Map([['a', 2]]).upsert('b', null, () => 3), 3);
assert.same(new Map([['a', 2]]).upsert('a', value => value ** 2), 4);
assert.throws(() => new Map().upsert('a'), TypeError);
assert.throws(() => upsert.call({}, 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
assert.throws(() => upsert.call([], 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
assert.throws(() => upsert.call(undefined, 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
assert.throws(() => upsert.call(null, 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.math.clamp.js 0000664 0000000 0000000 00000001621 14517762213 0022135 0 ustar 00root root 0000000 0000000 import { createConversionChecker } from '../helpers/helpers.js';
import clamp from 'core-js-pure/full/math/clamp';
QUnit.test('Math.clamp', assert => {
assert.isFunction(clamp);
assert.arity(clamp, 3);
assert.same(clamp(2, 4, 6), 4);
assert.same(clamp(4, 2, 6), 4);
assert.same(clamp(6, 2, 4), 4);
const checker1 = createConversionChecker(2);
const checker2 = createConversionChecker(4);
const checker3 = createConversionChecker(5);
assert.same(clamp(checker1, checker2, checker3), 4, 'object wrapper');
assert.same(checker1.$valueOf, 1, 'checker1 valueOf calls');
assert.same(checker1.$toString, 0, 'checker1 toString calls');
assert.same(checker2.$valueOf, 1, 'checker2 valueOf calls');
assert.same(checker2.$toString, 0, 'checker2 toString calls');
assert.same(checker3.$valueOf, 1, 'checker3 valueOf calls');
assert.same(checker3.$toString, 0, 'checker3 toString calls');
});
core-js-3.33.2/tests/unit-pure/esnext.math.deg-per-rad.js 0000664 0000000 0000000 00000000255 14517762213 0023132 0 ustar 00root root 0000000 0000000 import DEG_PER_RAD from 'core-js-pure/full/math/deg-per-rad';
QUnit.test('Math.DEG_PER_RAD', assert => {
assert.same(DEG_PER_RAD, Math.PI / 180, 'Is Math.PI / 180');
});
core-js-3.33.2/tests/unit-pure/esnext.math.degrees.js 0000664 0000000 0000000 00000001132 14517762213 0022454 0 ustar 00root root 0000000 0000000 import { createConversionChecker } from '../helpers/helpers.js';
import degrees from 'core-js-pure/full/math/degrees';
QUnit.test('Math.degrees', assert => {
assert.isFunction(degrees);
assert.arity(degrees, 1);
assert.same(degrees(0), 0);
assert.same(degrees(Math.PI / 2), 90);
assert.same(degrees(Math.PI), 180);
assert.same(degrees(3 * Math.PI / 2), 270);
const checker = createConversionChecker(3 * Math.PI / 2);
assert.same(degrees(checker), 270, 'object wrapper');
assert.same(checker.$valueOf, 1, 'valueOf calls');
assert.same(checker.$toString, 0, 'toString calls');
});
core-js-3.33.2/tests/unit-pure/esnext.math.f16round.js 0000664 0000000 0000000 00000003426 14517762213 0022512 0 ustar 00root root 0000000 0000000 // some asserts based on https://github.com/petamoriken/float16/blob/master/test/f16round.js
import { createConversionChecker } from '../helpers/helpers.js';
import f16round from 'core-js-pure/actual/math/f16round';
const { MAX_VALUE, MIN_VALUE } = Number;
QUnit.test('Math.f16round', assert => {
assert.isFunction(f16round);
assert.name(f16round, 'f16round');
assert.arity(f16round, 1);
assert.same(f16round(), NaN);
assert.same(f16round(undefined), NaN);
assert.same(f16round(NaN), NaN);
assert.same(f16round(null), 0);
assert.same(f16round(0), 0);
assert.same(f16round(-0), -0);
assert.same(f16round(MIN_VALUE), 0);
assert.same(f16round(-MIN_VALUE), -0);
assert.same(f16round(Infinity), Infinity);
assert.same(f16round(-Infinity), -Infinity);
assert.same(f16round(MAX_VALUE), Infinity);
assert.same(f16round(-MAX_VALUE), -Infinity);
const MAX_FLOAT16 = 65504;
const MIN_FLOAT16 = 2 ** -24;
assert.same(f16round(MAX_FLOAT16), MAX_FLOAT16);
assert.same(f16round(-MAX_FLOAT16), -MAX_FLOAT16);
assert.same(f16round(MIN_FLOAT16), MIN_FLOAT16);
assert.same(f16round(-MIN_FLOAT16), -MIN_FLOAT16);
assert.same(f16round(MIN_FLOAT16 / 2), 0);
assert.same(f16round(-MIN_FLOAT16 / 2), -0);
assert.same(f16round(2.980232238769531911744490042422139897126953655970282852649688720703125e-8), MIN_FLOAT16);
assert.same(f16round(-2.980232238769531911744490042422139897126953655970282852649688720703125e-8), -MIN_FLOAT16);
assert.same(f16round(1.337), 1.3369140625);
assert.same(f16round(0.499994), 0.5);
assert.same(f16round(7.9999999), 8);
const checker = createConversionChecker(1.1);
assert.same(f16round(checker), 1.099609375, 'object wrapper');
assert.same(checker.$valueOf, 1, 'valueOf calls');
assert.same(checker.$toString, 0, 'toString calls');
});
core-js-3.33.2/tests/unit-pure/esnext.math.fscale.js 0000664 0000000 0000000 00000002521 14517762213 0022276 0 ustar 00root root 0000000 0000000 import { createConversionChecker } from '../helpers/helpers.js';
import fscale from 'core-js-pure/full/math/fscale';
QUnit.test('Math.fscale', assert => {
assert.isFunction(fscale);
assert.arity(fscale, 5);
assert.same(fscale(3, 1, 2, 1, 2), 3);
assert.same(fscale(0, 3, 5, 8, 10), 5);
assert.same(fscale(1, 1, 1, 1, 1), NaN);
assert.same(fscale(-1, -1, -1, -1, -1), NaN);
const checker1 = createConversionChecker(3);
const checker2 = createConversionChecker(1);
const checker3 = createConversionChecker(2);
const checker4 = createConversionChecker(1);
const checker5 = createConversionChecker(2);
assert.same(fscale(checker1, checker2, checker3, checker4, checker5), 3, 'object wrapper');
assert.same(checker1.$valueOf, 1, 'checker1 valueOf calls');
assert.same(checker1.$toString, 0, 'checker1 toString calls');
assert.same(checker2.$valueOf, 1, 'checker2 valueOf calls');
assert.same(checker2.$toString, 0, 'checker2 toString calls');
assert.same(checker3.$valueOf, 1, 'checker3 valueOf calls');
assert.same(checker3.$toString, 0, 'checker3 toString calls');
assert.same(checker4.$valueOf, 1, 'checker4 valueOf calls');
assert.same(checker4.$toString, 0, 'checker4 toString calls');
assert.same(checker5.$valueOf, 1, 'checker5 valueOf calls');
assert.same(checker5.$toString, 0, 'checker5 toString calls');
});
core-js-3.33.2/tests/unit-pure/esnext.math.iaddh.js 0000664 0000000 0000000 00000000535 14517762213 0022115 0 ustar 00root root 0000000 0000000 import iaddh from 'core-js-pure/full/math/iaddh';
QUnit.test('Math.iaddh', assert => {
assert.isFunction(iaddh);
assert.arity(iaddh, 4);
assert.same(iaddh(0, 2, 1, 0), 2);
assert.same(iaddh(0, 4, 1, 1), 5);
assert.same(iaddh(2, 4, 1, 1), 5);
assert.same(iaddh(0xFFFFFFFF, 4, 1, 1), 6);
assert.same(iaddh(1, 4, 0xFFFFFFFF, 1), 6);
});
core-js-3.33.2/tests/unit-pure/esnext.math.imulh.js 0000664 0000000 0000000 00000000443 14517762213 0022160 0 ustar 00root root 0000000 0000000 import imulh from 'core-js-pure/full/math/imulh';
QUnit.test('Math.imulh', assert => {
assert.isFunction(imulh);
assert.arity(imulh, 2);
assert.same(imulh(0xFFFFFFFF, 7), -1);
assert.same(imulh(0xFFFFFFF, 77), 4);
assert.same(imulh(1, 7), 0);
assert.same(imulh(-1, 7), -1);
});
core-js-3.33.2/tests/unit-pure/esnext.math.isubh.js 0000664 0000000 0000000 00000000535 14517762213 0022156 0 ustar 00root root 0000000 0000000 import isubh from 'core-js-pure/full/math/isubh';
QUnit.test('Math.isubh', assert => {
assert.isFunction(isubh);
assert.arity(isubh, 4);
assert.same(isubh(0, 2, 1, 0), 1);
assert.same(isubh(0, 4, 1, 1), 2);
assert.same(isubh(2, 4, 1, 1), 3);
assert.same(isubh(0xFFFFFFFF, 4, 1, 1), 3);
assert.same(isubh(1, 4, 0xFFFFFFFF, 1), 2);
});
core-js-3.33.2/tests/unit-pure/esnext.math.rad-per-deg.js 0000664 0000000 0000000 00000000255 14517762213 0023132 0 ustar 00root root 0000000 0000000 import RAD_PER_DEG from 'core-js-pure/full/math/rad-per-deg';
QUnit.test('Math.RAD_PER_DEG', assert => {
assert.same(RAD_PER_DEG, 180 / Math.PI, 'Is 180 / Math.PI');
});
core-js-3.33.2/tests/unit-pure/esnext.math.radians.js 0000664 0000000 0000000 00000001132 14517762213 0022457 0 ustar 00root root 0000000 0000000 import { createConversionChecker } from '../helpers/helpers.js';
import radians from 'core-js-pure/full/math/radians';
QUnit.test('Math.radians', assert => {
assert.isFunction(radians);
assert.arity(radians, 1);
assert.same(radians(0), 0);
assert.same(radians(90), Math.PI / 2);
assert.same(radians(180), Math.PI);
assert.same(radians(270), 3 * Math.PI / 2);
const checker = createConversionChecker(270);
assert.same(radians(checker), 3 * Math.PI / 2, 'object wrapper');
assert.same(checker.$valueOf, 1, 'valueOf calls');
assert.same(checker.$toString, 0, 'toString calls');
});
core-js-3.33.2/tests/unit-pure/esnext.math.scale.js 0000664 0000000 0000000 00000002507 14517762213 0022134 0 ustar 00root root 0000000 0000000 import { createConversionChecker } from '../helpers/helpers.js';
import scale from 'core-js-pure/full/math/scale';
QUnit.test('Math.scale', assert => {
assert.isFunction(scale);
assert.arity(scale, 5);
assert.same(scale(3, 1, 2, 1, 2), 3);
assert.same(scale(0, 3, 5, 8, 10), 5);
assert.same(scale(1, 1, 1, 1, 1), NaN);
assert.same(scale(-1, -1, -1, -1, -1), NaN);
const checker1 = createConversionChecker(3);
const checker2 = createConversionChecker(1);
const checker3 = createConversionChecker(2);
const checker4 = createConversionChecker(1);
const checker5 = createConversionChecker(2);
assert.same(scale(checker1, checker2, checker3, checker4, checker5), 3, 'object wrapper');
assert.same(checker1.$valueOf, 1, 'checker1 valueOf calls');
assert.same(checker1.$toString, 0, 'checker1 toString calls');
assert.same(checker2.$valueOf, 1, 'checker2 valueOf calls');
assert.same(checker2.$toString, 0, 'checker2 toString calls');
assert.same(checker3.$valueOf, 1, 'checker3 valueOf calls');
assert.same(checker3.$toString, 0, 'checker3 toString calls');
assert.same(checker4.$valueOf, 1, 'checker4 valueOf calls');
assert.same(checker4.$toString, 0, 'checker4 toString calls');
assert.same(checker5.$valueOf, 1, 'checker5 valueOf calls');
assert.same(checker5.$toString, 0, 'checker5 toString calls');
});
core-js-3.33.2/tests/unit-pure/esnext.math.seeded-prng.js 0000664 0000000 0000000 00000002376 14517762213 0023246 0 ustar 00root root 0000000 0000000 import seededPRNG from 'core-js-pure/full/math/seeded-prng';
QUnit.test('Math.seededPRNG', assert => {
assert.isFunction(seededPRNG);
assert.arity(seededPRNG, 1);
for (const gen of [seededPRNG({ seed: 42 }), seededPRNG({ seed: 42 })]) {
assert.deepEqual(gen.next(), { value: 0.16461519912315087, done: false });
assert.deepEqual(gen.next(), { value: 0.2203933906000046, done: false });
assert.deepEqual(gen.next(), { value: 0.8249682894209105, done: false });
assert.deepEqual(gen.next(), { value: 0.10750079537509083, done: false });
assert.deepEqual(gen.next(), { value: 0.004673248161257476, done: false });
}
for (const gen of [seededPRNG({ seed: 43 }), seededPRNG({ seed: 43 })]) {
assert.deepEqual(gen.next(), { value: 0.1923438591811283, done: false });
assert.deepEqual(gen.next(), { value: 0.7896811578326683, done: false });
assert.deepEqual(gen.next(), { value: 0.9518230761883996, done: false });
assert.deepEqual(gen.next(), { value: 0.1414634102410296, done: false });
assert.deepEqual(gen.next(), { value: 0.7379838030207752, done: false });
}
assert.throws(() => seededPRNG(), TypeError);
assert.throws(() => seededPRNG(5), TypeError);
assert.throws(() => seededPRNG({ seed: null }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.math.signbit.js 0000664 0000000 0000000 00000001356 14517762213 0022505 0 ustar 00root root 0000000 0000000 import { createConversionChecker } from '../helpers/helpers.js';
import signbit from 'core-js-pure/full/math/signbit';
QUnit.test('Math.signbit', assert => {
assert.isFunction(signbit);
assert.false(signbit(NaN));
assert.false(signbit());
assert.true(signbit(-0));
assert.false(signbit(0));
assert.false(signbit(Infinity));
assert.true(signbit(-Infinity));
assert.false(signbit(13510798882111488));
assert.true(signbit(-13510798882111488));
assert.false(signbit(42.5));
assert.true(signbit(-42.5));
const checker = createConversionChecker(-13510798882111488);
assert.true(signbit(checker), 'object wrapper');
assert.same(checker.$valueOf, 1, 'valueOf calls');
assert.same(checker.$toString, 0, 'toString calls');
});
core-js-3.33.2/tests/unit-pure/esnext.math.umulh.js 0000664 0000000 0000000 00000000441 14517762213 0022172 0 ustar 00root root 0000000 0000000 import umulh from 'core-js-pure/full/math/umulh';
QUnit.test('Math.umulh', assert => {
assert.isFunction(umulh);
assert.arity(umulh, 2);
assert.same(umulh(0xFFFFFFFF, 7), 6);
assert.same(umulh(0xFFFFFFF, 77), 4);
assert.same(umulh(1, 7), 0);
assert.same(umulh(-1, 7), 6);
});
core-js-3.33.2/tests/unit-pure/esnext.number.from-string.js 0000664 0000000 0000000 00000004423 14517762213 0023652 0 ustar 00root root 0000000 0000000 import fromString from 'core-js-pure/full/number/from-string';
QUnit.test('Number.fromString', assert => {
assert.isFunction(fromString);
assert.name(fromString, 'fromString');
assert.arity(fromString, 2);
assert.throws(() => fromString(undefined), TypeError, 'The first argument should be a string #1');
assert.throws(() => fromString(Object('10')), TypeError, 'The first argument should be a string #1');
assert.throws(() => fromString(''), SyntaxError, 'Empty string');
assert.same(fromString('-10', 2), -2, 'Works with negative numbers');
assert.throws(() => fromString('-'), SyntaxError, '-');
assert.same(fromString('10'), 10, 'Default radix is 10 #1');
assert.same(fromString('10', undefined), 10, 'Default radix is 10 #2');
for (let radix = 2; radix <= 36; ++radix) {
assert.same(fromString('10', radix), radix, `Radix ${ radix }`);
}
assert.throws(() => fromString('10', -4294967294), RangeError, 'Radix uses ToInteger #1');
assert.same(fromString('10', 2.5), 2, 'Radix uses ToInteger #2');
assert.same(fromString('42'), 42);
assert.same(fromString('42', 10), 42);
assert.same(fromString('3.14159', 10), 3.14159);
assert.same(fromString('-100.11', 2), -4.75);
assert.same(fromString('202.1', 3), 20.333333333333332);
assert.same(fromString('0'), 0);
assert.same(fromString('0', 2), 0);
assert.same(fromString('-0'), -0);
assert.same(fromString('-0', 2), -0);
assert.throws(() => fromString('0xc0ffee'), SyntaxError);
assert.throws(() => fromString('0o755'), SyntaxError);
assert.throws(() => fromString('0b00101010'), SyntaxError);
assert.throws(() => fromString('C0FFEE', 16), SyntaxError);
assert.same(fromString('c0ffee', 16), 12648430);
assert.same(fromString('755', 8), 493);
assert.throws(() => fromString(''), SyntaxError);
assert.throws(() => fromString(' '), SyntaxError);
assert.throws(() => fromString(' 1'), SyntaxError);
assert.throws(() => fromString(' \n '), SyntaxError);
assert.throws(() => fromString('x'), SyntaxError);
assert.throws(() => fromString('1234', 0), RangeError);
assert.throws(() => fromString('1234', 1), RangeError);
assert.throws(() => fromString('1234', 37), RangeError);
assert.throws(() => fromString('010'), SyntaxError);
assert.throws(() => fromString('1_000_000_000'), SyntaxError);
});
core-js-3.33.2/tests/unit-pure/esnext.number.range.js 0000664 0000000 0000000 00000004445 14517762213 0022503 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import range from 'core-js-pure/full/number/range';
QUnit.test('range', assert => {
assert.isFunction(range);
assert.name(range, 'range');
assert.arity(range, 3);
let iterator = range(1, 2);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.deepEqual(iterator.next(), {
value: 1,
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
assert.deepEqual(from(range(-1, 5)), [-1, 0, 1, 2, 3, 4]);
assert.deepEqual(from(range(-5, 1)), [-5, -4, -3, -2, -1, 0]);
assert.deepEqual(
from(range(0, 1, 0.1)),
[0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9],
);
assert.deepEqual(
from(range(2 ** 53 - 1, 2 ** 53, { inclusive: true })),
[9007199254740991, 9007199254740992],
);
assert.deepEqual(from(range(0, 0)), []);
assert.deepEqual(from(range(0, -5, 1)), []);
assert.deepEqual(from(range(NaN, 0)), []);
assert.deepEqual(from(range(0, NaN)), []);
assert.deepEqual(from(range(NaN, NaN)), []);
assert.deepEqual(from(range(0, 0, { step: NaN })), []);
assert.deepEqual(from(range(0, 5, NaN)), []);
iterator = range(1, 3);
assert.deepEqual(iterator.start, 1);
assert.deepEqual(iterator.end, 3);
assert.deepEqual(iterator.step, 1);
assert.false(iterator.inclusive);
iterator = range(-1, -3, { inclusive: true });
assert.deepEqual(iterator.start, -1);
assert.deepEqual(iterator.end, -3);
assert.same(iterator.step, -1);
assert.true(iterator.inclusive);
iterator = range(-1, -3, { step: 4, inclusive() { /* empty */ } });
assert.same(iterator.start, -1);
assert.same(iterator.end, -3);
assert.same(iterator.step, 4);
assert.true(iterator.inclusive);
iterator = range(0, 5);
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
assert.throws(() => Object.getOwnPropertyDescriptor(iterator, 'start').get.call({}), TypeError);
assert.throws(() => range(Infinity, 10, 0), RangeError);
assert.throws(() => range(-Infinity, 10, 0), RangeError);
assert.throws(() => range(0, 10, Infinity), RangeError);
assert.throws(() => range(0, 10, { step: Infinity }), RangeError);
assert.throws(() => range({}, 1), TypeError);
assert.throws(() => range(1, {}), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.object.group-by.js 0000664 0000000 0000000 00000001653 14517762213 0023127 0 ustar 00root root 0000000 0000000 import { createIterable } from '../helpers/helpers.js';
import groupBy from 'core-js-pure/actual/object/group-by';
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
import entries from 'core-js-pure/es/object/entries';
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]]]);
const element = {};
groupBy([element], function (it, i) {
assert.same(arguments.length, 2);
assert.same(it, element);
assert.same(i, 0);
});
});
core-js-3.33.2/tests/unit-pure/esnext.object.iterate-entries.js 0000664 0000000 0000000 00000001413 14517762213 0024461 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/es/symbol';
import iterateEntries from 'core-js-pure/full/object/iterate-entries';
QUnit.test('Object.iterateEntries', assert => {
assert.isFunction(iterateEntries);
assert.name(iterateEntries, 'iterateEntries');
assert.arity(iterateEntries, 1);
const object = {
q: 1,
w: 2,
e: 3,
};
const iterator = iterateEntries(object);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Object Iterator');
assert.deepEqual(iterator.next(), {
value: ['q', 1],
done: false,
});
delete object.w;
assert.deepEqual(iterator.next(), {
value: ['e', 3],
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});
core-js-3.33.2/tests/unit-pure/esnext.object.iterate-keys.js 0000664 0000000 0000000 00000001351 14517762213 0023764 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/es/symbol';
import iterateKeys from 'core-js-pure/full/object/iterate-keys';
QUnit.test('Object.iterateKeys', assert => {
assert.isFunction(iterateKeys);
assert.name(iterateKeys, 'iterateKeys');
assert.arity(iterateKeys, 1);
const object = {
q: 1,
w: 2,
e: 3,
};
const iterator = iterateKeys(object);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Object Iterator');
assert.deepEqual(iterator.next(), {
value: 'q',
done: false,
});
delete object.w;
assert.deepEqual(iterator.next(), {
value: 'e',
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});
core-js-3.33.2/tests/unit-pure/esnext.object.iterate-values.js 0000664 0000000 0000000 00000001365 14517762213 0024315 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/es/symbol';
import iterateValues from 'core-js-pure/full/object/iterate-values';
QUnit.test('Object.iterateValues', assert => {
assert.isFunction(iterateValues);
assert.name(iterateValues, 'iterateValues');
assert.arity(iterateValues, 1);
const object = {
q: 1,
w: 2,
e: 3,
};
const iterator = iterateValues(object);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Object Iterator');
assert.deepEqual(iterator.next(), {
value: 1,
done: false,
});
delete object.w;
assert.deepEqual(iterator.next(), {
value: 3,
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});
core-js-3.33.2/tests/unit-pure/esnext.observable.constructor.js 0000664 0000000 0000000 00000003342 14517762213 0024623 0 ustar 00root root 0000000 0000000 import { STRICT } from '../helpers/constants.js';
import Symbol from 'core-js-pure/full/symbol';
import Observable from 'core-js-pure/full/observable';
QUnit.test('Observable', assert => {
assert.isFunction(Observable);
assert.arity(Observable, 1);
assert.throws(() => Observable(() => { /* empty */ }), 'throws w/o `new`');
const observable = new Observable(function (subscriptionObserver) {
assert.same(typeof subscriptionObserver, 'object', 'Subscription observer is object');
assert.same(subscriptionObserver.constructor, Object);
const { next, error, complete } = subscriptionObserver;
assert.isFunction(next);
assert.isFunction(error);
assert.isFunction(complete);
assert.arity(next, 1);
assert.arity(error, 1);
assert.arity(complete, 0);
if (STRICT) {
assert.same(this, undefined, 'correct executor context');
}
});
observable.subscribe({});
assert.true(observable instanceof Observable);
});
QUnit.test('Observable#subscribe', assert => {
assert.isFunction(Observable.prototype.subscribe);
assert.arity(Observable.prototype.subscribe, 1);
const subscription = new Observable(() => { /* empty */ }).subscribe({});
assert.same(typeof subscription, 'object', 'Subscription is object');
assert.same(subscription.constructor, Object);
assert.isFunction(subscription.unsubscribe);
assert.arity(subscription.unsubscribe, 0);
});
QUnit.test('Observable#constructor', assert => {
assert.same(Observable.prototype.constructor, Observable);
});
QUnit.test('Observable#@@observable', assert => {
assert.isFunction(Observable.prototype[Symbol.observable]);
const observable = new Observable(() => { /* empty*/ });
assert.same(observable[Symbol.observable](), observable);
});
core-js-3.33.2/tests/unit-pure/esnext.observable.from.js 0000664 0000000 0000000 00000000260 14517762213 0023175 0 ustar 00root root 0000000 0000000 import Observable from 'core-js-pure/full/observable';
QUnit.test('Observable.from', assert => {
assert.isFunction(Observable.from);
assert.arity(Observable.from, 1);
});
core-js-3.33.2/tests/unit-pure/esnext.observable.of.js 0000664 0000000 0000000 00000000252 14517762213 0022637 0 ustar 00root root 0000000 0000000 import Observable from 'core-js-pure/full/observable';
QUnit.test('Observable.of', assert => {
assert.isFunction(Observable.of);
assert.arity(Observable.of, 0);
});
core-js-3.33.2/tests/unit-pure/esnext.promise.try.js 0000664 0000000 0000000 00000001136 14517762213 0022405 0 ustar 00root root 0000000 0000000 import Promise from 'core-js-pure/full/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, rejected', assert => {
return Promise.try(() => {
throw new Error();
}).then(() => {
assert.avoid();
}, () => {
assert.true(true, 'rejected as expected');
});
});
core-js-3.33.2/tests/unit-pure/esnext.promise.with-resolvers.js 0000664 0000000 0000000 00000003331 14517762213 0024563 0 ustar 00root root 0000000 0000000 import Promise from 'core-js-pure/full/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');
});
});
core-js-3.33.2/tests/unit-pure/esnext.reflect.define-metadata.js 0000664 0000000 0000000 00000000655 14517762213 0024552 0 ustar 00root root 0000000 0000000 import defineMetadata from 'core-js-pure/full/reflect/define-metadata';
QUnit.test('Reflect.defineMetadata', assert => {
assert.isFunction(defineMetadata);
assert.arity(defineMetadata, 3);
assert.throws(() => defineMetadata('key', 'value', undefined, undefined), TypeError);
assert.same(defineMetadata('key', 'value', {}, undefined), undefined);
assert.same(defineMetadata('key', 'value', {}, 'name'), undefined);
});
core-js-3.33.2/tests/unit-pure/esnext.reflect.delete-metadata.js 0000664 0000000 0000000 00000001722 14517762213 0024556 0 ustar 00root root 0000000 0000000 import create from 'core-js-pure/full/object/create';
import defineMetadata from 'core-js-pure/full/reflect/define-metadata';
import hasOwnMetadata from 'core-js-pure/full/reflect/has-own-metadata';
import deleteMetadata from 'core-js-pure/full/reflect/delete-metadata';
QUnit.test('Reflect.deleteMetadata', assert => {
assert.isFunction(deleteMetadata);
assert.arity(deleteMetadata, 2);
assert.throws(() => deleteMetadata('key', undefined, undefined), TypeError);
assert.false(deleteMetadata('key', {}, undefined));
let object = {};
defineMetadata('key', 'value', object, undefined);
assert.true(deleteMetadata('key', object, undefined));
const prototype = {};
defineMetadata('key', 'value', prototype, undefined);
assert.false(deleteMetadata('key', create(prototype), undefined));
object = {};
defineMetadata('key', 'value', object, undefined);
deleteMetadata('key', object, undefined);
assert.false(hasOwnMetadata('key', object, undefined));
});
core-js-3.33.2/tests/unit-pure/esnext.reflect.get-metadata-keys.js 0000664 0000000 0000000 00000004530 14517762213 0025044 0 ustar 00root root 0000000 0000000 import create from 'core-js-pure/full/object/create';
import defineMetadata from 'core-js-pure/full/reflect/define-metadata';
import getMetadataKeys from 'core-js-pure/full/reflect/get-metadata-keys';
QUnit.test('Reflect.getMetadataKeys', assert => {
assert.isFunction(getMetadataKeys);
assert.arity(getMetadataKeys, 1);
assert.throws(() => getMetadataKeys(undefined, undefined), TypeError);
assert.deepEqual(getMetadataKeys({}, undefined), []);
let object = {};
defineMetadata('key', 'value', object, undefined);
assert.deepEqual(getMetadataKeys(object, undefined), ['key']);
let prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, undefined);
assert.deepEqual(getMetadataKeys(object, undefined), ['key']);
object = {};
defineMetadata('key0', 'value', object, undefined);
defineMetadata('key1', 'value', object, undefined);
assert.deepEqual(getMetadataKeys(object, undefined), ['key0', 'key1']);
object = {};
defineMetadata('key0', 'value', object, undefined);
defineMetadata('key1', 'value', object, undefined);
defineMetadata('key0', 'value', object, undefined);
assert.deepEqual(getMetadataKeys(object, undefined), ['key0', 'key1']);
prototype = {};
defineMetadata('key2', 'value', prototype, undefined);
object = create(prototype);
defineMetadata('key0', 'value', object, undefined);
defineMetadata('key1', 'value', object, undefined);
assert.deepEqual(getMetadataKeys(object, undefined), ['key0', 'key1', 'key2']);
object = {};
assert.deepEqual(getMetadataKeys({}, 'name'), []);
object = {};
defineMetadata('key', 'value', object, 'name');
assert.deepEqual(getMetadataKeys(object, 'name'), ['key']);
prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, 'name');
assert.deepEqual(getMetadataKeys(object, 'name'), ['key']);
object = {};
defineMetadata('key0', 'value', object, 'name');
defineMetadata('key1', 'value', object, 'name');
defineMetadata('key0', 'value', object, 'name');
assert.deepEqual(getMetadataKeys(object, 'name'), ['key0', 'key1']);
prototype = {};
defineMetadata('key2', 'value', prototype, 'name');
object = create(prototype);
defineMetadata('key0', 'value', object, 'name');
defineMetadata('key1', 'value', object, 'name');
assert.deepEqual(getMetadataKeys(object, 'name'), ['key0', 'key1', 'key2']);
});
core-js-3.33.2/tests/unit-pure/esnext.reflect.get-metadata.js 0000664 0000000 0000000 00000002110 14517762213 0024063 0 ustar 00root root 0000000 0000000 import create from 'core-js-pure/full/object/create';
import defineMetadata from 'core-js-pure/full/reflect/define-metadata';
import getMetadata from 'core-js-pure/full/reflect/get-metadata';
QUnit.test('Reflect.getMetadata', assert => {
assert.isFunction(getMetadata);
assert.arity(getMetadata, 2);
assert.throws(() => getMetadata('key', undefined, undefined), TypeError);
assert.same(getMetadata('key', {}, undefined), undefined);
let object = {};
defineMetadata('key', 'value', object, undefined);
assert.same(getMetadata('key', object, undefined), 'value');
let prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, undefined);
assert.same(getMetadata('key', object, undefined), 'value');
assert.same(getMetadata('key', {}, 'name'), undefined);
object = {};
defineMetadata('key', 'value', object, 'name');
assert.same(getMetadata('key', object, 'name'), 'value');
prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, 'name');
assert.same(getMetadata('key', object, 'name'), 'value');
});
core-js-3.33.2/tests/unit-pure/esnext.reflect.get-own-matadata.js 0000664 0000000 0000000 00000002161 14517762213 0024666 0 ustar 00root root 0000000 0000000 import create from 'core-js-pure/full/object/create';
import defineMetadata from 'core-js-pure/full/reflect/define-metadata';
import getOwnMetadata from 'core-js-pure/full/reflect/get-own-metadata';
QUnit.test('Reflect.getOwnMetadata', assert => {
assert.isFunction(getOwnMetadata);
assert.arity(getOwnMetadata, 2);
assert.throws(() => getOwnMetadata('key', undefined, undefined), TypeError);
assert.same(getOwnMetadata('key', {}, undefined), undefined);
let object = {};
defineMetadata('key', 'value', object, undefined);
assert.same(getOwnMetadata('key', object, undefined), 'value');
let prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, undefined);
assert.same(getOwnMetadata('key', object, undefined), undefined);
assert.same(getOwnMetadata('key', {}, 'name'), undefined);
object = {};
defineMetadata('key', 'value', object, 'name');
assert.same(getOwnMetadata('key', object, 'name'), 'value');
prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, 'name');
assert.same(getOwnMetadata('key', object, 'name'), undefined);
});
core-js-3.33.2/tests/unit-pure/esnext.reflect.get-own-metadata-keys.js 0000664 0000000 0000000 00000004562 14517762213 0025652 0 ustar 00root root 0000000 0000000 import create from 'core-js-pure/full/object/create';
import defineMetadata from 'core-js-pure/full/reflect/define-metadata';
import getOwnMetadataKeys from 'core-js-pure/full/reflect/get-own-metadata-keys';
QUnit.test('Reflect.getOwnMetadataKeys', assert => {
assert.isFunction(getOwnMetadataKeys);
assert.arity(getOwnMetadataKeys, 1);
assert.throws(() => getOwnMetadataKeys(undefined, undefined), TypeError);
assert.deepEqual(getOwnMetadataKeys({}, undefined), []);
let object = {};
defineMetadata('key', 'value', object, undefined);
assert.deepEqual(getOwnMetadataKeys(object, undefined), ['key']);
let prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, undefined);
assert.deepEqual(getOwnMetadataKeys(object, undefined), []);
object = {};
defineMetadata('key0', 'value', object, undefined);
defineMetadata('key1', 'value', object, undefined);
assert.deepEqual(getOwnMetadataKeys(object, undefined), ['key0', 'key1']);
object = {};
defineMetadata('key0', 'value', object, undefined);
defineMetadata('key1', 'value', object, undefined);
defineMetadata('key0', 'value', object, undefined);
assert.deepEqual(getOwnMetadataKeys(object, undefined), ['key0', 'key1']);
prototype = {};
defineMetadata('key2', 'value', prototype, undefined);
object = create(prototype);
defineMetadata('key0', 'value', object, undefined);
defineMetadata('key1', 'value', object, undefined);
assert.deepEqual(getOwnMetadataKeys(object, undefined), ['key0', 'key1']);
object = {};
assert.deepEqual(getOwnMetadataKeys({}, 'name'), []);
object = {};
defineMetadata('key', 'value', object, 'name');
assert.deepEqual(getOwnMetadataKeys(object, 'name'), ['key']);
prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, 'name');
assert.deepEqual(getOwnMetadataKeys(object, 'name'), []);
object = {};
defineMetadata('key0', 'value', object, 'name');
defineMetadata('key1', 'value', object, 'name');
defineMetadata('key0', 'value', object, 'name');
assert.deepEqual(getOwnMetadataKeys(object, 'name'), ['key0', 'key1']);
prototype = {};
defineMetadata('key2', 'value', prototype, 'name');
object = create(prototype);
defineMetadata('key0', 'value', object, 'name');
defineMetadata('key1', 'value', object, 'name');
assert.deepEqual(getOwnMetadataKeys(object, 'name'), ['key0', 'key1']);
});
core-js-3.33.2/tests/unit-pure/esnext.reflect.has-metadata.js 0000664 0000000 0000000 00000002020 14517762213 0024057 0 ustar 00root root 0000000 0000000 import create from 'core-js-pure/full/object/create';
import defineMetadata from 'core-js-pure/full/reflect/define-metadata';
import hasMetadata from 'core-js-pure/full/reflect/has-metadata';
QUnit.test('Reflect.hasMetadata', assert => {
assert.isFunction(hasMetadata);
assert.arity(hasMetadata, 2);
assert.throws(() => hasMetadata('key', undefined, undefined), TypeError);
assert.false(hasMetadata('key', {}, undefined));
let object = {};
defineMetadata('key', 'value', object, undefined);
assert.true(hasMetadata('key', object, undefined));
let prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, undefined);
assert.true(hasMetadata('key', object, undefined));
assert.false(hasMetadata('key', {}, 'name'));
object = {};
defineMetadata('key', 'value', object, 'name');
assert.true(hasMetadata('key', object, 'name'));
prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, 'name');
assert.true(hasMetadata('key', object, 'name'));
});
core-js-3.33.2/tests/unit-pure/esnext.reflect.has-own-metadata.js 0000664 0000000 0000000 00000002067 14517762213 0024673 0 ustar 00root root 0000000 0000000 import create from 'core-js-pure/full/object/create';
import defineMetadata from 'core-js-pure/full/reflect/define-metadata';
import hasOwnMetadata from 'core-js-pure/full/reflect/has-own-metadata';
QUnit.test('Reflect.hasOwnMetadata', assert => {
assert.isFunction(hasOwnMetadata);
assert.arity(hasOwnMetadata, 2);
assert.throws(() => hasOwnMetadata('key', undefined, undefined), TypeError);
assert.false(hasOwnMetadata('key', {}, undefined));
let object = {};
defineMetadata('key', 'value', object, undefined);
assert.true(hasOwnMetadata('key', object, undefined));
let prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, undefined);
assert.false(hasOwnMetadata('key', object, undefined));
assert.false(hasOwnMetadata('key', {}, 'name'));
object = {};
defineMetadata('key', 'value', object, 'name');
assert.true(hasOwnMetadata('key', object, 'name'));
prototype = {};
object = create(prototype);
defineMetadata('key', 'value', prototype, 'name');
assert.false(hasOwnMetadata('key', object, 'name'));
});
core-js-3.33.2/tests/unit-pure/esnext.reflect.metadata.js 0000664 0000000 0000000 00000001151 14517762213 0023312 0 ustar 00root root 0000000 0000000 import hasOwnMetadata from 'core-js-pure/full/reflect/has-own-metadata';
import metadata from 'core-js-pure/full/reflect/metadata';
QUnit.test('Reflect.metadata', assert => {
assert.isFunction(metadata);
assert.arity(metadata, 2);
assert.isFunction(metadata('key', 'value'));
const decorator = metadata('key', 'value');
assert.throws(() => decorator(undefined, 'name'), TypeError);
let target = function () { /* empty */ };
decorator(target);
assert.true(hasOwnMetadata('key', target, undefined));
target = {};
decorator(target, 'name');
assert.true(hasOwnMetadata('key', target, 'name'));
});
core-js-3.33.2/tests/unit-pure/esnext.regexp.escape.js 0000664 0000000 0000000 00000001733 14517762213 0022646 0 ustar 00root root 0000000 0000000 import escape from 'core-js-pure/full/regexp/escape';
import Symbol from 'core-js-pure/es/symbol';
import { createConversionChecker } from '../helpers/helpers.js';
QUnit.test('RegExp.escape', assert => {
assert.isFunction(escape);
assert.arity(escape, 1);
assert.name(escape, 'escape');
assert.same(escape('10$'), '\\x310\\$', '10$');
assert.same(escape('abcdefg_123456'), 'abcdefg_123456', 'abcdefg_123456');
assert.same(
escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`'),
'\\(\\)\\{\\}\\[\\]\\|\\,\\.\\?\\*\\+\\-\\^\\$\\=\\<\\>\\\\\\/\\#\\&\\!\\%\\:\\;\\@\\~\\\'\\"\\`',
'(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`',
);
const checker = createConversionChecker('10$');
assert.same(escape(checker), '\\x310\\$', 'checker result');
assert.same(checker.$valueOf, 0, 'checker valueOf calls');
assert.same(checker.$toString, 1, 'checker toString calls');
if (!Symbol.sham) {
assert.throws(() => escape(Symbol('thrower')), TypeError, 'throws on symbol');
}
});
core-js-3.33.2/tests/unit-pure/esnext.set.add-all.js 0000664 0000000 0000000 00000001517 14517762213 0022205 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Set from 'core-js-pure/full/set';
QUnit.test('Set#addAll', assert => {
const { addAll } = Set.prototype;
assert.isFunction(addAll);
assert.arity(addAll, 0);
assert.name(addAll, 'addAll');
assert.nonEnumerable(Set.prototype, 'addAll');
const set = new Set([1]);
assert.same(set.addAll(2), set);
assert.deepEqual(from(new Set([1, 2, 3]).addAll(4, 5)), [1, 2, 3, 4, 5]);
assert.deepEqual(from(new Set([1, 2, 3]).addAll(3, 4)), [1, 2, 3, 4]);
assert.deepEqual(from(new Set([1, 2, 3]).addAll()), [1, 2, 3]);
assert.throws(() => addAll.call({ add() { /* empty */ } }, 1, 2, 3));
assert.throws(() => addAll.call({}, 1, 2, 3), TypeError);
assert.throws(() => addAll.call(undefined, 1, 2, 3), TypeError);
assert.throws(() => addAll.call(null, 1, 2, 3), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.set.delete-all.js 0000664 0000000 0000000 00000002000 14517762213 0022703 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Set from 'core-js-pure/full/set';
QUnit.test('Set#deleteAll', assert => {
const { deleteAll } = Set.prototype;
assert.isFunction(deleteAll);
assert.arity(deleteAll, 0);
assert.name(deleteAll, 'deleteAll');
assert.nonEnumerable(Set.prototype, 'deleteAll');
let set = new Set([1, 2, 3]);
assert.true(set.deleteAll(1, 2));
assert.deepEqual(from(set), [3]);
set = new Set([1, 2, 3]);
assert.false(set.deleteAll(3, 4));
assert.deepEqual(from(set), [1, 2]);
set = new Set([1, 2, 3]);
assert.false(set.deleteAll(4, 5));
assert.deepEqual(from(set), [1, 2, 3]);
set = new Set([1, 2, 3]);
assert.true(set.deleteAll());
assert.deepEqual(from(set), [1, 2, 3]);
assert.throws(() => deleteAll.call({ delete() { /* empty */ } }, 1, 2, 3));
assert.throws(() => deleteAll.call({}, 1, 2, 3), TypeError);
assert.throws(() => deleteAll.call(undefined, 1, 2, 3), TypeError);
assert.throws(() => deleteAll.call(null, 1, 2, 3), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.set.difference.js 0000664 0000000 0000000 00000002536 14517762213 0023003 0 ustar 00root root 0000000 0000000 import { createIterable, createSetLike } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
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.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);
});
core-js-3.33.2/tests/unit-pure/esnext.set.every.js 0000664 0000000 0000000 00000002232 14517762213 0022034 0 ustar 00root root 0000000 0000000 import Set from 'core-js-pure/full/set';
QUnit.test('Set#every', assert => {
const { every } = Set.prototype;
assert.isFunction(every);
assert.arity(every, 1);
assert.name(every, 'every');
assert.nonEnumerable(Set.prototype, 'every');
const set = new Set([1]);
const context = {};
set.every(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 1, 'correct key in callback');
assert.same(that, set, 'correct link to set in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.true(new Set([1, 2, 3]).every(it => typeof it == 'number'));
assert.false(new Set(['1', '2', '3']).some(it => typeof it == 'number'));
assert.false(new Set([1, '2', 3]).every(it => typeof it == 'number'));
assert.true(new Set().every(it => typeof it == 'number'));
assert.throws(() => every.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => every.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => every.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.set.filter.js 0000664 0000000 0000000 00000002157 14517762213 0022175 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Set from 'core-js-pure/full/set';
QUnit.test('Set#filter', assert => {
const { filter } = Set.prototype;
assert.isFunction(filter);
assert.arity(filter, 1);
assert.name(filter, 'filter');
assert.nonEnumerable(Set.prototype, 'filter');
const set = new Set([1]);
const context = {};
set.filter(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 1, 'correct key in callback');
assert.same(that, set, 'correct link to set in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.true(new Set().filter(it => it) instanceof Set);
assert.deepEqual(from(new Set([1, 2, 3, 'q', {}, 4, true, 5]).filter(it => typeof it == 'number')), [1, 2, 3, 4, 5]);
assert.throws(() => filter.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => filter.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => filter.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.set.find.js 0000664 0000000 0000000 00000001753 14517762213 0021631 0 ustar 00root root 0000000 0000000 import Set from 'core-js-pure/full/set';
QUnit.test('Set#find', assert => {
const { find } = Set.prototype;
assert.isFunction(find);
assert.arity(find, 1);
assert.name(find, 'find');
assert.nonEnumerable(Set.prototype, 'find');
const set = new Set([1]);
const context = {};
set.find(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 1, 'correct key in callback');
assert.same(that, set, 'correct link to set in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.same(new Set([2, 3, 4]).find(it => it % 2), 3);
assert.same(new Set().find(it => it === 42), undefined);
assert.throws(() => find.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => find.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => find.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.set.from.js 0000664 0000000 0000000 00000001641 14517762213 0021650 0 ustar 00root root 0000000 0000000 import { createIterable } from '../helpers/helpers.js';
import toArray from 'core-js-pure/es/array/from';
import Set from 'core-js-pure/full/set';
QUnit.test('Set.from', assert => {
const { from } = Set;
assert.isFunction(from);
assert.arity(from, 1);
assert.true(Set.from() instanceof Set);
assert.deepEqual(toArray(Set.from([])), []);
assert.deepEqual(toArray(Set.from([1])), [1]);
assert.deepEqual(toArray(Set.from([1, 2, 3, 2, 1])), [1, 2, 3]);
assert.deepEqual(toArray(Set.from(createIterable([1, 2, 3, 2, 1]))), [1, 2, 3]);
const context = {};
Set.from([1], function (element, index) {
assert.same(element, 1);
assert.same(index, 0);
assert.same(this, context);
return element;
}, context);
assert.throws(() => from(1));
let arg = null;
function F(it) {
return arg = it;
}
from.call(F, createIterable([1, 2, 3]), it => it ** 2);
assert.deepEqual(arg, [1, 4, 9]);
});
core-js-3.33.2/tests/unit-pure/esnext.set.intersection.js 0000664 0000000 0000000 00000003647 14517762213 0023423 0 ustar 00root root 0000000 0000000 import { createIterable, createSetLike } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
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.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);
});
core-js-3.33.2/tests/unit-pure/esnext.set.is-disjoint-from.js 0000664 0000000 0000000 00000003103 14517762213 0024075 0 ustar 00root root 0000000 0000000 import { createIterable, createSetLike } from '../helpers/helpers.js';
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.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);
});
core-js-3.33.2/tests/unit-pure/esnext.set.is-subset-of.js 0000664 0000000 0000000 00000003052 14517762213 0023223 0 ustar 00root root 0000000 0000000 import { createIterable, createSetLike } from '../helpers/helpers.js';
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.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);
});
core-js-3.33.2/tests/unit-pure/esnext.set.is-superset-of.js 0000664 0000000 0000000 00000003134 14517762213 0023571 0 ustar 00root root 0000000 0000000 import { createIterable, createSetLike } from '../helpers/helpers.js';
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.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);
});
core-js-3.33.2/tests/unit-pure/esnext.set.join.js 0000664 0000000 0000000 00000001211 14517762213 0021635 0 ustar 00root root 0000000 0000000 /* eslint-disable unicorn/require-array-join-separator -- required for testing */
import Set from 'core-js-pure/full/set';
QUnit.test('Set#join', assert => {
const { join } = Set.prototype;
assert.isFunction(join);
assert.arity(join, 1);
assert.name(join, 'join');
assert.nonEnumerable(Set.prototype, 'join');
assert.same(new Set([1, 2, 3]).join(), '1,2,3');
assert.same(new Set([1, 2, 3]).join(undefined), '1,2,3');
assert.same(new Set([1, 2, 3]).join('|'), '1|2|3');
assert.throws(() => join.call({}), TypeError);
assert.throws(() => join.call(undefined), TypeError);
assert.throws(() => join.call(null), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.set.map.js 0000664 0000000 0000000 00000002147 14517762213 0021464 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Set from 'core-js-pure/full/set';
QUnit.test('Set#map', assert => {
const { map } = Set.prototype;
assert.isFunction(map);
assert.arity(map, 1);
assert.name(map, 'map');
assert.nonEnumerable(Set.prototype, 'map');
const set = new Set([1]);
const context = {};
set.map(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 1, 'correct key in callback');
assert.same(that, set, 'correct link to set in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.true(new Set().map(it => it) instanceof Set);
assert.deepEqual(from(new Set([1, 2, 3]).map(it => it ** 2)), [1, 4, 9]);
assert.deepEqual(from(new Set([1, 2, 3]).map(it => it % 2)), [1, 0]);
assert.throws(() => map.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => map.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => map.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.set.of.js 0000664 0000000 0000000 00000000751 14517762213 0021312 0 ustar 00root root 0000000 0000000 import from from 'core-js-pure/es/array/from';
import Set from 'core-js-pure/full/set';
QUnit.test('Set.of', assert => {
const { of } = Set;
assert.isFunction(of);
assert.arity(of, 0);
assert.true(Set.of() instanceof Set);
assert.deepEqual(from(Set.of(1)), [1]);
assert.deepEqual(from(Set.of(1, 2, 3, 2, 1)), [1, 2, 3]);
assert.throws(() => of(1));
let arg = null;
function F(it) {
return arg = it;
}
of.call(F, 1, 2, 3);
assert.deepEqual(arg, [1, 2, 3]);
});
core-js-3.33.2/tests/unit-pure/esnext.set.reduce.js 0000664 0000000 0000000 00000003176 14517762213 0022161 0 ustar 00root root 0000000 0000000 import Set from 'core-js-pure/full/set';
QUnit.test('Set#reduce', assert => {
const { reduce } = Set.prototype;
assert.isFunction(reduce);
assert.arity(reduce, 1);
assert.name(reduce, 'reduce');
assert.nonEnumerable(Set.prototype, 'reduce');
const set = new Set([1]);
const accumulator = {};
set.reduce(function (memo, value, key, that) {
assert.same(arguments.length, 4, 'correct number of callback arguments');
assert.same(memo, accumulator, 'correct callback accumulator');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 1, 'correct index in callback');
assert.same(that, set, 'correct link to set in callback');
}, accumulator);
assert.same(new Set([1, 2, 3]).reduce(((a, b) => a + b), 1), 7, 'works with initial accumulator');
new Set([1, 2]).reduce((memo, value, key) => {
assert.same(memo, 1, 'correct default accumulator');
assert.same(value, 2, 'correct start value without initial accumulator');
assert.same(key, 2, 'correct start index without initial accumulator');
});
assert.same(new Set([1, 2, 3]).reduce((a, b) => a + b), 6, 'works without initial accumulator');
let values = '';
let keys = '';
new Set([1, 2, 3]).reduce((memo, value, key, s) => {
s.delete(2);
values += value;
keys += key;
}, 0);
assert.same(values, '13', 'correct order #1');
assert.same(keys, '13', 'correct order #2');
assert.throws(() => reduce.call({}, () => { /* empty */ }, 1), TypeError);
assert.throws(() => reduce.call(undefined, () => { /* empty */ }, 1), TypeError);
assert.throws(() => reduce.call(null, () => { /* empty */ }, 1), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.set.some.js 0000664 0000000 0000000 00000002214 14517762213 0021645 0 ustar 00root root 0000000 0000000 import Set from 'core-js-pure/full/set';
QUnit.test('Set#some', assert => {
const { some } = Set.prototype;
assert.isFunction(some);
assert.arity(some, 1);
assert.name(some, 'some');
assert.nonEnumerable(Set.prototype, 'some');
const set = new Set([1]);
const context = {};
set.some(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 1, 'correct key in callback');
assert.same(that, set, 'correct link to set in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.true(new Set([1, 2, 3]).some(it => typeof it == 'number'));
assert.false(new Set(['1', '2', '3']).some(it => typeof it == 'number'));
assert.true(new Set([1, '2', 3]).some(it => typeof it == 'number'));
assert.false(new Set().some(it => typeof it == 'number'));
assert.throws(() => some.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => some.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => some.call(null, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.set.symmetric-difference.js 0000664 0000000 0000000 00000003225 14517762213 0025011 0 ustar 00root root 0000000 0000000 import { createIterable, createSetLike } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
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);
});
core-js-3.33.2/tests/unit-pure/esnext.set.union.js 0000664 0000000 0000000 00000002454 14517762213 0022040 0 ustar 00root root 0000000 0000000 import { createIterable, createSetLike } from '../helpers/helpers.js';
import from from 'core-js-pure/es/array/from';
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);
});
core-js-3.33.2/tests/unit-pure/esnext.string.at.js 0000664 0000000 0000000 00000010126 14517762213 0022022 0 ustar 00root root 0000000 0000000 import { STRICT } from '../helpers/constants.js';
import at from 'core-js-pure/full/string/at';
QUnit.test('String#at', assert => {
assert.isFunction(at);
// String that starts with a BMP symbol
// assert.same(at('abc\uD834\uDF06def', -Infinity), '');
// assert.same(at('abc\uD834\uDF06def', -1), '');
assert.same(at('abc\uD834\uDF06def', -0), 'a');
assert.same(at('abc\uD834\uDF06def', +0), 'a');
assert.same(at('abc\uD834\uDF06def', 1), 'b');
assert.same(at('abc\uD834\uDF06def', 3), '\uD834\uDF06');
assert.same(at('abc\uD834\uDF06def', 4), '\uDF06');
assert.same(at('abc\uD834\uDF06def', 5), 'd');
// assert.same(at('abc\uD834\uDF06def', 42), '');
// assert.same(at('abc\uD834\uDF06def', Infinity), '');
assert.same(at('abc\uD834\uDF06def', null), 'a');
assert.same(at('abc\uD834\uDF06def', undefined), 'a');
assert.same(at('abc\uD834\uDF06def'), 'a');
assert.same(at('abc\uD834\uDF06def', false), 'a');
assert.same(at('abc\uD834\uDF06def', NaN), 'a');
assert.same(at('abc\uD834\uDF06def', ''), 'a');
assert.same(at('abc\uD834\uDF06def', '_'), 'a');
assert.same(at('abc\uD834\uDF06def', '1'), 'b');
assert.same(at('abc\uD834\uDF06def', []), 'a');
assert.same(at('abc\uD834\uDF06def', {}), 'a');
assert.same(at('abc\uD834\uDF06def', -0.9), 'a');
assert.same(at('abc\uD834\uDF06def', 1.9), 'b');
assert.same(at('abc\uD834\uDF06def', 7.9), 'f');
// assert.same(at('abc\uD834\uDF06def', 2 ** 32), '');
// String that starts with an astral symbol
// assert.same(at('\uD834\uDF06def', -Infinity), '');
// assert.same(at('\uD834\uDF06def', -1), '');
assert.same(at('\uD834\uDF06def', -0), '\uD834\uDF06');
assert.same(at('\uD834\uDF06def', 0), '\uD834\uDF06');
assert.same(at('\uD834\uDF06def', 1), '\uDF06');
assert.same(at('\uD834\uDF06def', 2), 'd');
assert.same(at('\uD834\uDF06def', 3), 'e');
assert.same(at('\uD834\uDF06def', 4), 'f');
// assert.same(at('\uD834\uDF06def', 42), '');
// assert.same(at('\uD834\uDF06def', Infinity), '');
assert.same(at('\uD834\uDF06def', null), '\uD834\uDF06');
assert.same(at('\uD834\uDF06def', undefined), '\uD834\uDF06');
assert.same(at('\uD834\uDF06def'), '\uD834\uDF06');
assert.same(at('\uD834\uDF06def', false), '\uD834\uDF06');
assert.same(at('\uD834\uDF06def', NaN), '\uD834\uDF06');
assert.same(at('\uD834\uDF06def', ''), '\uD834\uDF06');
assert.same(at('\uD834\uDF06def', '_'), '\uD834\uDF06');
assert.same(at('\uD834\uDF06def', '1'), '\uDF06');
// Lone high surrogates
// assert.same(at('\uD834abc', -Infinity), '');
// assert.same(at('\uD834abc', -1), '');
assert.same(at('\uD834abc', -0), '\uD834');
assert.same(at('\uD834abc', 0), '\uD834');
assert.same(at('\uD834abc', 1), 'a');
// assert.same(at('\uD834abc', 42), '');
// assert.same(at('\uD834abc', Infinity), '');
assert.same(at('\uD834abc', null), '\uD834');
assert.same(at('\uD834abc', undefined), '\uD834');
assert.same(at('\uD834abc'), '\uD834');
assert.same(at('\uD834abc', false), '\uD834');
assert.same(at('\uD834abc', NaN), '\uD834');
assert.same(at('\uD834abc', ''), '\uD834');
assert.same(at('\uD834abc', '_'), '\uD834');
assert.same(at('\uD834abc', '1'), 'a');
// Lone low surrogates
// assert.same(at('\uDF06abc', -Infinity), '');
// assert.same(at('\uDF06abc', -1), '');
assert.same(at('\uDF06abc', -0), '\uDF06');
assert.same(at('\uDF06abc', 0), '\uDF06');
assert.same(at('\uDF06abc', 1), 'a');
// assert.same(at('\uDF06abc', 42), '');
// assert.same(at('\uDF06abc', Infinity), '');
assert.same(at('\uDF06abc', null), '\uDF06');
assert.same(at('\uDF06abc', undefined), '\uDF06');
assert.same(at('\uDF06abc'), '\uDF06');
assert.same(at('\uDF06abc', false), '\uDF06');
assert.same(at('\uDF06abc', NaN), '\uDF06');
assert.same(at('\uDF06abc', ''), '\uDF06');
assert.same(at('\uDF06abc', '_'), '\uDF06');
assert.same(at('\uDF06abc', '1'), 'a');
assert.same(at(42, 0), '4');
assert.same(at(42, 1), '2');
assert.same(at({
toString() {
return 'abc';
},
}, 2), 'c');
if (STRICT) {
assert.throws(() => at(null, 0), TypeError);
assert.throws(() => at(undefined, 0), TypeError);
}
});
core-js-3.33.2/tests/unit-pure/esnext.string.code-points.js 0000664 0000000 0000000 00000002463 14517762213 0023647 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/es/symbol';
import codePoints from 'core-js-pure/full/string/code-points';
QUnit.test('String#codePoints', assert => {
assert.isFunction(codePoints);
let iterator = codePoints('qwe');
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'String Iterator');
assert.same(String(iterator), '[object String Iterator]');
assert.deepEqual(iterator.next(), {
value: { codePoint: 113, position: 0 },
done: false,
});
assert.deepEqual(iterator.next(), {
value: { codePoint: 119, position: 1 },
done: false,
});
assert.deepEqual(iterator.next(), {
value: { codePoint: 101, position: 2 },
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
iterator = codePoints('𠮷𠮷𠮷');
assert.deepEqual(iterator.next(), {
value: { codePoint: 134071, position: 0 },
done: false,
});
assert.deepEqual(iterator.next(), {
value: { codePoint: 134071, position: 2 },
done: false,
});
assert.deepEqual(iterator.next(), {
value: { codePoint: 134071, position: 4 },
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
assert.throws(() => codePoints(Symbol()), 'throws on symbol context');
});
core-js-3.33.2/tests/unit-pure/esnext.string.cooked.js 0000664 0000000 0000000 00000001545 14517762213 0022667 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/es/symbol';
import cooked from 'core-js-pure/full/string/cooked';
QUnit.test('String.cooked', assert => {
assert.isFunction(cooked);
assert.arity(cooked, 1);
assert.name(cooked, 'cooked');
assert.same(cooked(['Hi\\n', '!'], 'Bob'), 'Hi\\nBob!', 'template is an array');
assert.same(cooked('test', 0, 1, 2), 't0e1s2t', 'template is a string');
assert.same(cooked('test', 0), 't0est', 'lacks substituting');
assert.same(cooked([]), '', 'empty template');
if (typeof Symbol == 'function' && !Symbol.sham) {
const symbol = Symbol('cooked test');
assert.throws(() => cooked([symbol]), TypeError, 'throws on symbol #1');
assert.throws(() => cooked('test', symbol), TypeError, 'throws on symbol #2');
}
assert.throws(() => cooked([undefined]), TypeError);
assert.throws(() => cooked(null), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.string.dedent.js 0000664 0000000 0000000 00000003163 14517762213 0022664 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/es/symbol';
import cooked from 'core-js-pure/full/string/cooked';
import dedent from 'core-js-pure/full/string/dedent';
import freeze from 'core-js-pure/es/object/freeze';
QUnit.test('String.dedent', assert => {
assert.isFunction(dedent);
assert.arity(dedent, 1);
assert.name(dedent, 'dedent');
assert.same(dedent`
qwe
asd
zxc
`, 'qwe\nasd\nzxc', '#1');
assert.same(dedent`
qwe
asd
zxc
`, ' qwe\nasd\n zxc', '#2');
assert.same(dedent`
qwe
asd
${ ' zxc' }
`, ' qwe\n asd\n zxc', '#3');
assert.same(dedent({ raw: freeze(['\n qwe\n ']) }), 'qwe', '#4');
assert.same(dedent({ raw: freeze(['\n qwe', '\n ']) }, 1), 'qwe1', '#5');
assert.same(dedent(cooked)`
qwe
asd
zxc
`, ' qwe\nasd\n zxc', '#6');
const tag = (it => it)`
abc
`;
assert.same(dedent(tag), dedent(tag), '#7');
if (typeof Symbol == 'function' && !Symbol.sham) {
assert.throws(() => dedent({ raw: freeze(['\n', Symbol('dedent test'), '\n']) }), TypeError, 'throws on symbol');
}
assert.throws(() => dedent([]), TypeError, '[]');
assert.throws(() => dedent(['qwe']), TypeError, '[qwe]');
assert.throws(() => dedent({ raw: freeze([]) }), TypeError, 'empty tpl');
assert.throws(() => dedent({ raw: freeze(['qwe']) }), TypeError, 'wrong start');
assert.throws(() => dedent({ raw: freeze(['\n', 'qwe']) }), TypeError, 'wrong start');
assert.throws(() => dedent({ raw: freeze(['\n qwe', 5, '\n ']) }, 1, 2), TypeError, 'wrong part');
assert.throws(() => dedent([undefined]), TypeError);
assert.throws(() => dedent(null), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.suppressed-error.constructor.js 0000664 0000000 0000000 00000003702 14517762213 0026023 0 ustar 00root root 0000000 0000000 import SuppressedError from 'core-js-pure/actual/suppressed-error';
import Symbol from 'core-js-pure/es/symbol';
import toString from 'core-js-pure/es/object/to-string';
QUnit.test('SuppressedError', assert => {
assert.isFunction(SuppressedError);
assert.arity(SuppressedError, 3);
assert.name(SuppressedError, 'SuppressedError');
assert.true(new SuppressedError() instanceof SuppressedError);
assert.true(new SuppressedError() instanceof Error);
assert.true(SuppressedError() instanceof SuppressedError);
assert.true(SuppressedError() instanceof Error);
assert.same(SuppressedError().error, undefined);
assert.same(SuppressedError().suppressed, undefined);
assert.same(SuppressedError().message, '');
assert.same(SuppressedError().cause, undefined);
assert.same(SuppressedError().name, 'SuppressedError');
assert.same(new SuppressedError().error, undefined);
assert.same(new SuppressedError().suppressed, undefined);
assert.same(new SuppressedError().message, '');
assert.same(new SuppressedError().cause, undefined);
assert.same(new SuppressedError().name, 'SuppressedError');
const error1 = SuppressedError(1, 2, 3, { cause: 4 });
assert.same(error1.error, 1);
assert.same(error1.suppressed, 2);
assert.same(error1.message, '3');
assert.same(error1.cause, undefined);
assert.same(error1.name, 'SuppressedError');
const error2 = new SuppressedError(1, 2, 3, { cause: 4 });
assert.same(error2.error, 1);
assert.same(error2.suppressed, 2);
assert.same(error2.message, '3');
assert.same(error2.cause, undefined);
assert.same(error2.name, 'SuppressedError');
assert.throws(() => SuppressedError(1, 2, Symbol('SuppressedError constructor test')), 'throws on symbol as a message');
assert.same(toString(SuppressedError()), '[object Error]', 'Object#toString');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.false(SuppressedError.prototype.hasOwnProperty('cause'), 'prototype has not cause');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.async-dispose.js 0000664 0000000 0000000 00000000413 14517762213 0024174 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Symbol.asyncDispose', assert => {
assert.true('asyncDispose' in Symbol, 'Symbol.asyncDispose available');
assert.true(Object(Symbol.asyncDispose) instanceof Symbol, 'Symbol.asyncDispose is symbol');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.dispose.js 0000664 0000000 0000000 00000000364 14517762213 0023066 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/actual/symbol';
QUnit.test('Symbol.dispose', assert => {
assert.true('dispose' in Symbol, 'Symbol.dispose available');
assert.true(Object(Symbol.dispose) instanceof Symbol, 'Symbol.dispose is symbol');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.is-registered-symbol.js 0000664 0000000 0000000 00000002134 14517762213 0025466 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Symbol.isRegisteredSymbol', assert => {
const { isRegisteredSymbol } = Symbol;
assert.isFunction(isRegisteredSymbol, 'Symbol.isRegisteredSymbol is function');
assert.arity(isRegisteredSymbol, 1, 'Symbol.isRegisteredSymbol arity is 1');
assert.name(isRegisteredSymbol, 'isRegisteredSymbol', 'Symbol.isRegisteredSymbol.name is "isRegisteredSymbol"');
assert.true(isRegisteredSymbol(Symbol.for('foo')), 'registered');
assert.true(isRegisteredSymbol(Object(Symbol.for('foo'))), 'registered, boxed');
const symbol = Symbol('Symbol.isRegisteredSymbol test');
assert.false(isRegisteredSymbol(symbol), 'non-registered');
assert.false(isRegisteredSymbol(Object(symbol)), 'non-registered, boxed');
assert.false(isRegisteredSymbol(1), '1');
assert.false(isRegisteredSymbol(true), 'true');
assert.false(isRegisteredSymbol('1'), 'string');
assert.false(isRegisteredSymbol(null), 'null');
assert.false(isRegisteredSymbol(), 'undefined');
assert.false(isRegisteredSymbol({}), 'object');
assert.false(isRegisteredSymbol([]), 'array');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.is-registered.js 0000664 0000000 0000000 00000001744 14517762213 0024171 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Symbol.isRegistered', assert => {
const { isRegistered } = Symbol;
assert.isFunction(isRegistered, 'Symbol.isRegistered is function');
assert.arity(isRegistered, 1, 'Symbol.isRegistered arity is 1');
assert.name(isRegistered, 'isRegisteredSymbol', 'Symbol.isRegistered.name is "isRegisteredSymbol"');
assert.true(isRegistered(Symbol.for('foo')), 'registered');
assert.true(isRegistered(Object(Symbol.for('foo'))), 'registered, boxed');
const symbol = Symbol('Symbol.isRegistered test');
assert.false(isRegistered(symbol), 'non-registered');
assert.false(isRegistered(Object(symbol)), 'non-registered, boxed');
assert.false(isRegistered(1), '1');
assert.false(isRegistered(true), 'true');
assert.false(isRegistered('1'), 'string');
assert.false(isRegistered(null), 'null');
assert.false(isRegistered(), 'undefined');
assert.false(isRegistered({}), 'object');
assert.false(isRegistered([]), 'array');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.is-well-known-symbol.js 0000664 0000000 0000000 00000002343 14517762213 0025430 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Symbol.isWellKnownSymbol', assert => {
const { isWellKnownSymbol } = Symbol;
assert.isFunction(isWellKnownSymbol, 'Symbol.isWellKnownSymbol is function');
assert.arity(isWellKnownSymbol, 1, 'Symbol.isWellKnownSymbol arity is 1');
assert.name(isWellKnownSymbol, 'isWellKnownSymbol', 'Symbol.isWellKnownSymbol.name is "isWellKnownSymbol"');
assert.true(isWellKnownSymbol(Symbol.iterator), 'registered-1');
assert.true(isWellKnownSymbol(Object(Symbol.iterator)), 'registered-2, boxed');
assert.true(isWellKnownSymbol(Symbol.patternMatch), 'registered-3');
assert.true(isWellKnownSymbol(Object(Symbol.patternMatch)), 'registered-4, boxed');
const symbol = Symbol('Symbol.isWellKnownSymbol test');
assert.false(isWellKnownSymbol(symbol), 'non-registered');
assert.false(isWellKnownSymbol(Object(symbol)), 'non-registered, boxed');
assert.false(isWellKnownSymbol(1), '1');
assert.false(isWellKnownSymbol(true), 'true');
assert.false(isWellKnownSymbol('1'), 'string');
assert.false(isWellKnownSymbol(null), 'null');
assert.false(isWellKnownSymbol(), 'undefined');
assert.false(isWellKnownSymbol({}), 'object');
assert.false(isWellKnownSymbol([]), 'array');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.is-well-known.js 0000664 0000000 0000000 00000002137 14517762213 0024126 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Symbol.isWellKnown', assert => {
const { isWellKnown } = Symbol;
assert.isFunction(isWellKnown, 'Symbol.isWellKnown is function');
assert.arity(isWellKnown, 1, 'Symbol.isWellKnown arity is 1');
assert.name(isWellKnown, 'isWellKnownSymbol', 'Symbol.isWellKnown.name is "isWellKnownSymbol"');
assert.true(isWellKnown(Symbol.iterator), 'registered-1');
assert.true(isWellKnown(Object(Symbol.iterator)), 'registered-2, boxed');
assert.true(isWellKnown(Symbol.patternMatch), 'registered-3');
assert.true(isWellKnown(Object(Symbol.patternMatch)), 'registered-4, boxed');
const symbol = Symbol('Symbol.isWellKnown test');
assert.false(isWellKnown(symbol), 'non-registered');
assert.false(isWellKnown(Object(symbol)), 'non-registered, boxed');
assert.false(isWellKnown(1), '1');
assert.false(isWellKnown(true), 'true');
assert.false(isWellKnown('1'), 'string');
assert.false(isWellKnown(null), 'null');
assert.false(isWellKnown(), 'undefined');
assert.false(isWellKnown({}), 'object');
assert.false(isWellKnown([]), 'array');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.matcher.js 0000664 0000000 0000000 00000000362 14517762213 0023041 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Symbol.matcher', assert => {
assert.true('matcher' in Symbol, 'Symbol.matcher available');
assert.true(Object(Symbol.matcher) instanceof Symbol, 'Symbol.matcher is symbol');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.metadata-key.js 0000664 0000000 0000000 00000000406 14517762213 0023763 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Symbol.metadataKey', assert => {
assert.true('metadataKey' in Symbol, 'Symbol.metadataKey available');
assert.true(Object(Symbol.metadataKey) instanceof Symbol, 'Symbol.metadataKey is symbol');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.metadata.js 0000664 0000000 0000000 00000000371 14517762213 0023176 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/actual/symbol';
QUnit.test('Symbol.metadata', assert => {
assert.true('metadata' in Symbol, 'Symbol.metadata available');
assert.true(Object(Symbol.metadata) instanceof Symbol, 'Symbol.metadata is symbol');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.observable.js 0000664 0000000 0000000 00000000401 14517762213 0023534 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Symbol.observable', assert => {
assert.true('observable' in Symbol, 'Symbol.observable available');
assert.true(Object(Symbol.observable) instanceof Symbol, 'Symbol.observable is symbol');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.pattern-match.js 0000664 0000000 0000000 00000000413 14517762213 0024162 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Symbol.patternMatch', assert => {
assert.true('patternMatch' in Symbol, 'Symbol.patternMatch available');
assert.true(Object(Symbol.patternMatch) instanceof Symbol, 'Symbol.patternMatch is symbol');
});
core-js-3.33.2/tests/unit-pure/esnext.symbol.replace-all.js 0000664 0000000 0000000 00000000404 14517762213 0023574 0 ustar 00root root 0000000 0000000 import Symbol from 'core-js-pure/full/symbol';
QUnit.test('Symbol.replaceAll', assert => {
assert.true('replaceAll' in Symbol, 'Symbol.replaceAll is available');
assert.true(Object(Symbol.replaceAll) instanceof Symbol, 'Symbol.replaceAll is symbol');
});
core-js-3.33.2/tests/unit-pure/esnext.weak-map.delete-all.js 0000664 0000000 0000000 00000002744 14517762213 0023631 0 ustar 00root root 0000000 0000000 import WeakMap from 'core-js-pure/full/weak-map';
QUnit.test('WeakMap#deleteAll', assert => {
const { deleteAll } = WeakMap.prototype;
assert.isFunction(deleteAll);
assert.arity(deleteAll, 0);
assert.nonEnumerable(WeakMap.prototype, 'deleteAll');
const a = [];
const b = [];
const c = [];
const d = [];
const e = [];
let set = new WeakMap([[a, 1], [b, 2], [c, 3]]);
assert.true(set.deleteAll(a, b));
assert.false(set.has(a));
assert.false(set.has(b));
assert.true(set.has(c));
assert.false(set.has(d));
assert.false(set.has(e));
set = new WeakMap([[a, 1], [b, 2], [c, 3]]);
assert.false(set.deleteAll(c, d));
assert.true(set.has(a));
assert.true(set.has(b));
assert.false(set.has(c));
assert.false(set.has(d));
assert.false(set.has(e));
set = new WeakMap([[a, 1], [b, 2], [c, 3]]);
assert.false(set.deleteAll(d, e));
assert.true(set.has(a));
assert.true(set.has(b));
assert.true(set.has(c));
assert.false(set.has(d));
assert.false(set.has(e));
set = new WeakMap([[a, 1], [b, 2], [c, 3]]);
assert.true(set.deleteAll());
assert.true(set.has(a));
assert.true(set.has(b));
assert.true(set.has(c));
assert.false(set.has(d));
assert.false(set.has(e));
assert.throws(() => deleteAll.call({ delete() { /* empty */ } }, a, b, c));
assert.throws(() => deleteAll.call({}, a, b, c), TypeError);
assert.throws(() => deleteAll.call(undefined, a, b, c), TypeError);
assert.throws(() => deleteAll.call(null, a, b, c), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.weak-map.emplace.js 0000664 0000000 0000000 00000003651 14517762213 0023225 0 ustar 00root root 0000000 0000000 import WeakMap from 'core-js-pure/full/weak-map';
QUnit.test('WeakMap#emplace', assert => {
const { emplace } = WeakMap.prototype;
assert.isFunction(emplace);
assert.arity(emplace, 2);
assert.name(emplace, 'emplace');
assert.nonEnumerable(WeakMap.prototype, 'emplace');
const a = {};
const b = {};
const map = new WeakMap([[a, 2]]);
let handler = {
update(value, key, that) {
assert.same(this, handler, 'correct handler in callback');
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
assert.same(key, a, 'correct key in callback');
assert.same(that, map, 'correct map in callback');
return value ** 2;
},
insert() {
assert.avoid();
},
};
assert.same(map.emplace(a, handler), 4, 'returns a correct value');
handler = {
update() {
assert.avoid();
},
insert(key, that) {
assert.same(this, handler, 'correct handler in callback');
assert.same(arguments.length, 2, 'correct number of callback arguments');
assert.same(key, b, 'correct key in callback');
assert.same(that, map, 'correct map in callback');
return 3;
},
};
assert.same(map.emplace(b, handler), 3, 'returns a correct value');
assert.same(map.get(a), 4, 'correct result #1');
assert.same(map.get(b), 3, 'correct result #2');
assert.same(new WeakMap([[a, 2]]).emplace(b, { insert: () => 3 }), 3);
assert.same(new WeakMap([[a, 2]]).emplace(a, { update: value => value ** 2 }), 4);
handler = { update() { /* empty */ }, insert() { /* empty */ } };
assert.throws(() => new WeakMap().emplace(a), TypeError);
assert.throws(() => emplace.call({}, a, handler), TypeError);
assert.throws(() => emplace.call([], a, handler), TypeError);
assert.throws(() => emplace.call(undefined, a, handler), TypeError);
assert.throws(() => emplace.call(null, a, handler), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.weak-map.from.js 0000664 0000000 0000000 00000001520 14517762213 0022553 0 ustar 00root root 0000000 0000000 import { createIterable } from '../helpers/helpers.js';
import WeakMap from 'core-js-pure/full/weak-map';
QUnit.test('WeakMap.from', assert => {
const { from } = WeakMap;
assert.isFunction(from);
assert.arity(from, 1);
assert.true(WeakMap.from() instanceof WeakMap);
const array = [];
assert.same(WeakMap.from([[array, 2]]).get(array), 2);
assert.same(WeakMap.from(createIterable([[array, 2]])).get(array), 2);
const pair = [{}, 1];
const context = {};
WeakMap.from([pair], function (element, index) {
assert.same(element, pair);
assert.same(index, 0);
assert.same(this, context);
return element;
}, context);
assert.throws(() => from([{}, 1]));
let arg = null;
function F(it) {
return arg = it;
}
from.call(F, createIterable([1, 2, 3]), it => it ** 2);
assert.deepEqual(arg, [1, 4, 9]);
});
core-js-3.33.2/tests/unit-pure/esnext.weak-map.of.js 0000664 0000000 0000000 00000000666 14517762213 0022226 0 ustar 00root root 0000000 0000000 import WeakMap from 'core-js-pure/full/weak-map';
QUnit.test('WeakMap.of', assert => {
const { of } = WeakMap;
assert.isFunction(of);
assert.arity(of, 0);
const array = [];
assert.true(WeakMap.of() instanceof WeakMap);
assert.same(WeakMap.of([array, 2]).get(array), 2);
assert.throws(() => of(1));
let arg = null;
function F(it) {
return arg = it;
}
of.call(F, 1, 2, 3);
assert.deepEqual(arg, [1, 2, 3]);
});
core-js-3.33.2/tests/unit-pure/esnext.weak-map.upsert.js 0000664 0000000 0000000 00000003010 14517762213 0023126 0 ustar 00root root 0000000 0000000 import WeakMap from 'core-js-pure/full/weak-map';
QUnit.test('WeakMap#upsert', assert => {
const { upsert } = WeakMap.prototype;
assert.isFunction(upsert);
assert.arity(upsert, 2);
assert.nonEnumerable(WeakMap.prototype, 'upsert');
const a = {};
const b = {};
const map = new WeakMap([[a, 2]]);
assert.same(map.upsert(a, function (value) {
assert.same(arguments.length, 1, 'correct number of callback arguments');
assert.same(value, 2, 'correct value in callback');
return value ** 2;
}, () => {
assert.avoid();
return 3;
}), 4, 'returns a correct value');
assert.same(map.upsert(b, value => {
assert.avoid();
return value ** 2;
}, function () {
assert.same(arguments.length, 0, 'correct number of callback arguments');
return 3;
}), 3, 'returns a correct value');
assert.same(map.get(a), 4, 'correct result #1');
assert.same(map.get(b), 3, 'correct result #2');
assert.same(new WeakMap([[a, 2]]).upsert(b, null, () => 3), 3);
assert.same(new WeakMap([[a, 2]]).upsert(a, value => value ** 2), 4);
assert.throws(() => new WeakMap().upsert(a), TypeError);
assert.throws(() => upsert.call({}, a, () => { /* empty */ }, () => { /* empty */ }), TypeError);
assert.throws(() => upsert.call([], a, () => { /* empty */ }, () => { /* empty */ }), TypeError);
assert.throws(() => upsert.call(undefined, a, () => { /* empty */ }, () => { /* empty */ }), TypeError);
assert.throws(() => upsert.call(null, a, () => { /* empty */ }, () => { /* empty */ }), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.weak-set.add-all.js 0000664 0000000 0000000 00000001646 14517762213 0023135 0 ustar 00root root 0000000 0000000 import WeakSet from 'core-js-pure/full/weak-set';
QUnit.test('WeakSet#addAll', assert => {
const { addAll } = WeakSet.prototype;
assert.isFunction(addAll);
assert.arity(addAll, 0);
assert.name(addAll, 'addAll');
assert.nonEnumerable(WeakSet.prototype, 'addAll');
const a = [];
const b = [];
const c = [];
let set = new WeakSet([a]);
assert.same(set.addAll(b), set);
set = new WeakSet([a]).addAll(b, c);
assert.true(set.has(a));
assert.true(set.has(b));
assert.true(set.has(c));
set = new WeakSet([a]).addAll(a, b);
assert.true(set.has(a));
assert.true(set.has(b));
set = new WeakSet([a]).addAll();
assert.true(set.has(a));
assert.throws(() => addAll.call({ add() { /* empty */ } }, a, b, c));
assert.throws(() => addAll.call({}, a, b, c), TypeError);
assert.throws(() => addAll.call(undefined, a, b, c), TypeError);
assert.throws(() => addAll.call(null, a, b, c), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.weak-set.delete-all.js 0000664 0000000 0000000 00000002717 14517762213 0023647 0 ustar 00root root 0000000 0000000 import WeakSet from 'core-js-pure/full/weak-set';
QUnit.test('WeakSet#deleteAll', assert => {
const { deleteAll } = WeakSet.prototype;
assert.isFunction(deleteAll);
assert.arity(deleteAll, 0);
assert.name(deleteAll, 'deleteAll');
assert.nonEnumerable(WeakSet.prototype, 'deleteAll');
const a = [];
const b = [];
const c = [];
const d = [];
const e = [];
let set = new WeakSet([a, b, c]);
assert.true(set.deleteAll(a, b));
assert.false(set.has(a));
assert.false(set.has(b));
assert.true(set.has(c));
assert.false(set.has(d));
assert.false(set.has(e));
set = new WeakSet([a, b, c]);
assert.false(set.deleteAll(c, d));
assert.true(set.has(a));
assert.true(set.has(b));
assert.false(set.has(c));
assert.false(set.has(d));
assert.false(set.has(e));
set = new WeakSet([a, b, c]);
assert.false(set.deleteAll(d, e));
assert.true(set.has(a));
assert.true(set.has(b));
assert.true(set.has(c));
assert.false(set.has(d));
assert.false(set.has(e));
set = new WeakSet([a, b, c]);
assert.true(set.deleteAll());
assert.true(set.has(a));
assert.true(set.has(b));
assert.true(set.has(c));
assert.false(set.has(d));
assert.false(set.has(e));
assert.throws(() => deleteAll.call({ delete() { /* empty */ } }, a, b, c));
assert.throws(() => deleteAll.call({}, a, b, c), TypeError);
assert.throws(() => deleteAll.call(undefined, a, b, c), TypeError);
assert.throws(() => deleteAll.call(null, a, b, c), TypeError);
});
core-js-3.33.2/tests/unit-pure/esnext.weak-set.from.js 0000664 0000000 0000000 00000001474 14517762213 0022601 0 ustar 00root root 0000000 0000000 import { createIterable } from '../helpers/helpers.js';
import WeakSet from 'core-js-pure/full/weak-set';
QUnit.test('WeakSet.from', assert => {
const { from } = WeakSet;
assert.isFunction(from);
assert.arity(from, 1);
assert.true(WeakSet.from() instanceof WeakSet);
const array = [];
assert.true(WeakSet.from([array]).has(array));
assert.true(WeakSet.from(createIterable([array])).has(array));
const object = {};
const context = {};
WeakSet.from([object], function (element, index) {
assert.same(element, object);
assert.same(index, 0);
assert.same(this, context);
return element;
}, context);
assert.throws(() => from({}));
let arg = null;
function F(it) {
return arg = it;
}
from.call(F, createIterable([1, 2, 3]), it => it ** 2);
assert.deepEqual(arg, [1, 4, 9]);
});
core-js-3.33.2/tests/unit-pure/esnext.weak-set.of.js 0000664 0000000 0000000 00000000647 14517762213 0022243 0 ustar 00root root 0000000 0000000 import WeakSet from 'core-js-pure/full/weak-set';
QUnit.test('WeakSet.of', assert => {
const { of } = WeakSet;
assert.isFunction(of);
assert.arity(of, 0);
const array = [];
assert.true(WeakSet.of() instanceof WeakSet);
assert.true(WeakSet.of(array).has(array));
assert.throws(() => of(1));
let arg = null;
function F(it) {
arg = it;
}
of.call(F, 1, 2, 3);
assert.deepEqual(arg, [1, 2, 3]);
});
core-js-3.33.2/tests/unit-pure/helpers.get-iterator-method.js 0000664 0000000 0000000 00000001262 14517762213 0024132 0 ustar 00root root 0000000 0000000 import { createIterable } from '../helpers/helpers.js';
import getIteratorMethod from 'core-js-pure/full/get-iterator-method';
QUnit.test('getIteratorMethod helper', assert => {
assert.isFunction(getIteratorMethod);
const iterable = createIterable([]);
const iterFn = getIteratorMethod(iterable);
assert.isFunction(iterFn);
assert.isIterator(iterFn.call(iterable));
assert.isFunction(getIteratorMethod([]));
assert.isFunction(getIteratorMethod(function () {
// eslint-disable-next-line prefer-rest-params -- required for testing
return arguments;
}()));
assert.isFunction(getIteratorMethod(Array.prototype));
assert.same(getIteratorMethod({}), undefined);
});
core-js-3.33.2/tests/unit-pure/helpers.get-iterator.js 0000664 0000000 0000000 00000000756 14517762213 0022663 0 ustar 00root root 0000000 0000000 import { createIterable } from '../helpers/helpers.js';
import getIterator from 'core-js-pure/full/get-iterator';
QUnit.test('getIterator helper', assert => {
assert.isFunction(getIterator);
assert.isIterator(getIterator([]));
assert.isIterator(getIterator(function () {
// eslint-disable-next-line prefer-rest-params -- required for testing
return arguments;
}()));
assert.isIterator(getIterator(createIterable([])));
assert.throws(() => getIterator({}), TypeError);
});
core-js-3.33.2/tests/unit-pure/helpers.is-iterable.js 0000664 0000000 0000000 00000000755 14517762213 0022454 0 ustar 00root root 0000000 0000000 import { createIterable } from '../helpers/helpers.js';
import isIterable from 'core-js-pure/full/is-iterable';
QUnit.test('isIterable helper', assert => {
assert.isFunction(isIterable);
assert.true(isIterable(createIterable([])));
assert.true(isIterable([]));
assert.true(isIterable(function () {
// eslint-disable-next-line prefer-rest-params -- required for testing
return arguments;
}()));
assert.true(isIterable(Array.prototype));
assert.true(isIterable({}));
});
core-js-3.33.2/tests/unit-pure/web.atob.js 0000664 0000000 0000000 00000002412 14517762213 0020304 0 ustar 00root root 0000000 0000000 // based on https://github.com/davidchambers/Base64.js/blob/master/test/base64.js
import atob from 'core-js-pure/stable/atob';
QUnit.test('atob', assert => {
assert.isFunction(atob);
assert.arity(atob, 1);
assert.same(atob(''), '');
assert.same(atob('Zg=='), 'f');
assert.same(atob('Zm8='), 'fo');
assert.same(atob('Zm9v'), 'foo');
assert.same(atob('cXV1eA=='), 'quux');
assert.same(atob('ISIjJCU='), '!"#$%');
assert.same(atob('JicoKSor'), "&'()*+");
assert.same(atob('LC0uLzAxMg=='), ',-./012');
assert.same(atob('MzQ1Njc4OTo='), '3456789:');
assert.same(atob('Ozw9Pj9AQUJD'), ';<=>?@ABC');
assert.same(atob('REVGR0hJSktMTQ=='), 'DEFGHIJKLM');
assert.same(atob('Tk9QUVJTVFVWV1g='), 'NOPQRSTUVWX');
assert.same(atob('WVpbXF1eX2BhYmM='), 'YZ[\\]^_`abc');
assert.same(atob('ZGVmZ2hpamtsbW5vcA=='), 'defghijklmnop');
assert.same(atob('cXJzdHV2d3h5ent8fX4='), 'qrstuvwxyz{|}~');
assert.same(atob(' '), '');
assert.same(atob(42), atob('42'));
assert.same(atob(null), atob('null'));
assert.throws(() => atob(), TypeError, 'no args');
assert.throws(() => atob('a'), 'invalid #1');
assert.throws(() => atob('a '), 'invalid #2');
assert.throws(() => atob('aaaaa'), 'invalid #3');
assert.throws(() => atob('[object Object]'), 'invalid #4');
});
core-js-3.33.2/tests/unit-pure/web.btoa.js 0000664 0000000 0000000 00000002301 14517762213 0020301 0 ustar 00root root 0000000 0000000 // based on https://github.com/davidchambers/Base64.js/blob/master/test/base64.js
import btoa from 'core-js-pure/stable/btoa';
QUnit.test('btoa', assert => {
assert.isFunction(btoa);
assert.arity(btoa, 1);
assert.same(btoa(''), '');
assert.same(btoa('f'), 'Zg==');
assert.same(btoa('fo'), 'Zm8=');
assert.same(btoa('foo'), 'Zm9v');
assert.same(btoa('quux'), 'cXV1eA==');
assert.same(btoa('!"#$%'), 'ISIjJCU=');
assert.same(btoa("&'()*+"), 'JicoKSor');
assert.same(btoa(',-./012'), 'LC0uLzAxMg==');
assert.same(btoa('3456789:'), 'MzQ1Njc4OTo=');
assert.same(btoa(';<=>?@ABC'), 'Ozw9Pj9AQUJD');
assert.same(btoa('DEFGHIJKLM'), 'REVGR0hJSktMTQ==');
assert.same(btoa('NOPQRSTUVWX'), 'Tk9QUVJTVFVWV1g=');
assert.same(btoa('YZ[\\]^_`abc'), 'WVpbXF1eX2BhYmM=');
assert.same(btoa('defghijklmnop'), 'ZGVmZ2hpamtsbW5vcA==');
assert.same(btoa('qrstuvwxyz{|}~'), 'cXJzdHV2d3h5ent8fX4=');
assert.same(btoa('qrstuvwxyz{|}~'), 'cXJzdHV2d3h5ent8fX4=');
assert.same(btoa(42), btoa('42'));
assert.same(btoa(null), btoa('null'));
assert.same(btoa({ x: 1 }), btoa('[object Object]'));
assert.throws(() => btoa(), TypeError, 'no args');
assert.throws(() => btoa('✈'), 'non-ASCII');
});
core-js-3.33.2/tests/unit-pure/web.dom-collections.iterator.js 0000664 0000000 0000000 00000003233 14517762213 0024304 0 ustar 00root root 0000000 0000000 import { GLOBAL } from '../helpers/constants.js';
import Symbol from 'core-js-pure/es/symbol';
import getIteratorMethod from 'core-js-pure/stable/get-iterator-method';
QUnit.test('Iterable DOM collections', assert => {
let absent = true;
const collections = [
'CSSRuleList',
'CSSStyleDeclaration',
'CSSValueList',
'ClientRectList',
'DOMRectList',
'DOMStringList',
'DOMTokenList',
'DataTransferItemList',
'FileList',
'HTMLAllCollection',
'HTMLCollection',
'HTMLFormElement',
'HTMLSelectElement',
'MediaList',
'MimeTypeArray',
'NamedNodeMap',
'NodeList',
'PaintRequestList',
'Plugin',
'PluginArray',
'SVGLengthList',
'SVGNumberList',
'SVGPathSegList',
'SVGPointList',
'SVGStringList',
'SVGTransformList',
'SourceBufferList',
'StyleSheetList',
'TextTrackCueList',
'TextTrackList',
'TouchList',
];
for (const name of collections) {
const Collection = GLOBAL[name];
if (Collection) {
absent = false;
assert.same(Collection.prototype[Symbol.toStringTag], name, `${ name }::@@toStringTag is '${ name }'`);
if (Object.prototype.toString.call(Collection.prototype).slice(8, -1) === name) {
assert.isFunction(getIteratorMethod(Collection.prototype), `${ name }::@@iterator is function`);
}
}
}
if (GLOBAL.NodeList && GLOBAL.document && document.querySelectorAll && document.querySelectorAll('div') instanceof NodeList) {
assert.isFunction(getIteratorMethod(document.querySelectorAll('div')), 'works with document.querySelectorAll');
}
if (absent) {
assert.required('DOM collections are absent');
}
});
core-js-3.33.2/tests/unit-pure/web.dom-exception.constructor.js 0000664 0000000 0000000 00000011432 14517762213 0024520 0 ustar 00root root 0000000 0000000 import { DESCRIPTORS, NODE } from '../helpers/constants.js';
import DOMException from 'core-js-pure/stable/dom-exception';
import Symbol from 'core-js-pure/es/symbol';
const errors = {
IndexSizeError: { s: 'INDEX_SIZE_ERR', c: 1, m: 1 },
DOMStringSizeError: { s: 'DOMSTRING_SIZE_ERR', c: 2, m: 0 },
HierarchyRequestError: { s: 'HIERARCHY_REQUEST_ERR', c: 3, m: 1 },
WrongDocumentError: { s: 'WRONG_DOCUMENT_ERR', c: 4, m: 1 },
InvalidCharacterError: { s: 'INVALID_CHARACTER_ERR', c: 5, m: 1 },
NoDataAllowedError: { s: 'NO_DATA_ALLOWED_ERR', c: 6, m: 0 },
NoModificationAllowedError: { s: 'NO_MODIFICATION_ALLOWED_ERR', c: 7, m: 1 },
NotFoundError: { s: 'NOT_FOUND_ERR', c: 8, m: 1 },
NotSupportedError: { s: 'NOT_SUPPORTED_ERR', c: 9, m: 1 },
InUseAttributeError: { s: 'INUSE_ATTRIBUTE_ERR', c: 10, m: 1 },
InvalidStateError: { s: 'INVALID_STATE_ERR', c: 11, m: 1 },
SyntaxError: { s: 'SYNTAX_ERR', c: 12, m: 1 },
InvalidModificationError: { s: 'INVALID_MODIFICATION_ERR', c: 13, m: 1 },
NamespaceError: { s: 'NAMESPACE_ERR', c: 14, m: 1 },
InvalidAccessError: { s: 'INVALID_ACCESS_ERR', c: 15, m: 1 },
ValidationError: { s: 'VALIDATION_ERR', c: 16, m: 0 },
TypeMismatchError: { s: 'TYPE_MISMATCH_ERR', c: 17, m: 1 },
SecurityError: { s: 'SECURITY_ERR', c: 18, m: 1 },
NetworkError: { s: 'NETWORK_ERR', c: 19, m: 1 },
AbortError: { s: 'ABORT_ERR', c: 20, m: 1 },
URLMismatchError: { s: 'URL_MISMATCH_ERR', c: 21, m: 1 },
QuotaExceededError: { s: 'QUOTA_EXCEEDED_ERR', c: 22, m: 1 },
TimeoutError: { s: 'TIMEOUT_ERR', c: 23, m: 1 },
InvalidNodeTypeError: { s: 'INVALID_NODE_TYPE_ERR', c: 24, m: 1 },
DataCloneError: { s: 'DATA_CLONE_ERR', c: 25, m: 1 },
};
const HAS_STACK = 'stack' in Error('1');
QUnit.test('DOMException', assert => {
assert.isFunction(DOMException);
assert.arity(DOMException, 0);
assert.name(DOMException, 'DOMException');
let error = new DOMException({}, 'Foo');
assert.true(error instanceof DOMException, 'new DOMException({}, "Foo") instanceof DOMException');
assert.same(error.message, '[object Object]', 'new DOMException({}, "Foo").message');
assert.same(error.name, 'Foo', 'new DOMException({}, "Foo").name');
assert.same(error.code, 0, 'new DOMException({}, "Foo").code');
assert.same(String(error), 'Foo: [object Object]', 'String(new DOMException({}, "Foo"))'); // Safari 10.1 bug
// assert.same(error.constructor, DOMException, 'new DOMException({}, "Foo").constructor');
assert.same(error[Symbol.toStringTag], 'DOMException', 'DOMException.prototype[Symbol.toStringTag]');
if (HAS_STACK) assert.true('stack' in error, "'stack' in new DOMException()");
assert.same(new DOMException().message, '', 'new DOMException().message');
assert.same(new DOMException(undefined).message, '', 'new DOMException(undefined).message');
assert.same(new DOMException(42).name, 'Error', 'new DOMException(42).name');
assert.same(new DOMException(42, undefined).name, 'Error', 'new DOMException(42, undefined).name');
for (const name in errors) {
error = new DOMException(42, name);
assert.true(error instanceof DOMException, `new DOMException({}, "${ name }") instanceof DOMException`);
assert.same(error.message, '42', `new DOMException({}, "${ name }").message`);
assert.same(error.name, name, `new DOMException({}, "${ name }").name`);
if (errors[name].m) assert.same(error.code, errors[name].c, `new DOMException({}, "${ name }").code`);
// NodeJS and Deno set codes to deprecated errors
else if (!NODE) assert.same(error.code, 0, `new DOMException({}, "${ name }").code`);
assert.same(String(error), `${ name }: 42`, `String(new DOMException({}, "${ name }"))`); // Safari 10.1 bug
if (HAS_STACK) assert.true('stack' in error, `'stack' in new DOMException({}, "${ name }")`);
assert.same(DOMException[errors[name].s], errors[name].c, `DOMException.${ errors[name].s }`);
assert.same(DOMException.prototype[errors[name].s], errors[name].c, `DOMException.prototype.${ errors[name].s }`);
}
assert.throws(() => DOMException(42, 'DataCloneError'), "DOMException(42, 'DataCloneError')");
const symbol = Symbol('DOMException constructor test');
assert.throws(() => new DOMException(symbol, 'DataCloneError'), "new DOMException(Symbol(), 'DataCloneError')");
assert.throws(() => new DOMException(42, symbol), 'new DOMException(42, Symbol())');
if (DESCRIPTORS) {
// assert.throws(() => DOMException.prototype.message, 'DOMException.prototype.message'); // FF55- , Safari 10.1 bug
// assert.throws(() => DOMException.prototype.name, 'DOMException.prototype.name'); // FF55-, Safari 10.1 bug bug
// assert.throws(() => DOMException.prototype.code, 'DOMException.prototype.code'); // Safari 10.1 bug
// assert.throws(() => DOMException.prototype.toString(), 'DOMException.prototype.toString()'); // FF55- bug
}
});
core-js-3.33.2/tests/unit-pure/web.queue-microtask.js 0000664 0000000 0000000 00000000734 14517762213 0022502 0 ustar 00root root 0000000 0000000 import { timeLimitedPromise } from '../helpers/helpers.js';
import queueMicrotask from 'core-js-pure/full/queue-microtask';
QUnit.test('queueMicrotask', assert => {
assert.isFunction(queueMicrotask);
assert.arity(queueMicrotask, 1);
return timeLimitedPromise(3e3, resolve => {
let called = false;
queueMicrotask(() => {
called = true;
resolve();
});
assert.false(called, 'async');
}).then(() => {
assert.required('works');
});
});
core-js-3.33.2/tests/unit-pure/web.self.js 0000664 0000000 0000000 00000000265 14517762213 0020314 0 ustar 00root root 0000000 0000000 import self from 'core-js-pure/stable/self';
QUnit.test('self', assert => {
assert.same(self, Object(self), 'is object');
assert.same(self.Math, Math, 'contains globals');
});
core-js-3.33.2/tests/unit-pure/web.set-immediate.js 0000664 0000000 0000000 00000002361 14517762213 0022111 0 ustar 00root root 0000000 0000000 import { timeLimitedPromise } from '../helpers/helpers.js';
import setImmediate from 'core-js-pure/stable/set-immediate';
import clearImmediate from 'core-js-pure/stable/clear-immediate';
QUnit.test('setImmediate / clearImmediate', assert => {
assert.isFunction(setImmediate, 'setImmediate is function');
assert.isFunction(clearImmediate, 'clearImmediate is function');
let called = false;
const promise = timeLimitedPromise(1e3, resolve => {
setImmediate(() => {
called = true;
resolve();
});
}).then(() => {
assert.required('setImmediate works');
}, () => {
assert.avoid('setImmediate works');
}).then(() => {
return timeLimitedPromise(1e3, resolve => {
setImmediate((a, b) => {
resolve(a + b);
}, 'a', 'b');
});
}).then(it => {
assert.same(it, 'ab', 'setImmediate works with additional args');
}, () => {
assert.avoid('setImmediate works with additional args');
}).then(() => {
return timeLimitedPromise(50, resolve => {
clearImmediate(setImmediate(resolve));
});
}).then(() => {
assert.avoid('clearImmediate works');
}, () => {
assert.required('clearImmediate works');
});
assert.false(called, 'setImmediate is async');
return promise;
});
core-js-3.33.2/tests/unit-pure/web.set-interval.js 0000664 0000000 0000000 00000001612 14517762213 0021775 0 ustar 00root root 0000000 0000000 import { timeLimitedPromise } from '../helpers/helpers.js';
import setTimeout from 'core-js-pure/stable/set-timeout';
import setInterval from 'core-js-pure/stable/set-interval';
QUnit.test('setInterval / clearInterval', assert => {
assert.isFunction(setInterval, 'setInterval is function');
assert.isFunction(clearInterval, 'clearInterval is function');
return timeLimitedPromise(1e4, (resolve, reject) => {
let i = 0;
const interval = setInterval((a, b) => {
if (a + b !== 'ab' || i > 2) reject({ a, b, i });
if (i++ === 2) {
clearInterval(interval);
setTimeout(resolve, 30);
}
}, 5, 'a', 'b');
}).then(() => {
assert.required('setInterval & clearInterval works with additional args');
}, (error = {}) => {
assert.avoid(`setInterval & clearInterval works with additional args: ${ error.a }, ${ error.b }, times: ${ error.i }`);
});
});
core-js-3.33.2/tests/unit-pure/web.set-timeout.js 0000664 0000000 0000000 00000001526 14517762213 0021643 0 ustar 00root root 0000000 0000000 import { timeLimitedPromise } from '../helpers/helpers.js';
import setTimeout from 'core-js-pure/stable/set-timeout';
QUnit.test('setTimeout / clearTimeout', assert => {
assert.isFunction(setTimeout, 'setTimeout is function');
assert.isFunction(clearTimeout, 'clearTimeout is function');
return timeLimitedPromise(1e3, resolve => {
setTimeout((a, b) => { resolve(a + b); }, 10, 'a', 'b');
}).then(it => {
assert.same(it, 'ab', 'setTimeout works with additional args');
}, () => {
assert.avoid('setTimeout works with additional args');
}).then(() => {
return timeLimitedPromise(50, resolve => {
clearTimeout(setTimeout(resolve, 10));
});
}).then(() => {
assert.avoid('clearImmediate works with wrapped setTimeout');
}, () => {
assert.required('clearImmediate works with wrapped setTimeout');
});
});
core-js-3.33.2/tests/unit-pure/web.structured-clone.js 0000664 0000000 0000000 00000040667 14517762213 0022677 0 ustar 00root root 0000000 0000000 // Originally from: https://github.com/web-platform-tests/wpt/blob/4b35e758e2fc4225368304b02bcec9133965fd1a/IndexedDB/structured-clone.any.js
// Copyright © web-platform-tests contributors. Available under the 3-Clause BSD License.
/* eslint-disable es/no-error-cause, es/no-typed-arrays -- safe */
import { GLOBAL, NODE } from '../helpers/constants.js';
import { bufferToArray, fromSource } from '../helpers/helpers.js';
import structuredClone from 'core-js-pure/stable/structured-clone';
import from from 'core-js-pure/es/array/from';
import assign from 'core-js-pure/es/object/assign';
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
import keys from 'core-js-pure/es/object/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';
import AggregateError from 'core-js-pure/es/aggregate-error';
import DOMException from 'core-js-pure/stable/dom-exception';
QUnit.module('structuredClone', () => {
QUnit.test('identity', assert => {
assert.isFunction(structuredClone, 'structuredClone is a function');
assert.name(structuredClone, 'structuredClone');
assert.arity(structuredClone, 1);
assert.throws(() => structuredClone(), 'throws without arguments');
assert.same(structuredClone(1, null), 1, 'null as options');
assert.same(structuredClone(1, undefined), 1, 'undefined as options');
});
function cloneTest(value, verifyFunc) {
verifyFunc(value, structuredClone(value));
}
// Specialization of cloneTest() for objects, with common asserts.
function cloneObjectTest(assert, value, verifyFunc) {
cloneTest(value, (orig, clone) => {
assert.notSame(orig, clone, 'clone should have different reference');
assert.same(typeof clone, 'object', 'clone should be an object');
// https://github.com/qunitjs/node-qunit/issues/146
assert.true(getPrototypeOf(orig) === getPrototypeOf(clone), 'clone should have same prototype');
verifyFunc(orig, clone);
});
}
// ECMAScript types
// Primitive values: Undefined, Null, Boolean, Number, BigInt, String
const booleans = [false, true];
const numbers = [
NaN,
-Infinity,
-Number.MAX_VALUE,
-0xFFFFFFFF,
-0x80000000,
-0x7FFFFFFF,
-1,
-Number.MIN_VALUE,
-0,
0,
1,
Number.MIN_VALUE,
0x7FFFFFFF,
0x80000000,
0xFFFFFFFF,
Number.MAX_VALUE,
Infinity,
];
const bigints = fromSource(`[
-12345678901234567890n,
-1n,
0n,
1n,
12345678901234567890n,
]`) || [];
const strings = [
'',
'this is a sample string',
'null(\0)',
];
QUnit.test('primitives', assert => {
const primitives = [undefined, null, ...booleans, ...numbers, ...bigints, ...strings];
for (const value of primitives) cloneTest(value, (orig, clone) => {
assert.same(orig, clone, 'primitives should be same after cloned');
});
});
// "Primitive" Objects (Boolean, Number, BigInt, String)
QUnit.test('primitive objects', assert => {
const primitives = [...booleans, ...numbers, ...bigints, ...strings];
for (const value of primitives) cloneObjectTest(assert, Object(value), (orig, clone) => {
assert.same(orig.valueOf(), clone.valueOf(), 'primitive wrappers should have same value');
});
});
// Dates
QUnit.test('Date', assert => {
const dates = [
new Date(-1e13),
new Date(-1e12),
new Date(-1e9),
new Date(-1e6),
new Date(-1e3),
new Date(0),
new Date(1e3),
new Date(1e6),
new Date(1e9),
new Date(1e12),
new Date(1e13),
];
for (const date of dates) cloneTest(date, (orig, clone) => {
assert.notSame(orig, clone);
assert.same(typeof clone, 'object');
assert.same(getPrototypeOf(orig), getPrototypeOf(clone));
assert.same(orig.valueOf(), clone.valueOf());
});
});
// Regular Expressions
QUnit.test('RegExp', assert => {
const regexes = [
new RegExp(),
/abc/,
/abc/g,
/abc/i,
/abc/gi,
/abc/,
/abc/g,
/abc/i,
/abc/gi,
];
const giuy = fromSource('/abc/giuy');
if (giuy) regexes.push(giuy);
for (const regex of regexes) cloneObjectTest(assert, regex, (orig, clone) => {
assert.same(orig.toString(), clone.toString(), `regex ${ regex }`);
});
});
if (fromSource('ArrayBuffer.prototype.slice || DataView')) {
// ArrayBuffer
if (typeof Uint8Array == 'function') QUnit.test('ArrayBuffer', assert => { // Crashes
cloneObjectTest(assert, new Uint8Array([0, 1, 254, 255]).buffer, (orig, clone) => {
assert.arrayEqual(new Uint8Array(orig), new Uint8Array(clone));
});
});
// TODO SharedArrayBuffer
// Array Buffer Views
if (typeof Int8Array != 'undefined') {
QUnit.test('%TypedArray%', assert => {
const arrays = [
new Uint8Array([]),
new Uint8Array([0, 1, 254, 255]),
new Uint16Array([0x0000, 0x0001, 0xFFFE, 0xFFFF]),
new Uint32Array([0x00000000, 0x00000001, 0xFFFFFFFE, 0xFFFFFFFF]),
new Int8Array([0, 1, 254, 255]),
new Int16Array([0x0000, 0x0001, 0xFFFE, 0xFFFF]),
new Int32Array([0x00000000, 0x00000001, 0xFFFFFFFE, 0xFFFFFFFF]),
new Float32Array([-Infinity, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, Infinity, NaN]),
new Float64Array([-Infinity, -Number.MAX_VALUE, -Number.MIN_VALUE, 0, Number.MIN_VALUE, Number.MAX_VALUE, Infinity, NaN]),
];
if (typeof Uint8ClampedArray != 'undefined') {
arrays.push(new Uint8ClampedArray([0, 1, 254, 255]));
}
for (const array of arrays) cloneObjectTest(assert, array, (orig, clone) => {
assert.arrayEqual(orig, clone);
});
});
if (typeof DataView != 'undefined') QUnit.test('DataView', assert => {
const array = new Int8Array([1, 2, 3, 4]);
const view = new DataView(array.buffer);
cloneObjectTest(assert, array, (orig, clone) => {
assert.same(orig.byteLength, clone.byteLength);
assert.same(orig.byteOffset, clone.byteOffset);
assert.arrayEqual(new Int8Array(view.buffer), array);
});
});
}
if ('resizable' in ArrayBuffer.prototype) {
QUnit.test('Resizable ArrayBuffer', assert => {
const array = [1, 2, 3, 4, 5, 6, 7, 8];
let buffer = new ArrayBuffer(8, { maxByteLength: 16 });
new Int8Array(buffer).set(array);
let copy = structuredClone(buffer);
assert.arrayEqual(bufferToArray(copy), array, 'resizable-ab-1');
assert.true(copy.resizable, 'resizable-ab-1');
buffer = new ArrayBuffer(8);
new Int8Array(buffer).set(array);
copy = structuredClone(buffer);
assert.arrayEqual(bufferToArray(copy), array, 'non-resizable-ab-1');
assert.false(copy.resizable, 'non-resizable-ab-1');
buffer = new ArrayBuffer(8, { maxByteLength: 16 });
let tarray = new Int8Array(buffer);
tarray.set(array);
copy = structuredClone(tarray).buffer;
assert.arrayEqual(bufferToArray(copy), array, 'resizable-ab-2');
assert.true(copy.resizable, 'resizable-ab-2');
buffer = new ArrayBuffer(8);
tarray = new Int8Array(buffer);
tarray.set(array);
copy = structuredClone(tarray).buffer;
assert.arrayEqual(bufferToArray(copy), array, 'non-resizable-ab-2');
assert.false(copy.resizable, 'non-resizable-ab-2');
});
}
}
// Map
QUnit.test('Map', assert => {
cloneObjectTest(assert, new Map([[1, 2], [3, 4]]), (orig, clone) => {
assert.deepEqual(from(orig.keys()), from(clone.keys()));
assert.deepEqual(from(orig.values()), from(clone.values()));
});
});
// Set
QUnit.test('Set', assert => {
cloneObjectTest(assert, new Set([1, 2, 3, 4]), (orig, clone) => {
assert.deepEqual(from(orig.values()), from(clone.values()));
});
});
// Error
QUnit.test('Error', assert => {
const errors = [
['Error', new Error()],
['Error', new Error('msg', { cause: 42 })],
['EvalError', new EvalError()],
['EvalError', new EvalError('msg', { cause: 42 })],
['RangeError', new RangeError()],
['RangeError', new RangeError('msg', { cause: 42 })],
['ReferenceError', new ReferenceError()],
['ReferenceError', new ReferenceError('msg', { cause: 42 })],
['SyntaxError', new SyntaxError()],
['SyntaxError', new SyntaxError('msg', { cause: 42 })],
['TypeError', new TypeError()],
['TypeError', new TypeError('msg', { cause: 42 })],
['URIError', new URIError()],
['URIError', new URIError('msg', { cause: 42 })],
['AggregateError', new AggregateError([1, 2])],
['AggregateError', new AggregateError([1, 2], 'msg', { cause: 42 })],
];
const compile = fromSource('WebAssembly.CompileError()');
const link = fromSource('WebAssembly.LinkError()');
const runtime = fromSource('WebAssembly.RuntimeError()');
if (compile && compile.name === 'CompileError') errors.push(['CompileError', compile]);
if (link && link.name === 'LinkError') errors.push(['LinkError', link]);
if (runtime && runtime.name === 'RuntimeError') errors.push(['RuntimeError', runtime]);
for (const [name, error] of errors) cloneObjectTest(assert, error, (orig, clone) => {
assert.same(orig.constructor, clone.constructor, `${ name }#constructor`);
assert.same(orig.name, clone.name, `${ name }#name`);
assert.same(orig.message, clone.message, `${ name }#message`);
assert.same(orig.stack, clone.stack, `${ name }#stack`);
assert.same(orig.cause, clone.cause, `${ name }#cause`);
assert.deepEqual(orig.errors, clone.errors, `${ name }#errors`);
});
});
// Arrays
QUnit.test('Array', assert => {
const arrays = [
[],
[1, 2, 3],
Array(1),
assign(
['foo', 'bar'],
{ 10: true, 11: false, 20: 123, 21: 456, 30: null }),
assign(
['foo', 'bar'],
{ a: true, b: false, foo: 123, bar: 456, '': null }),
];
for (const array of arrays) cloneObjectTest(assert, array, (orig, clone) => {
assert.deepEqual(orig, clone, `array content should be same: ${ array }`);
assert.deepEqual(orig.length, clone.length, `array length should be same: ${ array }`);
assert.deepEqual(keys(orig), keys(clone), `array key should be same: ${ array }`);
for (const key of keys(orig)) {
assert.same(orig[key], clone[key], `Property ${ key }`);
}
});
});
// Objects
QUnit.test('Object', assert => {
cloneObjectTest(assert, { foo: true, bar: false }, (orig, clone) => {
assert.deepEqual(keys(orig), keys(clone));
for (const key of keys(orig)) {
assert.same(orig[key], clone[key], `Property ${ key }`);
}
});
});
// [Serializable] Platform objects
// Geometry types
if (typeof DOMMatrix == 'function') {
QUnit.test('Geometry types, DOMMatrix', assert => {
cloneObjectTest(assert, new DOMMatrix(), (orig, clone) => {
for (const key of keys(getPrototypeOf(orig))) {
assert.same(orig[key], clone[key], `Property ${ key }`);
}
});
});
}
if (typeof DOMMatrixReadOnly == 'function' && typeof DOMMatrixReadOnly.fromMatrix == 'function') {
QUnit.test('Geometry types, DOMMatrixReadOnly', assert => {
cloneObjectTest(assert, new DOMMatrixReadOnly(), (orig, clone) => {
for (const key of keys(getPrototypeOf(orig))) {
assert.same(orig[key], clone[key], `Property ${ key }`);
}
});
});
}
if (typeof DOMPoint == 'function') {
QUnit.test('Geometry types, DOMPoint', assert => {
cloneObjectTest(assert, new DOMPoint(1, 2, 3, 4), (orig, clone) => {
for (const key of keys(getPrototypeOf(orig))) {
assert.same(orig[key], clone[key], `Property ${ key }`);
}
});
});
}
if (typeof DOMPointReadOnly == 'function' && typeof DOMPointReadOnly.fromPoint == 'function') {
QUnit.test('Geometry types, DOMPointReadOnly', assert => {
cloneObjectTest(assert, new DOMPointReadOnly(1, 2, 3, 4), (orig, clone) => {
for (const key of keys(getPrototypeOf(orig))) {
assert.same(orig[key], clone[key], `Property ${ key }`);
}
});
});
}
if (typeof DOMQuad == 'function' && typeof DOMPoint == 'function') {
QUnit.test('Geometry types, DOMQuad', assert => {
cloneObjectTest(assert, new DOMQuad(
new DOMPoint(1, 2, 3, 4),
new DOMPoint(2, 2, 3, 4),
new DOMPoint(1, 3, 3, 4),
new DOMPoint(1, 2, 4, 4),
), (orig, clone) => {
for (const key of keys(getPrototypeOf(orig))) {
assert.deepEqual(orig[key], clone[key], `Property ${ key }`);
}
});
});
}
if (fromSource('new DOMRect(1, 2, 3, 4)')) {
QUnit.test('Geometry types, DOMRect', assert => {
cloneObjectTest(assert, new DOMRect(1, 2, 3, 4), (orig, clone) => {
for (const key of keys(getPrototypeOf(orig))) {
assert.same(orig[key], clone[key], `Property ${ key }`);
}
});
});
}
if (typeof DOMRectReadOnly == 'function' && typeof DOMRectReadOnly.fromRect == 'function') {
QUnit.test('Geometry types, DOMRectReadOnly', assert => {
cloneObjectTest(assert, new DOMRectReadOnly(1, 2, 3, 4), (orig, clone) => {
for (const key of keys(getPrototypeOf(orig))) {
assert.same(orig[key], clone[key], `Property ${ key }`);
}
});
});
}
// Safari 8- does not support `{ colorSpace }` option
if (fromSource('new ImageData(new ImageData(8, 8).data, 8, 8, { colorSpace: new ImageData(8, 8).colorSpace })')) {
QUnit.test('ImageData', assert => {
const imageData = new ImageData(8, 8);
for (let i = 0; i < 256; ++i) {
imageData.data[i] = i;
}
cloneObjectTest(assert, imageData, (orig, clone) => {
assert.same(orig.width, clone.width);
assert.same(orig.height, clone.height);
assert.same(orig.colorSpace, clone.colorSpace);
assert.arrayEqual(orig.data, clone.data);
});
});
}
if (fromSource('new Blob(["test"])')) QUnit.test('Blob', assert => {
cloneObjectTest(
assert,
new Blob(['This is a test.'], { type: 'a/b' }),
(orig, clone) => {
assert.same(orig.size, clone.size);
assert.same(orig.type, clone.type);
// TODO: async
// assert.same(await orig.text(), await clone.text());
});
});
QUnit.test('DOMException', assert => {
const errors = [
new DOMException(),
new DOMException('foo', 'DataCloneError'),
];
for (const error of errors) cloneObjectTest(assert, error, (orig, clone) => {
assert.same(orig.name, clone.name);
assert.same(orig.message, clone.message);
assert.same(orig.code, clone.code);
assert.same(orig.stack, clone.stack);
});
});
if (fromSource('new File(["test"], "foo.txt")')) QUnit.test('File', assert => {
cloneObjectTest(
assert,
new File(['This is a test.'], 'foo.txt', { type: 'c/d' }),
(orig, clone) => {
assert.same(orig.size, clone.size);
assert.same(orig.type, clone.type);
assert.same(orig.name, clone.name);
assert.same(orig.lastModified, clone.lastModified);
// TODO: async
// assert.same(await orig.text(), await clone.text());
});
});
// FileList
if (fromSource('new File(["test"], "foo.txt")') && fromSource('new DataTransfer()')) QUnit.test('FileList', assert => {
const transfer = new DataTransfer();
transfer.items.add(new File(['test'], 'foo.txt'));
cloneObjectTest(
assert,
transfer.files,
(orig, clone) => {
assert.same(1, clone.length);
assert.same(orig[0].size, clone[0].size);
assert.same(orig[0].type, clone[0].type);
assert.same(orig[0].name, clone[0].name);
assert.same(orig[0].lastModified, clone[0].lastModified);
},
);
});
// Non-serializable types
QUnit.test('Non-serializable types', assert => {
const nons = [
function () { return 1; },
Symbol('desc'),
GLOBAL,
];
const event = fromSource('new Event("")');
const port = fromSource('new MessageChannel().port1');
// NodeJS events are simple objects
if (event && !NODE) nons.push(event);
if (port) nons.push(port);
for (const it of nons) {
// native NodeJS `structuredClone` throws a `TypeError` on transferable non-serializable instead of `DOMException`
// https://github.com/nodejs/node/issues/40841
assert.throws(() => structuredClone(it));
}
});
});
core-js-3.33.2/tests/unit-pure/web.url-search-params.js 0000664 0000000 0000000 00000073003 14517762213 0022711 0 ustar 00root root 0000000 0000000 import { DESCRIPTORS } from '../helpers/constants.js';
import { createIterable } from '../helpers/helpers.js';
import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of';
import getOwnPropertyDescriptor from 'core-js-pure/es/object/get-own-property-descriptor';
import Symbol from 'core-js-pure/es/symbol';
import URL from 'core-js-pure/stable/url';
import URLSearchParams from 'core-js-pure/stable/url-search-params';
QUnit.test('URLSearchParams', assert => {
assert.isFunction(URLSearchParams);
assert.arity(URLSearchParams, 0);
assert.same(String(new URLSearchParams()), '');
assert.same(String(new URLSearchParams('')), '');
assert.same(String(new URLSearchParams('a=b')), 'a=b');
assert.same(String(new URLSearchParams(new URLSearchParams('a=b'))), 'a=b');
assert.same(String(new URLSearchParams([])), '');
assert.same(String(new URLSearchParams([[1, 2], ['a', 'b']])), '1=2&a=b');
assert.same(String(new URLSearchParams(createIterable([createIterable(['a', 'b']), createIterable(['c', 'd'])]))), 'a=b&c=d');
assert.same(String(new URLSearchParams({})), '');
assert.same(String(new URLSearchParams({ 1: 2, a: 'b' })), '1=2&a=b');
assert.same(String(new URLSearchParams('?a=b')), 'a=b', 'leading ? should be ignored');
assert.same(String(new URLSearchParams('??a=b')), '%3Fa=b');
assert.same(String(new URLSearchParams('?')), '');
assert.same(String(new URLSearchParams('??')), '%3F=');
assert.same(String(new URLSearchParams('a=b c')), 'a=b+c');
assert.same(String(new URLSearchParams('a=b&b=c&a=d')), 'a=b&b=c&a=d');
assert.same(String(new URLSearchParams('a==')), 'a=%3D');
assert.same(String(new URLSearchParams('a=b=')), 'a=b%3D');
assert.same(String(new URLSearchParams('a=b=c')), 'a=b%3Dc');
assert.same(String(new URLSearchParams('a==b')), 'a=%3Db');
let params = new URLSearchParams('a=b');
assert.true(params.has('a'), 'search params object has name "a"');
assert.false(params.has('b'), 'search params object has not got name "b"');
params = new URLSearchParams('a=b&c');
assert.true(params.has('a'), 'search params object has name "a"');
assert.true(params.has('c'), 'search params object has name "c"');
params = new URLSearchParams('&a&&& &&&&&a+b=& c&m%c3%b8%c3%b8');
assert.true(params.has('a'), 'search params object has name "a"');
assert.true(params.has('a b'), 'search params object has name "a b"');
assert.true(params.has(' '), 'search params object has name " "');
assert.false(params.has('c'), 'search params object did not have the name "c"');
assert.true(params.has(' c'), 'search params object has name " c"');
assert.true(params.has('møø'), 'search params object has name "møø"');
params = new URLSearchParams('a=b+c');
assert.same(params.get('a'), 'b c', 'parse +');
params = new URLSearchParams('a+b=c');
assert.same(params.get('a b'), 'c', 'parse +');
params = new URLSearchParams('a=b c');
assert.same(params.get('a'), 'b c', 'parse " "');
params = new URLSearchParams('a b=c');
assert.same(params.get('a b'), 'c', 'parse " "');
params = new URLSearchParams('a=b%20c');
assert.same(params.get('a'), 'b c', 'parse %20');
params = new URLSearchParams('a%20b=c');
assert.same(params.get('a b'), 'c', 'parse %20');
params = new URLSearchParams('a=b\0c');
assert.same(params.get('a'), 'b\0c', 'parse \\0');
params = new URLSearchParams('a\0b=c');
assert.same(params.get('a\0b'), 'c', 'parse \\0');
params = new URLSearchParams('a=b%00c');
assert.same(params.get('a'), 'b\0c', 'parse %00');
params = new URLSearchParams('a%00b=c');
assert.same(params.get('a\0b'), 'c', 'parse %00');
params = new URLSearchParams('a=b\u2384');
assert.same(params.get('a'), 'b\u2384', 'parse \u2384');
params = new URLSearchParams('a\u2384b=c');
assert.same(params.get('a\u2384b'), 'c', 'parse \u2384');
params = new URLSearchParams('a=b%e2%8e%84');
assert.same(params.get('a'), 'b\u2384', 'parse %e2%8e%84');
params = new URLSearchParams('a%e2%8e%84b=c');
assert.same(params.get('a\u2384b'), 'c', 'parse %e2%8e%84');
params = new URLSearchParams('a=b\uD83D\uDCA9c');
assert.same(params.get('a'), 'b\uD83D\uDCA9c', 'parse \uD83D\uDCA9');
params = new URLSearchParams('a\uD83D\uDCA9b=c');
assert.same(params.get('a\uD83D\uDCA9b'), 'c', 'parse \uD83D\uDCA9');
params = new URLSearchParams('a=b%f0%9f%92%a9c');
assert.same(params.get('a'), 'b\uD83D\uDCA9c', 'parse %f0%9f%92%a9');
params = new URLSearchParams('a%f0%9f%92%a9b=c');
assert.same(params.get('a\uD83D\uDCA9b'), 'c', 'parse %f0%9f%92%a9');
params = new URLSearchParams();
params.set('query', '+15555555555');
assert.same(params.toString(), 'query=%2B15555555555');
assert.same(params.get('query'), '+15555555555', 'parse encoded +');
params = new URLSearchParams(params.toString());
assert.same(params.get('query'), '+15555555555', 'parse encoded +');
const testData = [
{ input: '?a=%', output: [['a', '%']], name: 'handling %' },
{ input: { '+': '%C2' }, output: [['+', '%C2']], name: 'object with +' },
{ input: { c: 'x', a: '?' }, output: [['c', 'x'], ['a', '?']], name: 'object with two keys' },
{ input: [['c', 'x'], ['a', '?']], output: [['c', 'x'], ['a', '?']], name: 'array with two keys' },
// eslint-disable-next-line @stylistic/js/max-len -- ignore
// !!! { input: { 'a\0b': '42', 'c\uD83D': '23', dሴ: 'foo' }, output: [['a\0b', '42'], ['c\uFFFD', '23'], ['d\u1234', 'foo']], name: 'object with NULL, non-ASCII, and surrogate keys' },
];
for (const { input, output, name } of testData) {
params = new URLSearchParams(input);
let i = 0;
params.forEach((value, key) => {
const [reqKey, reqValue] = output[i++];
assert.same(key, reqKey, `construct with ${ name }`);
assert.same(value, reqValue, `construct with ${ name }`);
});
}
assert.throws(() => {
URLSearchParams('');
}, 'throws w/o `new`');
assert.throws(() => {
new URLSearchParams([[1, 2, 3]]);
}, 'sequence elements must be pairs #1');
assert.throws(() => {
new URLSearchParams([createIterable([createIterable([1, 2, 3])])]);
}, 'sequence elements must be pairs #2');
assert.throws(() => {
new URLSearchParams([[1]]);
}, 'sequence elements must be pairs #3');
assert.throws(() => {
new URLSearchParams([createIterable([createIterable([1])])]);
}, 'sequence elements must be pairs #4');
});
QUnit.test('URLSearchParams#append', assert => {
const { append } = URLSearchParams.prototype;
assert.isFunction(append);
assert.arity(append, 2);
assert.enumerable(URLSearchParams.prototype, 'append');
assert.same(new URLSearchParams().append('a', 'b'), undefined, 'void');
let params = new URLSearchParams();
params.append('a', 'b');
assert.same(String(params), 'a=b');
params.append('a', 'b');
assert.same(String(params), 'a=b&a=b');
params.append('a', 'c');
assert.same(String(params), 'a=b&a=b&a=c');
params = new URLSearchParams();
params.append('', '');
assert.same(String(params), '=');
params.append('', '');
assert.same(String(params), '=&=');
params = new URLSearchParams();
params.append(undefined, undefined);
assert.same(String(params), 'undefined=undefined');
params.append(undefined, undefined);
assert.same(String(params), 'undefined=undefined&undefined=undefined');
params = new URLSearchParams();
params.append(null, null);
assert.same(String(params), 'null=null');
params.append(null, null);
assert.same(String(params), 'null=null&null=null');
params = new URLSearchParams();
params.append('first', 1);
params.append('second', 2);
params.append('third', '');
params.append('first', 10);
assert.true(params.has('first'), 'search params object has name "first"');
assert.same(params.get('first'), '1', 'search params object has name "first" with value "1"');
assert.same(params.get('second'), '2', 'search params object has name "second" with value "2"');
assert.same(params.get('third'), '', 'search params object has name "third" with value ""');
params.append('first', 10);
assert.same(params.get('first'), '1', 'search params object has name "first" with value "1"');
assert.throws(() => {
return new URLSearchParams('').append();
}, 'throws w/o arguments');
});
QUnit.test('URLSearchParams#delete', assert => {
const $delete = URLSearchParams.prototype.delete;
assert.isFunction($delete);
assert.arity($delete, 1);
assert.enumerable(URLSearchParams.prototype, 'delete');
let params = new URLSearchParams('a=b&c=d');
params.delete('a');
assert.same(String(params), 'c=d');
params = new URLSearchParams('a=a&b=b&a=a&c=c');
params.delete('a');
assert.same(String(params), 'b=b&c=c');
params = new URLSearchParams('a=a&=&b=b&c=c');
params.delete('');
assert.same(String(params), 'a=a&b=b&c=c');
params = new URLSearchParams('a=a&null=null&b=b');
params.delete(null);
assert.same(String(params), 'a=a&b=b');
params = new URLSearchParams('a=a&undefined=undefined&b=b');
params.delete(undefined);
assert.same(String(params), 'a=a&b=b');
params = new URLSearchParams();
params.append('first', 1);
assert.true(params.has('first'), 'search params object has name "first"');
assert.same(params.get('first'), '1', 'search params object has name "first" with value "1"');
params.delete('first');
assert.false(params.has('first'), 'search params object has no "first" name');
params.append('first', 1);
params.append('first', 10);
params.delete('first');
assert.false(params.has('first'), 'search params object has no "first" name');
params = new URLSearchParams('a=1&a=2&a=null&a=3&b=4');
params.delete('a', 2);
assert.same(String(params), 'a=1&a=null&a=3&b=4');
params = new URLSearchParams('a=1&a=2&a=null&a=3&b=4');
params.delete('a', null);
assert.same(String(params), 'a=1&a=2&a=3&b=4');
params = new URLSearchParams('a=1&a=2&a=null&a=3&b=4');
params.delete('a', undefined);
assert.same(String(params), 'b=4');
if (DESCRIPTORS) {
let url = new URL('http://example.com/?param1¶m2');
url.searchParams.delete('param1');
url.searchParams.delete('param2');
assert.same(String(url), 'http://example.com/', 'url.href does not have ?');
assert.same(url.search, '', 'url.search does not have ?');
url = new URL('http://example.com/?');
url.searchParams.delete('param1');
// assert.same(String(url), 'http://example.com/', 'url.href does not have ?'); // Safari bug
assert.same(url.search, '', 'url.search does not have ?');
}
assert.throws(() => {
return new URLSearchParams('').delete();
}, 'throws w/o arguments');
});
QUnit.test('URLSearchParams#get', assert => {
const { get } = URLSearchParams.prototype;
assert.isFunction(get);
assert.arity(get, 1);
assert.enumerable(URLSearchParams.prototype, 'get');
let params = new URLSearchParams('a=b&c=d');
assert.same(params.get('a'), 'b');
assert.same(params.get('c'), 'd');
assert.same(params.get('e'), null);
params = new URLSearchParams('a=b&c=d&a=e');
assert.same(params.get('a'), 'b');
params = new URLSearchParams('=b&c=d');
assert.same(params.get(''), 'b');
params = new URLSearchParams('a=&c=d&a=e');
assert.same(params.get('a'), '');
params = new URLSearchParams('first=second&third&&');
assert.true(params.has('first'), 'Search params object has name "first"');
assert.same(params.get('first'), 'second', 'Search params object has name "first" with value "second"');
assert.same(params.get('third'), '', 'Search params object has name "third" with the empty value.');
assert.same(params.get('fourth'), null, 'Search params object has no "fourth" name and value.');
assert.same(new URLSearchParams('a=b c').get('a'), 'b c');
assert.same(new URLSearchParams('a b=c').get('a b'), 'c');
assert.same(new URLSearchParams('a=b%20c').get('a'), 'b c', 'parse %20');
assert.same(new URLSearchParams('a%20b=c').get('a b'), 'c', 'parse %20');
assert.same(new URLSearchParams('a=b\0c').get('a'), 'b\0c', 'parse \\0');
assert.same(new URLSearchParams('a\0b=c').get('a\0b'), 'c', 'parse \\0');
assert.same(new URLSearchParams('a=b%2Bc').get('a'), 'b+c', 'parse %2B');
assert.same(new URLSearchParams('a%2Bb=c').get('a+b'), 'c', 'parse %2B');
assert.same(new URLSearchParams('a=b%00c').get('a'), 'b\0c', 'parse %00');
assert.same(new URLSearchParams('a%00b=c').get('a\0b'), 'c', 'parse %00');
assert.same(new URLSearchParams('a==').get('a'), '=', 'parse =');
assert.same(new URLSearchParams('a=b=').get('a'), 'b=', 'parse =');
assert.same(new URLSearchParams('a=b=c').get('a'), 'b=c', 'parse =');
assert.same(new URLSearchParams('a==b').get('a'), '=b', 'parse =');
assert.same(new URLSearchParams('a=b\u2384').get('a'), 'b\u2384', 'parse \\u2384');
assert.same(new URLSearchParams('a\u2384b=c').get('a\u2384b'), 'c', 'parse \\u2384');
assert.same(new URLSearchParams('a=b%e2%8e%84').get('a'), 'b\u2384', 'parse %e2%8e%84');
assert.same(new URLSearchParams('a%e2%8e%84b=c').get('a\u2384b'), 'c', 'parse %e2%8e%84');
assert.same(new URLSearchParams('a=b\uD83D\uDCA9c').get('a'), 'b\uD83D\uDCA9c', 'parse \\uD83D\\uDCA9');
assert.same(new URLSearchParams('a\uD83D\uDCA9b=c').get('a\uD83D\uDCA9b'), 'c', 'parse \\uD83D\\uDCA9');
assert.same(new URLSearchParams('a=b%f0%9f%92%a9c').get('a'), 'b\uD83D\uDCA9c', 'parse %f0%9f%92%a9');
assert.same(new URLSearchParams('a%f0%9f%92%a9b=c').get('a\uD83D\uDCA9b'), 'c', 'parse %f0%9f%92%a9');
assert.same(new URLSearchParams('=').get(''), '', 'parse =');
assert.throws(() => {
return new URLSearchParams('').get();
}, 'throws w/o arguments');
});
QUnit.test('URLSearchParams#getAll', assert => {
const { getAll } = URLSearchParams.prototype;
assert.isFunction(getAll);
assert.arity(getAll, 1);
assert.enumerable(URLSearchParams.prototype, 'getAll');
let params = new URLSearchParams('a=b&c=d');
assert.arrayEqual(params.getAll('a'), ['b']);
assert.arrayEqual(params.getAll('c'), ['d']);
assert.arrayEqual(params.getAll('e'), []);
params = new URLSearchParams('a=b&c=d&a=e');
assert.arrayEqual(params.getAll('a'), ['b', 'e']);
params = new URLSearchParams('=b&c=d');
assert.arrayEqual(params.getAll(''), ['b']);
params = new URLSearchParams('a=&c=d&a=e');
assert.arrayEqual(params.getAll('a'), ['', 'e']);
params = new URLSearchParams('a=1&a=2&a=3&a');
assert.arrayEqual(params.getAll('a'), ['1', '2', '3', ''], 'search params object has expected name "a" values');
params.set('a', 'one');
assert.arrayEqual(params.getAll('a'), ['one'], 'search params object has expected name "a" values');
assert.throws(() => {
return new URLSearchParams('').getAll();
}, 'throws w/o arguments');
});
QUnit.test('URLSearchParams#has', assert => {
const { has } = URLSearchParams.prototype;
assert.isFunction(has);
assert.arity(has, 1);
assert.enumerable(URLSearchParams.prototype, 'has');
let params = new URLSearchParams('a=b&c=d');
assert.true(params.has('a'));
assert.true(params.has('c'));
assert.false(params.has('e'));
params = new URLSearchParams('a=b&c=d&a=e');
assert.true(params.has('a'));
params = new URLSearchParams('=b&c=d');
assert.true(params.has(''));
params = new URLSearchParams('null=a');
assert.true(params.has(null));
params = new URLSearchParams('a=b&c=d&&');
params.append('first', 1);
params.append('first', 2);
assert.true(params.has('a'), 'search params object has name "a"');
assert.true(params.has('c'), 'search params object has name "c"');
assert.true(params.has('first'), 'search params object has name "first"');
assert.false(params.has('d'), 'search params object has no name "d"');
params.delete('first');
assert.false(params.has('first'), 'search params object has no name "first"');
params = new URLSearchParams('a=1&a=2&a=null&a=3&b=4');
assert.true(params.has('a', 2));
assert.true(params.has('a', null));
assert.false(params.has('a', 4));
assert.true(params.has('b', 4));
assert.false(params.has('b', null));
assert.true(params.has('b', undefined));
assert.false(params.has('c', undefined));
assert.throws(() => {
return new URLSearchParams('').has();
}, 'throws w/o arguments');
});
QUnit.test('URLSearchParams#set', assert => {
const { set } = URLSearchParams.prototype;
assert.isFunction(set);
assert.arity(set, 2);
assert.enumerable(URLSearchParams.prototype, 'set');
let params = new URLSearchParams('a=b&c=d');
params.set('a', 'B');
assert.same(String(params), 'a=B&c=d');
params = new URLSearchParams('a=b&c=d&a=e');
params.set('a', 'B');
assert.same(String(params), 'a=B&c=d');
params.set('e', 'f');
assert.same(String(params), 'a=B&c=d&e=f');
params = new URLSearchParams('a=1&a=2&a=3');
assert.true(params.has('a'), 'search params object has name "a"');
assert.same(params.get('a'), '1', 'search params object has name "a" with value "1"');
params.set('first', 4);
assert.true(params.has('a'), 'search params object has name "a"');
assert.same(params.get('a'), '1', 'search params object has name "a" with value "1"');
assert.same(String(params), 'a=1&a=2&a=3&first=4');
params.set('a', 4);
assert.true(params.has('a'), 'search params object has name "a"');
assert.same(params.get('a'), '4', 'search params object has name "a" with value "4"');
assert.same(String(params), 'a=4&first=4');
assert.throws(() => {
return new URLSearchParams('').set();
}, 'throws w/o arguments');
});
QUnit.test('URLSearchParams#sort', assert => {
const { sort } = URLSearchParams.prototype;
assert.isFunction(sort);
assert.arity(sort, 0);
assert.enumerable(URLSearchParams.prototype, 'sort');
let params = new URLSearchParams('a=1&b=4&a=3&b=2');
params.sort();
assert.same(String(params), 'a=1&a=3&b=4&b=2');
params.delete('a');
params.append('a', '0');
params.append('b', '0');
params.sort();
assert.same(String(params), 'a=0&b=4&b=2&b=0');
const testData = [
{
input: 'z=b&a=b&z=a&a=a',
output: [['a', 'b'], ['a', 'a'], ['z', 'b'], ['z', 'a']],
},
{
input: '\uFFFD=x&\uFFFC&\uFFFD=a',
output: [['\uFFFC', ''], ['\uFFFD', 'x'], ['\uFFFD', 'a']],
},
{
input: 'ffi&🌈', // 🌈 > code point, but < code unit because two code units
output: [['🌈', ''], ['ffi', '']],
},
{
input: 'é&e\uFFFD&e\u0301',
output: [['e\u0301', ''], ['e\uFFFD', ''], ['é', '']],
},
{
input: 'z=z&a=a&z=y&a=b&z=x&a=c&z=w&a=d&z=v&a=e&z=u&a=f&z=t&a=g',
output: [
['a', 'a'],
['a', 'b'],
['a', 'c'],
['a', 'd'],
['a', 'e'],
['a', 'f'],
['a', 'g'],
['z', 'z'],
['z', 'y'],
['z', 'x'],
['z', 'w'],
['z', 'v'],
['z', 'u'],
['z', 't'],
],
},
{
input: 'bbb&bb&aaa&aa=x&aa=y',
output: [['aa', 'x'], ['aa', 'y'], ['aaa', ''], ['bb', ''], ['bbb', '']],
},
{
input: 'z=z&=f&=t&=x',
output: [['', 'f'], ['', 't'], ['', 'x'], ['z', 'z']],
},
{
input: 'a🌈&a💩',
output: [['a🌈', ''], ['a💩', '']],
},
];
for (const { input, output } of testData) {
let i = 0;
params = new URLSearchParams(input);
params.sort();
params.forEach((value, key) => {
const [reqKey, reqValue] = output[i++];
assert.same(key, reqKey);
assert.same(value, reqValue);
});
i = 0;
const url = new URL(`?${ input }`, 'https://example/');
params = url.searchParams;
params.sort();
params.forEach((value, key) => {
const [reqKey, reqValue] = output[i++];
assert.same(key, reqKey);
assert.same(value, reqValue);
});
}
if (DESCRIPTORS) {
const url = new URL('http://example.com/?');
url.searchParams.sort();
assert.same(url.href, 'http://example.com/', 'Sorting non-existent params removes ? from URL');
assert.same(url.search, '', 'Sorting non-existent params removes ? from URL');
}
});
QUnit.test('URLSearchParams#toString', assert => {
const { toString } = URLSearchParams.prototype;
assert.isFunction(toString);
assert.arity(toString, 0);
let params = new URLSearchParams();
params.append('a', 'b c');
assert.same(String(params), 'a=b+c');
params.delete('a');
params.append('a b', 'c');
assert.same(String(params), 'a+b=c');
params = new URLSearchParams();
params.append('a', '');
assert.same(String(params), 'a=');
params.append('a', '');
assert.same(String(params), 'a=&a=');
params.append('', 'b');
assert.same(String(params), 'a=&a=&=b');
params.append('', '');
assert.same(String(params), 'a=&a=&=b&=');
params.append('', '');
assert.same(String(params), 'a=&a=&=b&=&=');
params = new URLSearchParams();
params.append('', 'b');
assert.same(String(params), '=b');
params.append('', 'b');
assert.same(String(params), '=b&=b');
params = new URLSearchParams();
params.append('', '');
assert.same(String(params), '=');
params.append('', '');
assert.same(String(params), '=&=');
params = new URLSearchParams();
params.append('a', 'b+c');
assert.same(String(params), 'a=b%2Bc');
params.delete('a');
params.append('a+b', 'c');
assert.same(String(params), 'a%2Bb=c');
params = new URLSearchParams();
params.append('=', 'a');
assert.same(String(params), '%3D=a');
params.append('b', '=');
assert.same(String(params), '%3D=a&b=%3D');
params = new URLSearchParams();
params.append('&', 'a');
assert.same(String(params), '%26=a');
params.append('b', '&');
assert.same(String(params), '%26=a&b=%26');
params = new URLSearchParams();
params.append('a', '\r');
assert.same(String(params), 'a=%0D');
params = new URLSearchParams();
params.append('a', '\n');
assert.same(String(params), 'a=%0A');
params = new URLSearchParams();
params.append('a', '\r\n');
assert.same(String(params), 'a=%0D%0A');
params = new URLSearchParams();
params.append('a', 'b%c');
assert.same(String(params), 'a=b%25c');
params.delete('a');
params.append('a%b', 'c');
assert.same(String(params), 'a%25b=c');
params = new URLSearchParams();
params.append('a', 'b\0c');
assert.same(String(params), 'a=b%00c');
params.delete('a');
params.append('a\0b', 'c');
assert.same(String(params), 'a%00b=c');
params = new URLSearchParams();
params.append('a', 'b\uD83D\uDCA9c');
assert.same(String(params), 'a=b%F0%9F%92%A9c');
params.delete('a');
params.append('a\uD83D\uDCA9b', 'c');
assert.same(String(params), 'a%F0%9F%92%A9b=c');
params = new URLSearchParams('a=b&c=d&&e&&');
assert.same(String(params), 'a=b&c=d&e=');
params = new URLSearchParams('a = b &a=b&c=d%20');
assert.same(String(params), 'a+=+b+&a=b&c=d+');
params = new URLSearchParams('a=&a=b');
assert.same(String(params), 'a=&a=b');
});
QUnit.test('URLSearchParams#forEach', assert => {
const { forEach } = URLSearchParams.prototype;
assert.isFunction(forEach);
assert.arity(forEach, 1);
assert.enumerable(URLSearchParams.prototype, 'forEach');
const expectedValues = { a: '1', b: '2', c: '3' };
let params = new URLSearchParams('a=1&b=2&c=3');
let result = '';
params.forEach((value, key, that) => {
assert.same(params.get(key), expectedValues[key]);
assert.same(value, expectedValues[key]);
assert.same(that, params);
result += key;
});
assert.same(result, 'abc');
new URL('http://a.b/c').searchParams.forEach(() => {
assert.avoid();
});
// fails in Chrome 66-
if (DESCRIPTORS) {
const url = new URL('http://a.b/c?a=1&b=2&c=3&d=4');
params = url.searchParams;
result = '';
params.forEach((val, key) => {
url.search = 'x=1&y=2&z=3';
result += key + val;
});
assert.same(result, 'a1y2z3');
}
// fails in Chrome 66-
params = new URLSearchParams('a=1&b=2&c=3');
result = '';
params.forEach((value, key) => {
params.delete('b');
result += key + value;
});
assert.same(result, 'a1c3');
});
QUnit.test('URLSearchParams#entries', assert => {
const { entries } = URLSearchParams.prototype;
assert.isFunction(entries);
assert.arity(entries, 0);
assert.enumerable(URLSearchParams.prototype, 'entries');
const expectedValues = { a: '1', b: '2', c: '3' };
let params = new URLSearchParams('a=1&b=2&c=3');
let iterator = params.entries();
let result = '';
let entry;
while (!(entry = iterator.next()).done) {
const [key, value] = entry.value;
assert.same(params.get(key), expectedValues[key]);
assert.same(value, expectedValues[key]);
result += key;
}
assert.same(result, 'abc');
assert.true(new URL('http://a.b/c').searchParams.entries().next().done, 'should be finished');
// fails in Chrome 66-
if (DESCRIPTORS) {
const url = new URL('http://a.b/c?a=1&b=2&c=3&d=4');
iterator = url.searchParams.entries();
result = '';
while (!(entry = iterator.next()).done) {
const [key, value] = entry.value;
url.search = 'x=1&y=2&z=3';
result += key + value;
}
assert.same(result, 'a1y2z3');
}
// fails in Chrome 66-
params = new URLSearchParams('a=1&b=2&c=3');
iterator = params.entries();
result = '';
while (!(entry = iterator.next()).done) {
params.delete('b');
const [key, value] = entry.value;
result += key + value;
}
assert.same(result, 'a1c3');
if (DESCRIPTORS) assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().entries()), 'next').enumerable, 'enumerable .next');
});
QUnit.test('URLSearchParams#keys', assert => {
const { keys } = URLSearchParams.prototype;
assert.isFunction(keys);
assert.arity(keys, 0);
assert.enumerable(URLSearchParams.prototype, 'keys');
let iterator = new URLSearchParams('a=1&b=2&c=3').keys();
let result = '';
let entry;
while (!(entry = iterator.next()).done) {
result += entry.value;
}
assert.same(result, 'abc');
assert.true(new URL('http://a.b/c').searchParams.keys().next().done, 'should be finished');
// fails in Chrome 66-
if (DESCRIPTORS) {
const url = new URL('http://a.b/c?a=1&b=2&c=3&d=4');
iterator = url.searchParams.keys();
result = '';
while (!(entry = iterator.next()).done) {
const key = entry.value;
url.search = 'x=1&y=2&z=3';
result += key;
}
assert.same(result, 'ayz');
}
// fails in Chrome 66-
const params = new URLSearchParams('a=1&b=2&c=3');
iterator = params.keys();
result = '';
while (!(entry = iterator.next()).done) {
params.delete('b');
const key = entry.value;
result += key;
}
assert.same(result, 'ac');
if (DESCRIPTORS) assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().keys()), 'next').enumerable, 'enumerable .next');
});
QUnit.test('URLSearchParams#values', assert => {
const { values } = URLSearchParams.prototype;
assert.isFunction(values);
assert.arity(values, 0);
assert.enumerable(URLSearchParams.prototype, 'values');
let iterator = new URLSearchParams('a=1&b=2&c=3').values();
let result = '';
let entry;
while (!(entry = iterator.next()).done) {
result += entry.value;
}
assert.same(result, '123');
assert.true(new URL('http://a.b/c').searchParams.values().next().done, 'should be finished');
// fails in Chrome 66-
if (DESCRIPTORS) {
const url = new URL('http://a.b/c?a=a&b=b&c=c&d=d');
iterator = url.searchParams.keys();
result = '';
while (!(entry = iterator.next()).done) {
const { value } = entry;
url.search = 'x=x&y=y&z=z';
result += value;
}
assert.same(result, 'ayz');
}
// fails in Chrome 66-
const params = new URLSearchParams('a=1&b=2&c=3');
iterator = params.values();
result = '';
while (!(entry = iterator.next()).done) {
params.delete('b');
const key = entry.value;
result += key;
}
assert.same(result, '13');
if (DESCRIPTORS) assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().values()), 'next').enumerable, 'enumerable .next');
});
QUnit.test('URLSearchParams#@@iterator', assert => {
const entries = URLSearchParams.prototype[Symbol.iterator];
assert.isFunction(entries);
assert.arity(entries, 0);
assert.same(entries, URLSearchParams.prototype.entries);
const expectedValues = { a: '1', b: '2', c: '3' };
let params = new URLSearchParams('a=1&b=2&c=3');
let iterator = params[Symbol.iterator]();
let result = '';
let entry;
while (!(entry = iterator.next()).done) {
const [key, value] = entry.value;
assert.same(params.get(key), expectedValues[key]);
assert.same(value, expectedValues[key]);
result += key;
}
assert.same(result, 'abc');
assert.true(new URL('http://a.b/c').searchParams[Symbol.iterator]().next().done, 'should be finished');
// fails in Chrome 66-
if (DESCRIPTORS) {
const url = new URL('http://a.b/c?a=1&b=2&c=3&d=4');
iterator = url.searchParams[Symbol.iterator]();
result = '';
while (!(entry = iterator.next()).done) {
const [key, value] = entry.value;
url.search = 'x=1&y=2&z=3';
result += key + value;
}
assert.same(result, 'a1y2z3');
}
// fails in Chrome 66-
params = new URLSearchParams('a=1&b=2&c=3');
iterator = params[Symbol.iterator]();
result = '';
while (!(entry = iterator.next()).done) {
params.delete('b');
const [key, value] = entry.value;
result += key + value;
}
assert.same(result, 'a1c3');
if (DESCRIPTORS) assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams()[Symbol.iterator]()), 'next').enumerable, 'enumerable .next');
});
QUnit.test('URLSearchParams#size', assert => {
const params = new URLSearchParams('a=1&b=2&b=3');
assert.true('size' in params);
assert.same(params.size, 3);
if (DESCRIPTORS) {
assert.true('size' in URLSearchParams.prototype);
const { enumerable, configurable, get } = getOwnPropertyDescriptor(URLSearchParams.prototype, 'size');
assert.true(enumerable, 'enumerable');
assert.true(configurable, 'configurable');
assert.throws(() => get.call([]));
}
});
core-js-3.33.2/tests/unit-pure/web.url.can-parse.js 0000664 0000000 0000000 00000003145 14517762213 0022035 0 ustar 00root root 0000000 0000000 import canParse from 'core-js-pure/stable/url/can-parse';
QUnit.test('URL.canParse', assert => {
assert.isFunction(canParse);
assert.arity(canParse, 1);
assert.name(canParse, 'canParse');
assert.false(canParse(undefined), 'undefined');
assert.false(canParse(undefined, undefined), 'undefined, undefined');
assert.true(canParse('q:w'), 'q:w');
assert.true(canParse('q:w', undefined), 'q:w, undefined');
// assert.false(canParse(undefined, 'q:w'), 'undefined, q:w'); // fails in Chromium on Windows
assert.true(canParse('q:/w'), 'q:/w');
assert.true(canParse('q:/w', undefined), 'q:/w, undefined');
assert.true(canParse(undefined, 'q:/w'), 'undefined, q:/w');
assert.false(canParse('https://login:password@examp:le.com:8080/?a=1&b=2&a=3&c=4#fragment'), 'https://login:password@examp:le.com:8080/?a=1&b=2&a=3&c=4#fragment');
assert.true(canParse('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'), 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment');
assert.true(canParse('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment', undefined), 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment, undefined');
assert.true(canParse('x', 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'), 'x, https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment');
assert.throws(() => canParse(), 'no args');
assert.throws(() => canParse({ toString() { throw new Error('thrower'); } }), 'conversion thrower #1');
assert.throws(() => canParse('q:w', { toString() { throw new Error('thrower'); } }), 'conversion thrower #2');
});
core-js-3.33.2/tests/unit-pure/web.url.js 0000664 0000000 0000000 00000067347 14517762213 0020203 0 ustar 00root root 0000000 0000000 /* eslint-disable es/no-object-getownpropertydescriptor, unicorn/relative-url-style -- required for testing */
import { DESCRIPTORS, NODE } from '../helpers/constants.js';
import urlTestData from '../wpt-url-resources/urltestdata.js';
import settersTestData from '../wpt-url-resources/setters.js';
import toASCIITestData from '../wpt-url-resources/toascii.js';
import URL from 'core-js-pure/stable/url';
import URLSearchParams from 'core-js-pure/stable/url-search-params';
const { hasOwnProperty } = Object.prototype;
QUnit.test('URL constructor', assert => {
assert.isFunction(URL);
if (!NODE) assert.arity(URL, 1);
assert.same(String(new URL('http://www.domain.com/a/b')), 'http://www.domain.com/a/b');
assert.same(String(new URL('/c/d', 'http://www.domain.com/a/b')), 'http://www.domain.com/c/d');
assert.same(String(new URL('b/c', 'http://www.domain.com/a/b')), 'http://www.domain.com/a/b/c');
assert.same(String(new URL('b/c', new URL('http://www.domain.com/a/b'))), 'http://www.domain.com/a/b/c');
assert.same(String(new URL({ toString: () => 'https://example.org/' })), 'https://example.org/');
assert.same(String(new URL('nonspecial://example.com/')), 'nonspecial://example.com/');
assert.same(String(new URL('https://測試')), 'https://xn--g6w251d/', 'unicode parsing');
assert.same(String(new URL('https://xxпривет.тест')), 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing');
assert.same(String(new URL('https://xxПРИВЕТ.тест')), 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing');
assert.same(String(new URL('http://Example.com/', 'https://example.org/')), 'http://example.com/');
assert.same(String(new URL('https://Example.com/', 'https://example.org/')), 'https://example.com/');
assert.same(String(new URL('nonspecial://Example.com/', 'https://example.org/')), 'nonspecial://Example.com/');
assert.same(String(new URL('http:Example.com/', 'https://example.org/')), 'http://example.com/');
assert.same(String(new URL('https:Example.com/', 'https://example.org/')), 'https://example.org/Example.com/');
assert.same(String(new URL('nonspecial:Example.com/', 'https://example.org/')), 'nonspecial:Example.com/');
assert.same(String(new URL('http://0300.168.0xF0')), 'http://192.168.0.240/');
assert.same(String(new URL('http://[20:0:0:1:0:0:0:ff]')), 'http://[20:0:0:1::ff]/');
// assert.same(String(new URL('http://257.168.0xF0')), 'http://257.168.0xf0/', 'incorrect IPv4 parsed as host'); // TypeError in Chrome and Safari
assert.same(String(new URL('http://0300.168.0xG0')), 'http://0300.168.0xg0/', 'incorrect IPv4 parsed as host');
assert.same(String(new URL('file:///var/log/system.log')), 'file:///var/log/system.log', 'file scheme');
// assert.same(String(new URL('file://nnsc.nsf.net/bar/baz')), 'file://nnsc.nsf.net/bar/baz', 'file scheme'); // 'file:///bar/baz' in FF
// assert.same(String(new URL('file://localhost/bar/baz')), 'file:///bar/baz', 'file scheme'); // 'file://localhost/bar/baz' in Chrome
assert.throws(() => new URL(), 'TypeError: Failed to construct URL: 1 argument required, but only 0 present.');
assert.throws(() => new URL(''), 'TypeError: Failed to construct URL: Invalid URL');
// Node 19.7
// https://github.com/nodejs/node/issues/46755
// assert.throws(() => new URL('', 'about:blank'), 'TypeError: Failed to construct URL: Invalid URL');
assert.throws(() => new URL('abc'), 'TypeError: Failed to construct URL: Invalid URL');
assert.throws(() => new URL('//abc'), 'TypeError: Failed to construct URL: Invalid URL');
assert.throws(() => new URL('http:///www.domain.com/', 'abc'), 'TypeError: Failed to construct URL: Invalid base URL');
assert.throws(() => new URL('http:///www.domain.com/', null), 'TypeError: Failed to construct URL: Invalid base URL');
assert.throws(() => new URL('//abc', null), 'TypeError: Failed to construct URL: Invalid base URL');
assert.throws(() => new URL('http://[20:0:0:1:0:0:0:ff'), 'incorrect IPv6');
assert.throws(() => new URL('http://[20:0:0:1:0:0:0:fg]'), 'incorrect IPv6');
// assert.throws(() => new URL('http://a%b'), 'forbidden host code point'); // no error in FF
assert.throws(() => new URL('1http://zloirock.ru'), 'incorrect scheme');
});
QUnit.test('URL#href', assert => {
let url = new URL('http://zloirock.ru/');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'href'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'href');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
assert.same(typeof descriptor.set, 'function');
}
assert.same(url.href, 'http://zloirock.ru/');
if (DESCRIPTORS) {
url.searchParams.append('foo', 'bar');
assert.same(url.href, 'http://zloirock.ru/?foo=bar');
url = new URL('http://zloirock.ru/foo');
url.href = 'https://測試';
assert.same(url.href, 'https://xn--g6w251d/', 'unicode parsing');
assert.same(String(url), 'https://xn--g6w251d/', 'unicode parsing');
url = new URL('http://zloirock.ru/foo');
url.href = 'https://xxпривет.тест';
assert.same(url.href, 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing');
assert.same(String(url), 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing');
url = new URL('http://zloirock.ru/foo');
url.href = 'https://xxПРИВЕТ.тест';
assert.same(url.href, 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing');
assert.same(String(url), 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing');
url = new URL('http://zloirock.ru/');
url.href = 'http://0300.168.0xF0';
assert.same(url.href, 'http://192.168.0.240/');
assert.same(String(url), 'http://192.168.0.240/');
url = new URL('http://zloirock.ru/');
url.href = 'http://[20:0:0:1:0:0:0:ff]';
assert.same(url.href, 'http://[20:0:0:1::ff]/');
assert.same(String(url), 'http://[20:0:0:1::ff]/');
// url = new URL('http://zloirock.ru/');
// url.href = 'http://257.168.0xF0'; // TypeError and Safari
// assert.same(url.href, 'http://257.168.0xf0/', 'incorrect IPv4 parsed as host'); // `F` instead of `f` in Chrome
// assert.same(String(url), 'http://257.168.0xf0/', 'incorrect IPv4 parsed as host'); // `F` instead of `f` in Chrome
url = new URL('http://zloirock.ru/');
url.href = 'http://0300.168.0xG0';
assert.same(url.href, 'http://0300.168.0xg0/', 'incorrect IPv4 parsed as host');
assert.same(String(url), 'http://0300.168.0xg0/', 'incorrect IPv4 parsed as host');
url = new URL('http://192.168.0.240/');
url.href = 'file:///var/log/system.log';
assert.same(url.href, 'file:///var/log/system.log', 'file -> ip');
assert.same(String(url), 'file:///var/log/system.log', 'file -> ip');
url = new URL('file:///var/log/system.log');
url.href = 'http://0300.168.0xF0';
// Node 19.7
// https://github.com/nodejs/node/issues/46755
// assert.same(url.href, 'http://192.168.0.240/', 'file -> http');
// assert.same(String(url), 'http://192.168.0.240/', 'file -> http');
// assert.throws(() => new URL('http://zloirock.ru/').href = undefined, 'incorrect URL'); // no error in Chrome
// assert.throws(() => new URL('http://zloirock.ru/').href = '', 'incorrect URL'); // no error in Chrome
// assert.throws(() => new URL('http://zloirock.ru/').href = 'abc', 'incorrect URL'); // no error in Chrome
// assert.throws(() => new URL('http://zloirock.ru/').href = '//abc', 'incorrect URL'); // no error in Chrome
// assert.throws(() => new URL('http://zloirock.ru/').href = 'http://[20:0:0:1:0:0:0:ff', 'incorrect IPv6'); // no error in Chrome
// assert.throws(() => new URL('http://zloirock.ru/').href = 'http://[20:0:0:1:0:0:0:fg]', 'incorrect IPv6'); // no error in Chrome
// assert.throws(() => new URL('http://zloirock.ru/').href = 'http://a%b', 'forbidden host code point'); // no error in Chrome and FF
// assert.throws(() => new URL('http://zloirock.ru/').href = '1http://zloirock.ru', 'incorrect scheme'); // no error in Chrome
}
});
QUnit.test('URL#origin', assert => {
const url = new URL('http://es6.zloirock.ru/tests.html');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'origin'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'origin');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
}
assert.same(url.origin, 'http://es6.zloirock.ru');
assert.same(new URL('https://測試/tests').origin, 'https://xn--g6w251d');
});
QUnit.test('URL#protocol', assert => {
let url = new URL('http://zloirock.ru/');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'protocol'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'protocol');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
assert.same(typeof descriptor.set, 'function');
}
assert.same(url.protocol, 'http:');
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru/');
url.protocol = 'https';
assert.same(url.protocol, 'https:');
assert.same(String(url), 'https://zloirock.ru/');
// https://nodejs.org/api/url.html#url_special_schemes
// url = new URL('http://zloirock.ru/');
// url.protocol = 'fish';
// assert.same(url.protocol, 'http:');
// assert.same(url.href, 'http://zloirock.ru/');
// assert.same(String(url), 'http://zloirock.ru/');
url = new URL('http://zloirock.ru/');
url.protocol = '1http';
assert.same(url.protocol, 'http:');
assert.same(url.href, 'http://zloirock.ru/', 'incorrect scheme');
assert.same(String(url), 'http://zloirock.ru/', 'incorrect scheme');
}
});
QUnit.test('URL#username', assert => {
let url = new URL('http://zloirock.ru/');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'username'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'username');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
assert.same(typeof descriptor.set, 'function');
}
assert.same(url.username, '');
url = new URL('http://username@zloirock.ru/');
assert.same(url.username, 'username');
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru/');
url.username = 'username';
assert.same(url.username, 'username');
assert.same(String(url), 'http://username@zloirock.ru/');
}
});
QUnit.test('URL#password', assert => {
let url = new URL('http://zloirock.ru/');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'password'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'password');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
assert.same(typeof descriptor.set, 'function');
}
assert.same(url.password, '');
url = new URL('http://username:password@zloirock.ru/');
assert.same(url.password, 'password');
// url = new URL('http://:password@zloirock.ru/'); // TypeError in FF
// assert.same(url.password, 'password');
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru/');
url.username = 'username';
url.password = 'password';
assert.same(url.password, 'password');
assert.same(String(url), 'http://username:password@zloirock.ru/');
// url = new URL('http://zloirock.ru/');
// url.password = 'password';
// assert.same(url.password, 'password'); // '' in FF
// assert.same(String(url), 'http://:password@zloirock.ru/'); // 'http://zloirock.ru/' in FF
}
});
QUnit.test('URL#host', assert => {
let url = new URL('http://zloirock.ru:81/path');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'host'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'host');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
assert.same(typeof descriptor.set, 'function');
}
assert.same(url.host, 'zloirock.ru:81');
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru:81/path');
url.host = 'example.com:82';
assert.same(url.host, 'example.com:82');
assert.same(String(url), 'http://example.com:82/path');
// url = new URL('http://zloirock.ru:81/path');
// url.host = 'other?domain.com';
// assert.same(String(url), 'http://other:81/path'); // 'http://other/?domain.com/path' in Safari
url = new URL('https://www.mydomain.com:8080/path/');
url.host = 'www.otherdomain.com:80';
assert.same(url.href, 'https://www.otherdomain.com:80/path/', 'set default port for another protocol');
// url = new URL('https://www.mydomain.com:8080/path/');
// url.host = 'www.otherdomain.com:443';
// assert.same(url.href, 'https://www.otherdomain.com/path/', 'set default port');
url = new URL('http://zloirock.ru/foo');
url.host = '測試';
assert.same(url.host, 'xn--g6w251d', 'unicode parsing');
assert.same(String(url), 'http://xn--g6w251d/foo', 'unicode parsing');
url = new URL('http://zloirock.ru/foo');
url.host = 'xxпривет.тест';
assert.same(url.host, 'xn--xx-flcmn5bht.xn--e1aybc', 'unicode parsing');
assert.same(String(url), 'http://xn--xx-flcmn5bht.xn--e1aybc/foo', 'unicode parsing');
url = new URL('http://zloirock.ru/foo');
url.host = 'xxПРИВЕТ.тест';
assert.same(url.host, 'xn--xx-flcmn5bht.xn--e1aybc', 'unicode parsing');
assert.same(String(url), 'http://xn--xx-flcmn5bht.xn--e1aybc/foo', 'unicode parsing');
url = new URL('http://zloirock.ru/foo');
url.host = '0300.168.0xF0';
assert.same(url.host, '192.168.0.240');
assert.same(String(url), 'http://192.168.0.240/foo');
// url = new URL('http://zloirock.ru/foo');
// url.host = '[20:0:0:1:0:0:0:ff]';
// assert.same(url.host, '[20:0:0:1::ff]'); // ':0' in Chrome, 'zloirock.ru' in Safari
// assert.same(String(url), 'http://[20:0:0:1::ff]/foo'); // 'http://[20:0/foo' in Chrome, 'http://zloirock.ru/foo' in Safari
// url = new URL('file:///var/log/system.log');
// url.host = 'nnsc.nsf.net'; // does not work in FF
// assert.same(url.hostname, 'nnsc.nsf.net', 'file');
// assert.same(String(url), 'file://nnsc.nsf.net/var/log/system.log', 'file');
// url = new URL('http://zloirock.ru/');
// url.host = '[20:0:0:1:0:0:0:ff';
// assert.same(url.host, 'zloirock.ru', 'incorrect IPv6'); // ':0' in Chrome
// assert.same(String(url), 'http://zloirock.ru/', 'incorrect IPv6'); // 'http://[20:0/' in Chrome
// url = new URL('http://zloirock.ru/');
// url.host = '[20:0:0:1:0:0:0:fg]';
// assert.same(url.host, 'zloirock.ru', 'incorrect IPv6'); // ':0' in Chrome
// assert.same(String(url), 'http://zloirock.ru/', 'incorrect IPv6'); // 'http://[20:0/' in Chrome
// url = new URL('http://zloirock.ru/');
// url.host = 'a%b';
// assert.same(url.host, 'zloirock.ru', 'forbidden host code point'); // '' in Chrome, 'a%b' in FF
// assert.same(String(url), 'http://zloirock.ru/', 'forbidden host code point'); // 'http://a%25b/' in Chrome, 'http://a%b/' in FF
}
});
QUnit.test('URL#hostname', assert => {
let url = new URL('http://zloirock.ru:81/');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'hostname'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'hostname');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
assert.same(typeof descriptor.set, 'function');
}
assert.same(url.hostname, 'zloirock.ru');
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru:81/');
url.hostname = 'example.com';
assert.same(url.hostname, 'example.com');
assert.same(String(url), 'http://example.com:81/');
// url = new URL('http://zloirock.ru:81/');
// url.hostname = 'example.com:82';
// assert.same(url.hostname, 'example.com'); // '' in Chrome
// assert.same(String(url), 'http://example.com:81/'); // 'http://example.com:82:81/' in Chrome
url = new URL('http://zloirock.ru/foo');
url.hostname = '測試';
assert.same(url.hostname, 'xn--g6w251d', 'unicode parsing');
assert.same(String(url), 'http://xn--g6w251d/foo', 'unicode parsing');
url = new URL('http://zloirock.ru/foo');
url.hostname = 'xxпривет.тест';
assert.same(url.hostname, 'xn--xx-flcmn5bht.xn--e1aybc', 'unicode parsing');
assert.same(String(url), 'http://xn--xx-flcmn5bht.xn--e1aybc/foo', 'unicode parsing');
url = new URL('http://zloirock.ru/foo');
url.hostname = 'xxПРИВЕТ.тест';
assert.same(url.hostname, 'xn--xx-flcmn5bht.xn--e1aybc', 'unicode parsing');
assert.same(String(url), 'http://xn--xx-flcmn5bht.xn--e1aybc/foo', 'unicode parsing');
url = new URL('http://zloirock.ru/foo');
url.hostname = '0300.168.0xF0';
assert.same(url.hostname, '192.168.0.240');
assert.same(String(url), 'http://192.168.0.240/foo');
// url = new URL('http://zloirock.ru/foo');
// url.hostname = '[20:0:0:1:0:0:0:ff]';
// assert.same(url.hostname, '[20:0:0:1::ff]'); // 'zloirock.ru' in Safari
// assert.same(String(url), 'http://[20:0:0:1::ff]/foo'); // 'http://zloirock.ru/foo' in Safari
// url = new URL('file:///var/log/system.log');
// url.hostname = 'nnsc.nsf.net'; // does not work in FF
// assert.same(url.hostname, 'nnsc.nsf.net', 'file');
// assert.same(String(url), 'file://nnsc.nsf.net/var/log/system.log', 'file');
// url = new URL('http://zloirock.ru/');
// url.hostname = '[20:0:0:1:0:0:0:ff';
// assert.same(url.hostname, 'zloirock.ru', 'incorrect IPv6'); // '' in Chrome
// assert.same(String(url), 'http://zloirock.ru/', 'incorrect IPv6'); // 'http://[20:0:0:1:0:0:0:ff' in Chrome
// url = new URL('http://zloirock.ru/');
// url.hostname = '[20:0:0:1:0:0:0:fg]';
// assert.same(url.hostname, 'zloirock.ru', 'incorrect IPv6'); // '' in Chrome
// assert.same(String(url), 'http://zloirock.ru/', 'incorrect IPv6'); // 'http://[20:0:0:1:0:0:0:ff/' in Chrome
// url = new URL('http://zloirock.ru/');
// url.hostname = 'a%b';
// assert.same(url.hostname, 'zloirock.ru', 'forbidden host code point'); // '' in Chrome, 'a%b' in FF
// assert.same(String(url), 'http://zloirock.ru/', 'forbidden host code point'); // 'http://a%25b/' in Chrome, 'http://a%b/' in FF
}
});
QUnit.test('URL#port', assert => {
let url = new URL('http://zloirock.ru:1337/');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'port'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'port');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
assert.same(typeof descriptor.set, 'function');
}
assert.same(url.port, '1337');
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru/');
url.port = 80;
assert.same(url.port, '');
assert.same(String(url), 'http://zloirock.ru/');
url.port = 1337;
assert.same(url.port, '1337');
assert.same(String(url), 'http://zloirock.ru:1337/');
// url.port = 'abcd';
// assert.same(url.port, '1337'); // '0' in Chrome
// assert.same(String(url), 'http://zloirock.ru:1337/'); // 'http://zloirock.ru:0/' in Chrome
// url.port = '5678abcd';
// assert.same(url.port, '5678'); // '1337' in FF
// assert.same(String(url), 'http://zloirock.ru:5678/'); // 'http://zloirock.ru:1337/"' in FF
url.port = 1234.5678;
assert.same(url.port, '1234');
assert.same(String(url), 'http://zloirock.ru:1234/');
// url.port = 1e10;
// assert.same(url.port, '1234'); // '0' in Chrome
// assert.same(String(url), 'http://zloirock.ru:1234/'); // 'http://zloirock.ru:0/' in Chrome
}
});
QUnit.test('URL#pathname', assert => {
let url = new URL('http://zloirock.ru/foo/bar');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'pathname'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'pathname');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
assert.same(typeof descriptor.set, 'function');
}
assert.same(url.pathname, '/foo/bar');
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru/');
url.pathname = 'bar/baz';
assert.same(url.pathname, '/bar/baz');
assert.same(String(url), 'http://zloirock.ru/bar/baz');
}
});
QUnit.test('URL#search', assert => {
let url = new URL('http://zloirock.ru/');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'search'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'search');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
assert.same(typeof descriptor.set, 'function');
}
assert.same(url.search, '');
url = new URL('http://zloirock.ru/?foo=bar');
assert.same(url.search, '?foo=bar');
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru/?');
assert.same(url.search, '');
assert.same(String(url), 'http://zloirock.ru/?');
url.search = 'foo=bar';
assert.same(url.search, '?foo=bar');
assert.same(String(url), 'http://zloirock.ru/?foo=bar');
url.search = '?bar=baz';
assert.same(url.search, '?bar=baz');
assert.same(String(url), 'http://zloirock.ru/?bar=baz');
url.search = '';
assert.same(url.search, '');
assert.same(String(url), 'http://zloirock.ru/');
}
});
QUnit.test('URL#searchParams', assert => {
let url = new URL('http://zloirock.ru/?foo=bar&bar=baz');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'searchParams'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'searchParams');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
}
assert.true(url.searchParams instanceof URLSearchParams);
assert.same(url.searchParams.get('foo'), 'bar');
assert.same(url.searchParams.get('bar'), 'baz');
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru/');
url.searchParams.append('foo', 'bar');
assert.same(String(url), 'http://zloirock.ru/?foo=bar');
url = new URL('http://zloirock.ru/');
url.search = 'foo=bar';
assert.same(url.searchParams.get('foo'), 'bar');
url = new URL('http://zloirock.ru/?foo=bar&bar=baz');
url.search = '';
assert.false(url.searchParams.has('foo'));
}
});
QUnit.test('URL#hash', assert => {
let url = new URL('http://zloirock.ru/');
if (DESCRIPTORS) {
assert.false(hasOwnProperty.call(url, 'hash'));
const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'hash');
assert.true(descriptor.enumerable);
assert.true(descriptor.configurable);
assert.same(typeof descriptor.get, 'function');
assert.same(typeof descriptor.set, 'function');
}
assert.same(url.hash, '');
url = new URL('http://zloirock.ru/#foo');
assert.same(url.hash, '#foo');
url = new URL('http://zloirock.ru/#');
assert.same(url.hash, '');
assert.same(String(url), 'http://zloirock.ru/#');
if (DESCRIPTORS) {
url = new URL('http://zloirock.ru/#');
url.hash = 'foo';
assert.same(url.hash, '#foo');
assert.same(String(url), 'http://zloirock.ru/#foo');
url.hash = '';
assert.same(url.hash, '');
assert.same(String(url), 'http://zloirock.ru/');
// url.hash = '#';
// assert.same(url.hash, '');
// assert.same(String(url), 'http://zloirock.ru/'); // 'http://zloirock.ru/#' in FF
url.hash = '#foo';
assert.same(url.hash, '#foo');
assert.same(String(url), 'http://zloirock.ru/#foo');
url.hash = '#foo#bar';
assert.same(url.hash, '#foo#bar');
assert.same(String(url), 'http://zloirock.ru/#foo#bar');
url = new URL('http://zloirock.ru/');
url.hash = 'абa';
assert.same(url.hash, '#%D0%B0%D0%B1a');
// url = new URL('http://zloirock.ru/');
// url.hash = '\udc01\ud802a';
// assert.same(url.hash, '#%EF%BF%BD%EF%BF%BDa', 'unmatched surrogates');
}
});
QUnit.test('URL#toJSON', assert => {
const { toJSON } = URL.prototype;
assert.isFunction(toJSON);
assert.arity(toJSON, 0);
assert.enumerable(URL.prototype, 'toJSON');
const url = new URL('http://zloirock.ru/');
assert.same(url.toJSON(), 'http://zloirock.ru/');
if (DESCRIPTORS) {
url.searchParams.append('foo', 'bar');
assert.same(url.toJSON(), 'http://zloirock.ru/?foo=bar');
}
});
QUnit.test('URL#toString', assert => {
const { toString } = URL.prototype;
assert.isFunction(toString);
assert.arity(toString, 0);
assert.enumerable(URL.prototype, 'toString');
const url = new URL('http://zloirock.ru/');
assert.same(url.toString(), 'http://zloirock.ru/');
if (DESCRIPTORS) {
url.searchParams.append('foo', 'bar');
assert.same(url.toString(), 'http://zloirock.ru/?foo=bar');
}
});
QUnit.test('URL.sham', assert => {
assert.same(URL.sham, DESCRIPTORS ? undefined : true);
});
// `core-js` URL implementation pass all (exclude some encoding-related) tests
// from the next 3 test cases, but URLs from all of popular browsers fail a serious part of tests.
// Replacing all of them does not looks like a good idea, so next test cases disabled by default.
// see https://github.com/web-platform-tests/wpt/blob/master/url
QUnit.skip('WPT URL constructor tests', assert => {
for (const expected of urlTestData) {
if (typeof expected == 'string') continue;
const name = `Parsing: <${ expected.input }> against <${ expected.base }>`;
if (expected.failure) {
assert.throws(() => new URL(expected.input, expected.base || 'about:blank'), name);
} else {
const url = new URL(expected.input, expected.base || 'about:blank');
assert.same(url.href, expected.href, `${ name }: href`);
assert.same(url.protocol, expected.protocol, `${ name }: protocol`);
assert.same(url.username, expected.username, `${ name }: username`);
assert.same(url.password, expected.password, `${ name }: password`);
assert.same(url.host, expected.host, `${ name }: host`);
assert.same(url.hostname, expected.hostname, `${ name }: hostname`);
assert.same(url.port, expected.port, `${ name }: port`);
assert.same(url.pathname, expected.pathname, `${ name }: pathname`);
assert.same(url.search, expected.search, `${ name }: search`);
if ('searchParams' in expected) {
assert.same(url.searchParams.toString(), expected.searchParams, `${ name }: searchParams`);
}
assert.same(url.hash, expected.hash, `${ name }: hash`);
if ('origin' in expected) {
assert.same(url.origin, expected.origin, `${ name }: origin`);
}
}
}
});
// see https://github.com/web-platform-tests/wpt/blob/master/url
if (DESCRIPTORS) QUnit.skip('WPT URL setters tests', assert => {
for (const setter in settersTestData) {
const testCases = settersTestData[setter];
for (const { href, newValue, comment, expected } of testCases) {
let name = `Setting <${ href }>.${ setter } = '${ newValue }'.`;
if (comment) name += ` ${ comment }`;
const url = new URL(href);
url[setter] = newValue;
for (const attribute in expected) {
assert.same(url[attribute], expected[attribute], name);
}
}
}
});
// see https://github.com/web-platform-tests/wpt/blob/master/url
QUnit.skip('WPT conversion to ASCII tests', assert => {
for (const { comment, input, output } of toASCIITestData) {
let name = `Parsing: <${ input }>`;
if (comment) name += ` ${ comment }`;
if (output === null) {
assert.throws(() => new URL(`https://${ input }/x`), name);
} else {
const url = new URL(`https://${ input }/x`);
assert.same(url.host, output, name);
assert.same(url.hostname, output, name);
assert.same(url.pathname, '/x', name);
assert.same(url.href, `https://${ output }/x`, name);
}
}
});
core-js-3.33.2/tests/worker/ 0000775 0000000 0000000 00000000000 14517762213 0015627 5 ustar 00root root 0000000 0000000 core-js-3.33.2/tests/worker/index.html 0000664 0000000 0000000 00000000153 14517762213 0017623 0 ustar 00root root 0000000 0000000
Worker test
core-js-3.33.2/tests/worker/runner.js 0000664 0000000 0000000 00000000456 14517762213 0017503 0 ustar 00root root 0000000 0000000 'use strict';
importScripts('../../packages/core-js-bundle/index.js');
postMessage(typeof core != 'undefined');
setImmediate(function () {
postMessage('setImmediate');
});
// eslint-disable-next-line es/no-promise -- safe
Promise.resolve().then(function () {
postMessage('Promise.resolve');
});
core-js-3.33.2/tests/worker/test.js 0000664 0000000 0000000 00000000506 14517762213 0017145 0 ustar 00root root 0000000 0000000 'use strict';
var worker = new Worker('./worker/runner.js');
worker.addEventListener('error', function (e) {
// eslint-disable-next-line no-console -- output
console.error(e);
});
worker.addEventListener('message', function (message) {
// eslint-disable-next-line no-console -- output
console.log(message.data);
});
core-js-3.33.2/tests/wpt-url-resources/ 0000775 0000000 0000000 00000000000 14517762213 0017740 5 ustar 00root root 0000000 0000000 core-js-3.33.2/tests/wpt-url-resources/setters.js 0000664 0000000 0000000 00000126426 14517762213 0022002 0 ustar 00root root 0000000 0000000 // Copyright © web-platform-tests contributors
// Originally from https://github.com/web-platform-tests/wpt
// Available under the 3-Clause BSD License https://github.com/web-platform-tests/wpt/blob/master/LICENSE.md
/* eslint-disable no-script-url -- required for testing */
export default {
protocol: [
{
comment: 'The empty string is not a valid scheme. Setter leaves the URL unchanged.',
href: 'a://example.net',
newValue: '',
expected: {
href: 'a://example.net',
protocol: 'a:',
},
},
{
href: 'a://example.net',
newValue: 'b',
expected: {
href: 'b://example.net',
protocol: 'b:',
},
},
{
href: 'javascript:alert(1)',
newValue: 'defuse',
expected: {
href: 'defuse:alert(1)',
protocol: 'defuse:',
},
},
{
comment: 'Upper-case ASCII is lower-cased',
href: 'a://example.net',
newValue: 'B',
expected: {
href: 'b://example.net',
protocol: 'b:',
},
},
{
comment: 'Non-ASCII is rejected',
href: 'a://example.net',
newValue: 'é',
expected: {
href: 'a://example.net',
protocol: 'a:',
},
},
{
comment: 'No leading digit',
href: 'a://example.net',
newValue: '0b',
expected: {
href: 'a://example.net',
protocol: 'a:',
},
},
{
comment: 'No leading punctuation',
href: 'a://example.net',
newValue: '+b',
expected: {
href: 'a://example.net',
protocol: 'a:',
},
},
{
href: 'a://example.net',
newValue: 'bC0+-.',
expected: {
href: 'bc0+-.://example.net',
protocol: 'bc0+-.:',
},
},
{
comment: 'Only some punctuation is acceptable',
href: 'a://example.net',
newValue: 'b,c',
expected: {
href: 'a://example.net',
protocol: 'a:',
},
},
{
comment: 'Non-ASCII is rejected',
href: 'a://example.net',
newValue: 'bé',
expected: {
href: 'a://example.net',
protocol: 'a:',
},
},
{
comment: 'Can’t switch from URL containing username/password/port to file',
href: 'http://test@example.net',
newValue: 'file',
expected: {
href: 'http://test@example.net/',
protocol: 'http:',
},
},
{
href: 'wss://x:x@example.net:1234',
newValue: 'file',
expected: {
href: 'wss://x:x@example.net:1234/',
protocol: 'wss:',
},
},
{
comment: 'Can’t switch from file URL with no host',
href: 'file://localhost/',
newValue: 'http',
expected: {
href: 'file:///',
protocol: 'file:',
},
},
{
href: 'file:',
newValue: 'wss',
expected: {
href: 'file:///',
protocol: 'file:',
},
},
{
comment: 'Can’t switch from special scheme to non-special',
href: 'http://example.net',
newValue: 'b',
expected: {
href: 'http://example.net/',
protocol: 'http:',
},
},
{
href: 'file://hi/path',
newValue: 's',
expected: {
href: 'file://hi/path',
protocol: 'file:',
},
},
{
href: 'https://example.net',
newValue: 's',
expected: {
href: 'https://example.net/',
protocol: 'https:',
},
},
{
href: 'ftp://example.net',
newValue: 'test',
expected: {
href: 'ftp://example.net/',
protocol: 'ftp:',
},
},
{
comment: 'Cannot-be-a-base URL doesn’t have a host, but URL in a special scheme must.',
href: 'mailto:me@example.net',
newValue: 'http',
expected: {
href: 'mailto:me@example.net',
protocol: 'mailto:',
},
},
{
comment: 'Can’t switch from non-special scheme to special',
href: 'ssh://me@example.net',
newValue: 'http',
expected: {
href: 'ssh://me@example.net',
protocol: 'ssh:',
},
},
{
href: 'ssh://me@example.net',
newValue: 'file',
expected: {
href: 'ssh://me@example.net',
protocol: 'ssh:',
},
},
{
href: 'ssh://example.net',
newValue: 'file',
expected: {
href: 'ssh://example.net',
protocol: 'ssh:',
},
},
{
href: 'nonsense:///test',
newValue: 'https',
expected: {
href: 'nonsense:///test',
protocol: 'nonsense:',
},
},
{
comment: "Stuff after the first ':' is ignored",
href: 'http://example.net',
newValue: 'https:foo : bar',
expected: {
href: 'https://example.net/',
protocol: 'https:',
},
},
{
comment: "Stuff after the first ':' is ignored",
href: 'data:text/html,Test',
newValue: 'view-source+data:foo : bar',
expected: {
href: 'view-source+data:text/html,
Test',
protocol: 'view-source+data:',
},
},
{
comment: 'Port is set to null if it is the default for new scheme.',
href: 'http://foo.com:443/',
newValue: 'https',
expected: {
href: 'https://foo.com/',
protocol: 'https:',
port: '',
},
},
],
username: [
{
comment: 'No host means no username',
href: 'file:///home/you/index.html',
newValue: 'me',
expected: {
href: 'file:///home/you/index.html',
username: '',
},
},
{
comment: 'No host means no username',
href: 'unix:/run/foo.socket',
newValue: 'me',
expected: {
href: 'unix:/run/foo.socket',
username: '',
},
},
{
comment: 'Cannot-be-a-base means no username',
href: 'mailto:you@example.net',
newValue: 'me',
expected: {
href: 'mailto:you@example.net',
username: '',
},
},
{
href: 'javascript:alert(1)',
newValue: 'wario',
expected: {
href: 'javascript:alert(1)',
username: '',
},
},
{
href: 'http://example.net',
newValue: 'me',
expected: {
href: 'http://me@example.net/',
username: 'me',
},
},
{
href: 'http://:secret@example.net',
newValue: 'me',
expected: {
href: 'http://me:secret@example.net/',
username: 'me',
},
},
{
href: 'http://me@example.net',
newValue: '',
expected: {
href: 'http://example.net/',
username: '',
},
},
{
href: 'http://me:secret@example.net',
newValue: '',
expected: {
href: 'http://:secret@example.net/',
username: '',
},
},
{
comment: 'UTF-8 percent encoding with the userinfo encode set.',
href: 'http://example.net',
newValue: "\u0000\u0001\t\n\r\u001F !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007F\u0080\u0081Éé",
expected: {
href: "http://%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9@example.net/",
username: "%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9",
},
},
{
comment: 'Bytes already percent-encoded are left as-is.',
href: 'http://example.net',
newValue: '%c3%89té',
expected: {
href: 'http://%c3%89t%C3%A9@example.net/',
username: '%c3%89t%C3%A9',
},
},
{
href: 'sc:///',
newValue: 'x',
expected: {
href: 'sc:///',
username: '',
},
},
{
href: 'javascript://x/',
newValue: 'wario',
expected: {
href: 'javascript://wario@x/',
username: 'wario',
},
},
{
href: 'file://test/',
newValue: 'test',
expected: {
href: 'file://test/',
username: '',
},
},
],
password: [
{
comment: 'No host means no password',
href: 'file:///home/me/index.html',
newValue: 'secret',
expected: {
href: 'file:///home/me/index.html',
password: '',
},
},
{
comment: 'No host means no password',
href: 'unix:/run/foo.socket',
newValue: 'secret',
expected: {
href: 'unix:/run/foo.socket',
password: '',
},
},
{
comment: 'Cannot-be-a-base means no password',
href: 'mailto:me@example.net',
newValue: 'secret',
expected: {
href: 'mailto:me@example.net',
password: '',
},
},
{
href: 'http://example.net',
newValue: 'secret',
expected: {
href: 'http://:secret@example.net/',
password: 'secret',
},
},
{
href: 'http://me@example.net',
newValue: 'secret',
expected: {
href: 'http://me:secret@example.net/',
password: 'secret',
},
},
{
href: 'http://:secret@example.net',
newValue: '',
expected: {
href: 'http://example.net/',
password: '',
},
},
{
href: 'http://me:secret@example.net',
newValue: '',
expected: {
href: 'http://me@example.net/',
password: '',
},
},
{
comment: 'UTF-8 percent encoding with the userinfo encode set.',
href: 'http://example.net',
newValue: "\u0000\u0001\t\n\r\u001F !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007F\u0080\u0081Éé",
expected: {
href: "http://:%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9@example.net/",
password: "%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9",
},
},
{
comment: 'Bytes already percent-encoded are left as-is.',
href: 'http://example.net',
newValue: '%c3%89té',
expected: {
href: 'http://:%c3%89t%C3%A9@example.net/',
password: '%c3%89t%C3%A9',
},
},
{
href: 'sc:///',
newValue: 'x',
expected: {
href: 'sc:///',
password: '',
},
},
{
href: 'javascript://x/',
newValue: 'bowser',
expected: {
href: 'javascript://:bowser@x/',
password: 'bowser',
},
},
{
href: 'file://test/',
newValue: 'test',
expected: {
href: 'file://test/',
password: '',
},
},
],
host: [
{
comment: 'Non-special scheme',
href: 'sc://x/',
newValue: '\u0000',
expected: {
href: 'sc://x/',
host: 'x',
hostname: 'x',
},
},
{
href: 'sc://x/',
newValue: '\u0009',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: '\u000A',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: '\u000D',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: ' ',
expected: {
href: 'sc://x/',
host: 'x',
hostname: 'x',
},
},
{
href: 'sc://x/',
newValue: '#',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: '/',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: '?',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: '@',
expected: {
href: 'sc://x/',
host: 'x',
hostname: 'x',
},
},
{
href: 'sc://x/',
newValue: 'ß',
expected: {
href: 'sc://%C3%9F/',
host: '%C3%9F',
hostname: '%C3%9F',
},
},
{
comment: 'IDNA Nontransitional_Processing',
href: 'https://x/',
newValue: 'ß',
expected: {
href: 'https://xn--zca/',
host: 'xn--zca',
hostname: 'xn--zca',
},
},
{
comment: 'Cannot-be-a-base means no host',
href: 'mailto:me@example.net',
newValue: 'example.com',
expected: {
href: 'mailto:me@example.net',
host: '',
},
},
{
comment: 'Cannot-be-a-base means no password',
href: 'data:text/plain,Stuff',
newValue: 'example.net',
expected: {
href: 'data:text/plain,Stuff',
host: '',
},
},
{
href: 'http://example.net',
newValue: 'example.com:8080',
expected: {
href: 'http://example.com:8080/',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'Port number is unchanged if not specified in the new value',
href: 'http://example.net:8080',
newValue: 'example.com',
expected: {
href: 'http://example.com:8080/',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'Port number is unchanged if not specified',
href: 'http://example.net:8080',
newValue: 'example.com:',
expected: {
href: 'http://example.com:8080/',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'The empty host is not valid for special schemes',
href: 'http://example.net',
newValue: '',
expected: {
href: 'http://example.net/',
host: 'example.net',
},
},
{
comment: 'The empty host is OK for non-special schemes',
href: 'view-source+http://example.net/foo',
newValue: '',
expected: {
href: 'view-source+http:///foo',
host: '',
},
},
{
comment: 'Path-only URLs can gain a host',
href: 'a:/foo',
newValue: 'example.net',
expected: {
href: 'a://example.net/foo',
host: 'example.net',
},
},
{
comment: 'IPv4 address syntax is normalized',
href: 'http://example.net',
newValue: '0x7F000001:8080',
expected: {
href: 'http://127.0.0.1:8080/',
host: '127.0.0.1:8080',
hostname: '127.0.0.1',
port: '8080',
},
},
{
comment: 'IPv6 address syntax is normalized',
href: 'http://example.net',
newValue: '[::0:01]:2',
expected: {
href: 'http://[::1]:2/',
host: '[::1]:2',
hostname: '[::1]',
port: '2',
},
},
{
comment: 'Default port number is removed',
href: 'http://example.net',
newValue: 'example.com:80',
expected: {
href: 'http://example.com/',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Default port number is removed',
href: 'https://example.net',
newValue: 'example.com:443',
expected: {
href: 'https://example.com/',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Default port number is only removed for the relevant scheme',
href: 'https://example.net',
newValue: 'example.com:80',
expected: {
href: 'https://example.com:80/',
host: 'example.com:80',
hostname: 'example.com',
port: '80',
},
},
{
comment: 'Port number is removed if new port is scheme default and existing URL has a non-default port',
href: 'http://example.net:8080',
newValue: 'example.com:80',
expected: {
href: 'http://example.com/',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Stuff after a / delimiter is ignored',
href: 'http://example.net/path',
newValue: 'example.com/stuff',
expected: {
href: 'http://example.com/path',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Stuff after a / delimiter is ignored',
href: 'http://example.net/path',
newValue: 'example.com:8080/stuff',
expected: {
href: 'http://example.com:8080/path',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'Stuff after a ? delimiter is ignored',
href: 'http://example.net/path',
newValue: 'example.com?stuff',
expected: {
href: 'http://example.com/path',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Stuff after a ? delimiter is ignored',
href: 'http://example.net/path',
newValue: 'example.com:8080?stuff',
expected: {
href: 'http://example.com:8080/path',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'Stuff after a # delimiter is ignored',
href: 'http://example.net/path',
newValue: 'example.com#stuff',
expected: {
href: 'http://example.com/path',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Stuff after a # delimiter is ignored',
href: 'http://example.net/path',
newValue: 'example.com:8080#stuff',
expected: {
href: 'http://example.com:8080/path',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'Stuff after a \\ delimiter is ignored for special schemes',
href: 'http://example.net/path',
newValue: 'example.com\\stuff',
expected: {
href: 'http://example.com/path',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Stuff after a \\ delimiter is ignored for special schemes',
href: 'http://example.net/path',
newValue: 'example.com:8080\\stuff',
expected: {
href: 'http://example.com:8080/path',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: '\\ is not a delimiter for non-special schemes, but still forbidden in hosts',
href: 'view-source+http://example.net/path',
newValue: 'example.com\\stuff',
expected: {
href: 'view-source+http://example.net/path',
host: 'example.net',
hostname: 'example.net',
port: '',
},
},
{
comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error',
href: 'view-source+http://example.net/path',
newValue: 'example.com:8080stuff2',
expected: {
href: 'view-source+http://example.com:8080/path',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error',
href: 'http://example.net/path',
newValue: 'example.com:8080stuff2',
expected: {
href: 'http://example.com:8080/path',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error',
href: 'http://example.net/path',
newValue: 'example.com:8080+2',
expected: {
href: 'http://example.com:8080/path',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'Port numbers are 16 bit integers',
href: 'http://example.net/path',
newValue: 'example.com:65535',
expected: {
href: 'http://example.com:65535/path',
host: 'example.com:65535',
hostname: 'example.com',
port: '65535',
},
},
{
comment: 'Port numbers are 16 bit integers, overflowing is an error. Hostname is still set, though.',
href: 'http://example.net/path',
newValue: 'example.com:65536',
expected: {
href: 'http://example.com/path',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Broken IPv6',
href: 'http://example.net/',
newValue: '[google.com]',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
},
},
{
href: 'http://example.net/',
newValue: '[::1.2.3.4x]',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
},
},
{
href: 'http://example.net/',
newValue: '[::1.2.3.]',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
},
},
{
href: 'http://example.net/',
newValue: '[::1.2.]',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
},
},
{
href: 'http://example.net/',
newValue: '[::1.]',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
},
},
{
href: 'file://y/',
newValue: 'x:123',
expected: {
href: 'file://y/',
host: 'y',
hostname: 'y',
port: '',
},
},
{
href: 'file://y/',
newValue: 'loc%41lhost',
expected: {
href: 'file:///',
host: '',
hostname: '',
port: '',
},
},
{
href: 'file://hi/x',
newValue: '',
expected: {
href: 'file:///x',
host: '',
hostname: '',
port: '',
},
},
{
href: 'sc://test@test/',
newValue: '',
expected: {
href: 'sc://test@test/',
host: 'test',
hostname: 'test',
username: 'test',
},
},
{
href: 'sc://test:12/',
newValue: '',
expected: {
href: 'sc://test:12/',
host: 'test:12',
hostname: 'test',
port: '12',
},
},
],
hostname: [
{
comment: 'Non-special scheme',
href: 'sc://x/',
newValue: '\u0000',
expected: {
href: 'sc://x/',
host: 'x',
hostname: 'x',
},
},
{
href: 'sc://x/',
newValue: '\u0009',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: '\u000A',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: '\u000D',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: ' ',
expected: {
href: 'sc://x/',
host: 'x',
hostname: 'x',
},
},
{
href: 'sc://x/',
newValue: '#',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: '/',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: '?',
expected: {
href: 'sc:///',
host: '',
hostname: '',
},
},
{
href: 'sc://x/',
newValue: '@',
expected: {
href: 'sc://x/',
host: 'x',
hostname: 'x',
},
},
{
comment: 'Cannot-be-a-base means no host',
href: 'mailto:me@example.net',
newValue: 'example.com',
expected: {
href: 'mailto:me@example.net',
host: '',
},
},
{
comment: 'Cannot-be-a-base means no password',
href: 'data:text/plain,Stuff',
newValue: 'example.net',
expected: {
href: 'data:text/plain,Stuff',
host: '',
},
},
{
href: 'http://example.net:8080',
newValue: 'example.com',
expected: {
href: 'http://example.com:8080/',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'The empty host is not valid for special schemes',
href: 'http://example.net',
newValue: '',
expected: {
href: 'http://example.net/',
host: 'example.net',
},
},
{
comment: 'The empty host is OK for non-special schemes',
href: 'view-source+http://example.net/foo',
newValue: '',
expected: {
href: 'view-source+http:///foo',
host: '',
},
},
{
comment: 'Path-only URLs can gain a host',
href: 'a:/foo',
newValue: 'example.net',
expected: {
href: 'a://example.net/foo',
host: 'example.net',
},
},
{
comment: 'IPv4 address syntax is normalized',
href: 'http://example.net:8080',
newValue: '0x7F000001',
expected: {
href: 'http://127.0.0.1:8080/',
host: '127.0.0.1:8080',
hostname: '127.0.0.1',
port: '8080',
},
},
{
comment: 'IPv6 address syntax is normalized',
href: 'http://example.net',
newValue: '[::0:01]',
expected: {
href: 'http://[::1]/',
host: '[::1]',
hostname: '[::1]',
port: '',
},
},
{
comment: 'Stuff after a : delimiter is ignored',
href: 'http://example.net/path',
newValue: 'example.com:8080',
expected: {
href: 'http://example.com/path',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Stuff after a : delimiter is ignored',
href: 'http://example.net:8080/path',
newValue: 'example.com:',
expected: {
href: 'http://example.com:8080/path',
host: 'example.com:8080',
hostname: 'example.com',
port: '8080',
},
},
{
comment: 'Stuff after a / delimiter is ignored',
href: 'http://example.net/path',
newValue: 'example.com/stuff',
expected: {
href: 'http://example.com/path',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Stuff after a ? delimiter is ignored',
href: 'http://example.net/path',
newValue: 'example.com?stuff',
expected: {
href: 'http://example.com/path',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Stuff after a # delimiter is ignored',
href: 'http://example.net/path',
newValue: 'example.com#stuff',
expected: {
href: 'http://example.com/path',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: 'Stuff after a \\ delimiter is ignored for special schemes',
href: 'http://example.net/path',
newValue: 'example.com\\stuff',
expected: {
href: 'http://example.com/path',
host: 'example.com',
hostname: 'example.com',
port: '',
},
},
{
comment: '\\ is not a delimiter for non-special schemes, but still forbidden in hosts',
href: 'view-source+http://example.net/path',
newValue: 'example.com\\stuff',
expected: {
href: 'view-source+http://example.net/path',
host: 'example.net',
hostname: 'example.net',
port: '',
},
},
{
comment: 'Broken IPv6',
href: 'http://example.net/',
newValue: '[google.com]',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
},
},
{
href: 'http://example.net/',
newValue: '[::1.2.3.4x]',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
},
},
{
href: 'http://example.net/',
newValue: '[::1.2.3.]',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
},
},
{
href: 'http://example.net/',
newValue: '[::1.2.]',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
},
},
{
href: 'http://example.net/',
newValue: '[::1.]',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
},
},
{
href: 'file://y/',
newValue: 'x:123',
expected: {
href: 'file://y/',
host: 'y',
hostname: 'y',
port: '',
},
},
{
href: 'file://y/',
newValue: 'loc%41lhost',
expected: {
href: 'file:///',
host: '',
hostname: '',
port: '',
},
},
{
href: 'file://hi/x',
newValue: '',
expected: {
href: 'file:///x',
host: '',
hostname: '',
port: '',
},
},
{
href: 'sc://test@test/',
newValue: '',
expected: {
href: 'sc://test@test/',
host: 'test',
hostname: 'test',
username: 'test',
},
},
{
href: 'sc://test:12/',
newValue: '',
expected: {
href: 'sc://test:12/',
host: 'test:12',
hostname: 'test',
port: '12',
},
},
],
port: [
{
href: 'http://example.net',
newValue: '8080',
expected: {
href: 'http://example.net:8080/',
host: 'example.net:8080',
hostname: 'example.net',
port: '8080',
},
},
{
comment: 'Port number is removed if empty is the new value',
href: 'http://example.net:8080',
newValue: '',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
port: '',
},
},
{
comment: 'Default port number is removed',
href: 'http://example.net:8080',
newValue: '80',
expected: {
href: 'http://example.net/',
host: 'example.net',
hostname: 'example.net',
port: '',
},
},
{
comment: 'Default port number is removed',
href: 'https://example.net:4433',
newValue: '443',
expected: {
href: 'https://example.net/',
host: 'example.net',
hostname: 'example.net',
port: '',
},
},
{
comment: 'Default port number is only removed for the relevant scheme',
href: 'https://example.net',
newValue: '80',
expected: {
href: 'https://example.net:80/',
host: 'example.net:80',
hostname: 'example.net',
port: '80',
},
},
{
comment: 'Stuff after a / delimiter is ignored',
href: 'http://example.net/path',
newValue: '8080/stuff',
expected: {
href: 'http://example.net:8080/path',
host: 'example.net:8080',
hostname: 'example.net',
port: '8080',
},
},
{
comment: 'Stuff after a ? delimiter is ignored',
href: 'http://example.net/path',
newValue: '8080?stuff',
expected: {
href: 'http://example.net:8080/path',
host: 'example.net:8080',
hostname: 'example.net',
port: '8080',
},
},
{
comment: 'Stuff after a # delimiter is ignored',
href: 'http://example.net/path',
newValue: '8080#stuff',
expected: {
href: 'http://example.net:8080/path',
host: 'example.net:8080',
hostname: 'example.net',
port: '8080',
},
},
{
comment: 'Stuff after a \\ delimiter is ignored for special schemes',
href: 'http://example.net/path',
newValue: '8080\\stuff',
expected: {
href: 'http://example.net:8080/path',
host: 'example.net:8080',
hostname: 'example.net',
port: '8080',
},
},
{
comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error',
href: 'view-source+http://example.net/path',
newValue: '8080stuff2',
expected: {
href: 'view-source+http://example.net:8080/path',
host: 'example.net:8080',
hostname: 'example.net',
port: '8080',
},
},
{
comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error',
href: 'http://example.net/path',
newValue: '8080stuff2',
expected: {
href: 'http://example.net:8080/path',
host: 'example.net:8080',
hostname: 'example.net',
port: '8080',
},
},
{
comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error',
href: 'http://example.net/path',
newValue: '8080+2',
expected: {
href: 'http://example.net:8080/path',
host: 'example.net:8080',
hostname: 'example.net',
port: '8080',
},
},
{
comment: 'Port numbers are 16 bit integers',
href: 'http://example.net/path',
newValue: '65535',
expected: {
href: 'http://example.net:65535/path',
host: 'example.net:65535',
hostname: 'example.net',
port: '65535',
},
},
{
comment: 'Port numbers are 16 bit integers, overflowing is an error',
href: 'http://example.net:8080/path',
newValue: '65536',
expected: {
href: 'http://example.net:8080/path',
host: 'example.net:8080',
hostname: 'example.net',
port: '8080',
},
},
{
comment: 'Port numbers are 16 bit integers, overflowing is an error',
href: 'non-special://example.net:8080/path',
newValue: '65536',
expected: {
href: 'non-special://example.net:8080/path',
host: 'example.net:8080',
hostname: 'example.net',
port: '8080',
},
},
{
href: 'file://test/',
newValue: '12',
expected: {
href: 'file://test/',
port: '',
},
},
{
href: 'file://localhost/',
newValue: '12',
expected: {
href: 'file:///',
port: '',
},
},
{
href: 'non-base:value',
newValue: '12',
expected: {
href: 'non-base:value',
port: '',
},
},
{
href: 'sc:///',
newValue: '12',
expected: {
href: 'sc:///',
port: '',
},
},
{
href: 'sc://x/',
newValue: '12',
expected: {
href: 'sc://x:12/',
port: '12',
},
},
{
href: 'javascript://x/',
newValue: '12',
expected: {
href: 'javascript://x:12/',
port: '12',
},
},
],
pathname: [
{
comment: 'Cannot-be-a-base don’t have a path',
href: 'mailto:me@example.net',
newValue: '/foo',
expected: {
href: 'mailto:me@example.net',
pathname: 'me@example.net',
},
},
{
href: 'unix:/run/foo.socket?timeout=10',
newValue: '/var/log/../run/bar.socket',
expected: {
href: 'unix:/var/run/bar.socket?timeout=10',
pathname: '/var/run/bar.socket',
},
},
{
href: 'https://example.net#nav',
newValue: 'home',
expected: {
href: 'https://example.net/home#nav',
pathname: '/home',
},
},
{
href: 'https://example.net#nav',
newValue: '../home',
expected: {
href: 'https://example.net/home#nav',
pathname: '/home',
},
},
{
comment: "\\ is a segment delimiter for 'special' URLs",
href: 'http://example.net/home?lang=fr#nav',
newValue: '\\a\\%2E\\b\\%2e.\\c',
expected: {
href: 'http://example.net/a/c?lang=fr#nav',
pathname: '/a/c',
},
},
{
comment: "\\ is *not* a segment delimiter for non-'special' URLs",
href: 'view-source+http://example.net/home?lang=fr#nav',
newValue: '\\a\\%2E\\b\\%2e.\\c',
expected: {
href: 'view-source+http://example.net/\\a\\%2E\\b\\%2e.\\c?lang=fr#nav',
pathname: '/\\a\\%2E\\b\\%2e.\\c',
},
},
{
comment: 'UTF-8 percent encoding with the default encode set. Tabs and newlines are removed.',
href: 'a:/',
newValue: "\u0000\u0001\t\n\r\u001F !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007F\u0080\u0081Éé",
expected: {
href: "a:/%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E%3F@AZ[\\]^_%60az%7B|%7D~%7F%C2%80%C2%81%C3%89%C3%A9",
pathname: "/%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E%3F@AZ[\\]^_%60az%7B|%7D~%7F%C2%80%C2%81%C3%89%C3%A9",
},
},
{
comment: 'Bytes already percent-encoded are left as-is, including %2E outside dotted segments.',
href: 'http://example.net',
newValue: '%2e%2E%c3%89té',
expected: {
href: 'http://example.net/%2e%2E%c3%89t%C3%A9',
pathname: '/%2e%2E%c3%89t%C3%A9',
},
},
{
comment: '? needs to be encoded',
href: 'http://example.net',
newValue: '?',
expected: {
href: 'http://example.net/%3F',
pathname: '/%3F',
},
},
{
comment: '# needs to be encoded',
href: 'http://example.net',
newValue: '#',
expected: {
href: 'http://example.net/%23',
pathname: '/%23',
},
},
{
comment: '? needs to be encoded, non-special scheme',
href: 'sc://example.net',
newValue: '?',
expected: {
href: 'sc://example.net/%3F',
pathname: '/%3F',
},
},
{
comment: '# needs to be encoded, non-special scheme',
href: 'sc://example.net',
newValue: '#',
expected: {
href: 'sc://example.net/%23',
pathname: '/%23',
},
},
{
comment: 'File URLs and (back)slashes',
href: 'file://monkey/',
newValue: '\\\\',
expected: {
href: 'file://monkey/',
pathname: '/',
},
},
{
comment: 'File URLs and (back)slashes',
href: 'file:///unicorn',
newValue: '//\\/',
expected: {
href: 'file:///',
pathname: '/',
},
},
{
comment: 'File URLs and (back)slashes',
href: 'file:///unicorn',
newValue: '//monkey/..//',
expected: {
href: 'file:///',
pathname: '/',
},
},
],
search: [
{
href: 'https://example.net#nav',
newValue: 'lang=fr',
expected: {
href: 'https://example.net/?lang=fr#nav',
search: '?lang=fr',
},
},
{
href: 'https://example.net?lang=en-US#nav',
newValue: 'lang=fr',
expected: {
href: 'https://example.net/?lang=fr#nav',
search: '?lang=fr',
},
},
{
href: 'https://example.net?lang=en-US#nav',
newValue: '?lang=fr',
expected: {
href: 'https://example.net/?lang=fr#nav',
search: '?lang=fr',
},
},
{
href: 'https://example.net?lang=en-US#nav',
newValue: '??lang=fr',
expected: {
href: 'https://example.net/??lang=fr#nav',
search: '??lang=fr',
},
},
{
href: 'https://example.net?lang=en-US#nav',
newValue: '?',
expected: {
href: 'https://example.net/?#nav',
search: '',
},
},
{
href: 'https://example.net?lang=en-US#nav',
newValue: '',
expected: {
href: 'https://example.net/#nav',
search: '',
},
},
{
href: 'https://example.net?lang=en-US',
newValue: '',
expected: {
href: 'https://example.net/',
search: '',
},
},
{
href: 'https://example.net',
newValue: '',
expected: {
href: 'https://example.net/',
search: '',
},
},
/* URI malformed
{
comment: 'UTF-8 percent encoding with the query encode set. Tabs and newlines are removed.',
href: 'a:/',
newValue: "\u0000\u0001\t\n\r\u001f !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007f\u0080\u0081Éé",
expected: {
href: "a:/?%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_`az{|}~%7F%C2%80%C2%81%C3%89%C3%A9",
search: "?%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_`az{|}~%7F%C2%80%C2%81%C3%89%C3%A9",
},
},
*/
{
comment: 'Bytes already percent-encoded are left as-is',
href: 'http://example.net',
newValue: '%c3%89té',
expected: {
href: 'http://example.net/?%c3%89t%C3%A9',
search: '?%c3%89t%C3%A9',
},
},
],
hash: [
{
href: 'https://example.net',
newValue: 'main',
expected: {
href: 'https://example.net/#main',
hash: '#main',
},
},
{
href: 'https://example.net#nav',
newValue: 'main',
expected: {
href: 'https://example.net/#main',
hash: '#main',
},
},
{
href: 'https://example.net?lang=en-US',
newValue: '##nav',
expected: {
href: 'https://example.net/?lang=en-US##nav',
hash: '##nav',
},
},
{
href: 'https://example.net?lang=en-US#nav',
newValue: '#main',
expected: {
href: 'https://example.net/?lang=en-US#main',
hash: '#main',
},
},
{
href: 'https://example.net?lang=en-US#nav',
newValue: '#',
expected: {
href: 'https://example.net/?lang=en-US#',
hash: '',
},
},
{
href: 'https://example.net?lang=en-US#nav',
newValue: '',
expected: {
href: 'https://example.net/?lang=en-US',
hash: '',
},
},
{
href: 'http://example.net',
newValue: '#foo bar',
expected: {
href: 'http://example.net/#foo%20bar',
hash: '#foo%20bar',
},
},
{
href: 'http://example.net',
newValue: '#foo"bar',
expected: {
href: 'http://example.net/#foo%22bar',
hash: '#foo%22bar',
},
},
{
href: 'http://example.net',
newValue: '#foobar',
expected: {
href: 'http://example.net/#foo%3Ebar',
hash: '#foo%3Ebar',
},
},
{
href: 'http://example.net',
newValue: '#foo`bar',
expected: {
href: 'http://example.net/#foo%60bar',
hash: '#foo%60bar',
},
},
{
comment: 'Simple percent-encoding; nuls, tabs, and newlines are removed',
href: 'a:/',
newValue: "\u0000\u0001\t\n\r\u001F !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007F\u0080\u0081Éé",
expected: {
href: "a:/#%01%1F%20!%22#$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_%60az{|}~%7F%C2%80%C2%81%C3%89%C3%A9",
hash: "#%01%1F%20!%22#$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_%60az{|}~%7F%C2%80%C2%81%C3%89%C3%A9",
},
},
{
comment: 'Bytes already percent-encoded are left as-is',
href: 'http://example.net',
newValue: '%c3%89té',
expected: {
href: 'http://example.net/#%c3%89t%C3%A9',
hash: '#%c3%89t%C3%A9',
},
},
{
href: 'javascript:alert(1)',
newValue: 'castle',
expected: {
href: 'javascript:alert(1)#castle',
hash: '#castle',
},
},
],
};
core-js-3.33.2/tests/wpt-url-resources/toascii.js 0000664 0000000 0000000 00000011167 14517762213 0021737 0 ustar 00root root 0000000 0000000 // Copyright © web-platform-tests contributors
// Originally from https://github.com/web-platform-tests/wpt
// Available under the 3-Clause BSD License https://github.com/web-platform-tests/wpt/blob/master/LICENSE.md
/* eslint-disable @stylistic/js/max-len -- ignore */
export default [
{
comment: 'Label with hyphens in 3rd and 4th position',
input: 'aa--',
output: 'aa--',
},
{
input: 'a†--',
output: 'xn--a---kp0a',
},
{
input: 'ab--c',
output: 'ab--c',
},
{
comment: 'Label with leading hyphen',
input: '-x',
output: '-x',
},
{
input: '-†',
output: 'xn----xhn',
},
{
input: '-x.xn--nxa',
output: '-x.xn--nxa',
},
{
input: '-x.β',
output: '-x.xn--nxa',
},
{
comment: 'Label with trailing hyphen',
input: 'x-.xn--nxa',
output: 'x-.xn--nxa',
},
{
input: 'x-.β',
output: 'x-.xn--nxa',
},
{
comment: 'Empty labels',
input: 'x..xn--nxa',
output: 'x..xn--nxa',
},
{
input: 'x..β',
output: 'x..xn--nxa',
},
{
comment: 'Invalid Punycode',
input: 'xn--a',
output: null,
},
{
input: 'xn--a.xn--nxa',
output: null,
},
{
input: 'xn--a.β',
output: null,
},
{
comment: 'Valid Punycode',
input: 'xn--nxa.xn--nxa',
output: 'xn--nxa.xn--nxa',
},
{
comment: 'Mixed',
input: 'xn--nxa.β',
output: 'xn--nxa.xn--nxa',
},
{
input: 'ab--c.xn--nxa',
output: 'ab--c.xn--nxa',
},
{
input: 'ab--c.β',
output: 'ab--c.xn--nxa',
},
{
comment: 'CheckJoiners is true',
input: '\u200D.example',
output: null,
},
{
input: 'xn--1ug.example',
output: null,
},
{
comment: 'CheckBidi is true',
input: 'يa',
output: null,
},
{
input: 'xn--a-yoc',
output: null,
},
{
comment: 'processing_option is Nontransitional_Processing',
input: 'ශ්රී',
output: 'xn--10cl1a0b660p',
},
{
input: 'نامهای',
output: 'xn--mgba3gch31f060k',
},
{
comment: 'U+FFFD',
input: '\uFFFD.com',
output: null,
},
{
comment: 'U+FFFD character encoded in Punycode',
input: 'xn--zn7c.com',
output: null,
},
{
comment: 'Label longer than 63 code points',
input: 'x01234567890123456789012345678901234567890123456789012345678901x',
output: 'x01234567890123456789012345678901234567890123456789012345678901x',
},
{
input: 'x01234567890123456789012345678901234567890123456789012345678901†',
output: 'xn--x01234567890123456789012345678901234567890123456789012345678901-6963b',
},
{
input: 'x01234567890123456789012345678901234567890123456789012345678901x.xn--nxa',
output: 'x01234567890123456789012345678901234567890123456789012345678901x.xn--nxa',
},
{
input: 'x01234567890123456789012345678901234567890123456789012345678901x.β',
output: 'x01234567890123456789012345678901234567890123456789012345678901x.xn--nxa',
},
{
comment: 'Domain excluding TLD longer than 253 code points',
input: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.x',
output: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.x',
},
{
input: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.xn--nxa',
output: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.xn--nxa',
},
{
input: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.β',
output: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.xn--nxa',
},
];
core-js-3.33.2/tests/wpt-url-resources/urltestdata.js 0000664 0000000 0000000 00000410677 14517762213 0022651 0 ustar 00root root 0000000 0000000 // Copyright © web-platform-tests contributors
// Originally from https://github.com/web-platform-tests/wpt
// Available under the 3-Clause BSD License https://github.com/web-platform-tests/wpt/blob/master/LICENSE.md
/* eslint-disable no-script-url -- required for testing */
export default [
'# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/script-tests/segments.js',
{
input: 'http://example\t.\norg',
base: 'http://example.org/foo/bar',
href: 'http://example.org/',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://user:pass@foo:21/bar;par?b#c',
base: 'http://example.org/foo/bar',
href: 'http://user:pass@foo:21/bar;par?b#c',
origin: 'http://foo:21',
protocol: 'http:',
username: 'user',
password: 'pass',
host: 'foo:21',
hostname: 'foo',
port: '21',
pathname: '/bar;par',
search: '?b',
hash: '#c',
},
{
input: 'https://test:@test',
base: 'about:blank',
href: 'https://test@test/',
origin: 'https://test',
protocol: 'https:',
username: 'test',
password: '',
host: 'test',
hostname: 'test',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'https://:@test',
base: 'about:blank',
href: 'https://test/',
origin: 'https://test',
protocol: 'https:',
username: '',
password: '',
host: 'test',
hostname: 'test',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'non-special://test:@test/x',
base: 'about:blank',
href: 'non-special://test@test/x',
origin: 'null',
protocol: 'non-special:',
username: 'test',
password: '',
host: 'test',
hostname: 'test',
port: '',
pathname: '/x',
search: '',
hash: '',
},
{
input: 'non-special://:@test/x',
base: 'about:blank',
href: 'non-special://test/x',
origin: 'null',
protocol: 'non-special:',
username: '',
password: '',
host: 'test',
hostname: 'test',
port: '',
pathname: '/x',
search: '',
hash: '',
},
{
input: 'http:foo.com',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/foo.com',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/foo.com',
search: '',
hash: '',
},
{
input: '\t :foo.com \n',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/:foo.com',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/:foo.com',
search: '',
hash: '',
},
{
input: ' foo.com ',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/foo.com',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/foo.com',
search: '',
hash: '',
},
{
input: 'a:\t foo.com',
base: 'http://example.org/foo/bar',
href: 'a: foo.com',
origin: 'null',
protocol: 'a:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: ' foo.com',
search: '',
hash: '',
},
{
input: 'http://f:21/ b ? d # e ',
base: 'http://example.org/foo/bar',
href: 'http://f:21/%20b%20?%20d%20#%20e',
origin: 'http://f:21',
protocol: 'http:',
username: '',
password: '',
host: 'f:21',
hostname: 'f',
port: '21',
pathname: '/%20b%20',
search: '?%20d%20',
hash: '#%20e',
},
{
input: 'lolscheme:x x#x x',
base: 'about:blank',
href: 'lolscheme:x x#x%20x',
protocol: 'lolscheme:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'x x',
search: '',
hash: '#x%20x',
},
{
input: 'http://f:/c',
base: 'http://example.org/foo/bar',
href: 'http://f/c',
origin: 'http://f',
protocol: 'http:',
username: '',
password: '',
host: 'f',
hostname: 'f',
port: '',
pathname: '/c',
search: '',
hash: '',
},
{
input: 'http://f:0/c',
base: 'http://example.org/foo/bar',
href: 'http://f:0/c',
origin: 'http://f:0',
protocol: 'http:',
username: '',
password: '',
host: 'f:0',
hostname: 'f',
port: '0',
pathname: '/c',
search: '',
hash: '',
},
{
input: 'http://f:00000000000000/c',
base: 'http://example.org/foo/bar',
href: 'http://f:0/c',
origin: 'http://f:0',
protocol: 'http:',
username: '',
password: '',
host: 'f:0',
hostname: 'f',
port: '0',
pathname: '/c',
search: '',
hash: '',
},
{
input: 'http://f:00000000000000000000080/c',
base: 'http://example.org/foo/bar',
href: 'http://f/c',
origin: 'http://f',
protocol: 'http:',
username: '',
password: '',
host: 'f',
hostname: 'f',
port: '',
pathname: '/c',
search: '',
hash: '',
},
{
input: 'http://f:b/c',
base: 'http://example.org/foo/bar',
failure: true,
},
{
input: 'http://f: /c',
base: 'http://example.org/foo/bar',
failure: true,
},
{
input: 'http://f:\n/c',
base: 'http://example.org/foo/bar',
href: 'http://f/c',
origin: 'http://f',
protocol: 'http:',
username: '',
password: '',
host: 'f',
hostname: 'f',
port: '',
pathname: '/c',
search: '',
hash: '',
},
{
input: 'http://f:fifty-two/c',
base: 'http://example.org/foo/bar',
failure: true,
},
{
input: 'http://f:999999/c',
base: 'http://example.org/foo/bar',
failure: true,
},
{
input: 'non-special://f:999999/c',
base: 'http://example.org/foo/bar',
failure: true,
},
{
input: 'http://f: 21 / b ? d # e ',
base: 'http://example.org/foo/bar',
failure: true,
},
{
input: '',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '',
hash: '',
},
{
input: ' \t',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '',
hash: '',
},
{
input: ':foo.com/',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/:foo.com/',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/:foo.com/',
search: '',
hash: '',
},
{
input: ':foo.com\\',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/:foo.com/',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/:foo.com/',
search: '',
hash: '',
},
{
input: ':',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/:',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/:',
search: '',
hash: '',
},
{
input: ':a',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/:a',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/:a',
search: '',
hash: '',
},
{
input: ':/',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/:/',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/:/',
search: '',
hash: '',
},
{
input: ':\\',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/:/',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/:/',
search: '',
hash: '',
},
{
input: ':#',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/:#',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/:',
search: '',
hash: '',
},
{
input: '#',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar#',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '',
hash: '',
},
{
input: '#/',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar#/',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '',
hash: '#/',
},
{
input: '#\\',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar#\\',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '',
hash: '#\\',
},
{
input: '#;?',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar#;?',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '',
hash: '#;?',
},
{
input: '?',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar?',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '',
hash: '',
},
{
input: '/',
base: 'http://example.org/foo/bar',
href: 'http://example.org/',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: ':23',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/:23',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/:23',
search: '',
hash: '',
},
{
input: '/:23',
base: 'http://example.org/foo/bar',
href: 'http://example.org/:23',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/:23',
search: '',
hash: '',
},
{
input: '::',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/::',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/::',
search: '',
hash: '',
},
{
input: '::23',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/::23',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/::23',
search: '',
hash: '',
},
{
input: 'foo://',
base: 'http://example.org/foo/bar',
href: 'foo://',
origin: 'null',
protocol: 'foo:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '',
search: '',
hash: '',
},
{
input: 'http://a:b@c:29/d',
base: 'http://example.org/foo/bar',
href: 'http://a:b@c:29/d',
origin: 'http://c:29',
protocol: 'http:',
username: 'a',
password: 'b',
host: 'c:29',
hostname: 'c',
port: '29',
pathname: '/d',
search: '',
hash: '',
},
{
input: 'http::@c:29',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/:@c:29',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/:@c:29',
search: '',
hash: '',
},
{
input: 'http://&a:foo(b]c@d:2/',
base: 'http://example.org/foo/bar',
href: 'http://&a:foo(b%5Dc@d:2/',
origin: 'http://d:2',
protocol: 'http:',
username: '&a',
password: 'foo(b%5Dc',
host: 'd:2',
hostname: 'd',
port: '2',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://::@c@d:2',
base: 'http://example.org/foo/bar',
href: 'http://:%3A%40c@d:2/',
origin: 'http://d:2',
protocol: 'http:',
username: '',
password: '%3A%40c',
host: 'd:2',
hostname: 'd',
port: '2',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://foo.com:b@d/',
base: 'http://example.org/foo/bar',
href: 'http://foo.com:b@d/',
origin: 'http://d',
protocol: 'http:',
username: 'foo.com',
password: 'b',
host: 'd',
hostname: 'd',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://foo.com/\\@',
base: 'http://example.org/foo/bar',
href: 'http://foo.com//@',
origin: 'http://foo.com',
protocol: 'http:',
username: '',
password: '',
host: 'foo.com',
hostname: 'foo.com',
port: '',
pathname: '//@',
search: '',
hash: '',
},
{
input: 'http:\\\\foo.com\\',
base: 'http://example.org/foo/bar',
href: 'http://foo.com/',
origin: 'http://foo.com',
protocol: 'http:',
username: '',
password: '',
host: 'foo.com',
hostname: 'foo.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:\\\\a\\b:c\\d@foo.com\\',
base: 'http://example.org/foo/bar',
href: 'http://a/b:c/d@foo.com/',
origin: 'http://a',
protocol: 'http:',
username: '',
password: '',
host: 'a',
hostname: 'a',
port: '',
pathname: '/b:c/d@foo.com/',
search: '',
hash: '',
},
{
input: 'foo:/',
base: 'http://example.org/foo/bar',
href: 'foo:/',
origin: 'null',
protocol: 'foo:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'foo:/bar.com/',
base: 'http://example.org/foo/bar',
href: 'foo:/bar.com/',
origin: 'null',
protocol: 'foo:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/bar.com/',
search: '',
hash: '',
},
{
input: 'foo://///////',
base: 'http://example.org/foo/bar',
href: 'foo://///////',
origin: 'null',
protocol: 'foo:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '///////',
search: '',
hash: '',
},
{
input: 'foo://///////bar.com/',
base: 'http://example.org/foo/bar',
href: 'foo://///////bar.com/',
origin: 'null',
protocol: 'foo:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '///////bar.com/',
search: '',
hash: '',
},
{
input: 'foo:////://///',
base: 'http://example.org/foo/bar',
href: 'foo:////://///',
origin: 'null',
protocol: 'foo:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '//://///',
search: '',
hash: '',
},
{
input: 'c:/foo',
base: 'http://example.org/foo/bar',
href: 'c:/foo',
origin: 'null',
protocol: 'c:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/foo',
search: '',
hash: '',
},
{
input: '//foo/bar',
base: 'http://example.org/foo/bar',
href: 'http://foo/bar',
origin: 'http://foo',
protocol: 'http:',
username: '',
password: '',
host: 'foo',
hostname: 'foo',
port: '',
pathname: '/bar',
search: '',
hash: '',
},
{
input: 'http://foo/path;a??e#f#g',
base: 'http://example.org/foo/bar',
href: 'http://foo/path;a??e#f#g',
origin: 'http://foo',
protocol: 'http:',
username: '',
password: '',
host: 'foo',
hostname: 'foo',
port: '',
pathname: '/path;a',
search: '??e',
hash: '#f#g',
},
{
input: 'http://foo/abcd?efgh?ijkl',
base: 'http://example.org/foo/bar',
href: 'http://foo/abcd?efgh?ijkl',
origin: 'http://foo',
protocol: 'http:',
username: '',
password: '',
host: 'foo',
hostname: 'foo',
port: '',
pathname: '/abcd',
search: '?efgh?ijkl',
hash: '',
},
{
input: 'http://foo/abcd#foo?bar',
base: 'http://example.org/foo/bar',
href: 'http://foo/abcd#foo?bar',
origin: 'http://foo',
protocol: 'http:',
username: '',
password: '',
host: 'foo',
hostname: 'foo',
port: '',
pathname: '/abcd',
search: '',
hash: '#foo?bar',
},
{
input: '[61:24:74]:98',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/[61:24:74]:98',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/[61:24:74]:98',
search: '',
hash: '',
},
{
input: 'http:[61:27]/:foo',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/[61:27]/:foo',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/[61:27]/:foo',
search: '',
hash: '',
},
{
input: 'http://[1::2]:3:4',
base: 'http://example.org/foo/bar',
failure: true,
},
{
input: 'http://2001::1',
base: 'http://example.org/foo/bar',
failure: true,
},
{
input: 'http://2001::1]',
base: 'http://example.org/foo/bar',
failure: true,
},
{
input: 'http://2001::1]:80',
base: 'http://example.org/foo/bar',
failure: true,
},
{
input: 'http://[2001::1]',
base: 'http://example.org/foo/bar',
href: 'http://[2001::1]/',
origin: 'http://[2001::1]',
protocol: 'http:',
username: '',
password: '',
host: '[2001::1]',
hostname: '[2001::1]',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://[::127.0.0.1]',
base: 'http://example.org/foo/bar',
href: 'http://[::7f00:1]/',
origin: 'http://[::7f00:1]',
protocol: 'http:',
username: '',
password: '',
host: '[::7f00:1]',
hostname: '[::7f00:1]',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://[0:0:0:0:0:0:13.1.68.3]',
base: 'http://example.org/foo/bar',
href: 'http://[::d01:4403]/',
origin: 'http://[::d01:4403]',
protocol: 'http:',
username: '',
password: '',
host: '[::d01:4403]',
hostname: '[::d01:4403]',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://[2001::1]:80',
base: 'http://example.org/foo/bar',
href: 'http://[2001::1]/',
origin: 'http://[2001::1]',
protocol: 'http:',
username: '',
password: '',
host: '[2001::1]',
hostname: '[2001::1]',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:/example.com/',
base: 'http://example.org/foo/bar',
href: 'http://example.org/example.com/',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'ftp:/example.com/',
base: 'http://example.org/foo/bar',
href: 'ftp://example.com/',
origin: 'ftp://example.com',
protocol: 'ftp:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'https:/example.com/',
base: 'http://example.org/foo/bar',
href: 'https://example.com/',
origin: 'https://example.com',
protocol: 'https:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'madeupscheme:/example.com/',
base: 'http://example.org/foo/bar',
href: 'madeupscheme:/example.com/',
origin: 'null',
protocol: 'madeupscheme:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'file:/example.com/',
base: 'http://example.org/foo/bar',
href: 'file:///example.com/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'file://example:1/',
base: 'about:blank',
failure: true,
},
{
input: 'file://example:test/',
base: 'about:blank',
failure: true,
},
{
input: 'file://example%/',
base: 'about:blank',
failure: true,
},
{
input: 'file://[example]/',
base: 'about:blank',
failure: true,
},
{
input: 'ftps:/example.com/',
base: 'http://example.org/foo/bar',
href: 'ftps:/example.com/',
origin: 'null',
protocol: 'ftps:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'ws:/example.com/',
base: 'http://example.org/foo/bar',
href: 'ws://example.com/',
origin: 'ws://example.com',
protocol: 'ws:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'wss:/example.com/',
base: 'http://example.org/foo/bar',
href: 'wss://example.com/',
origin: 'wss://example.com',
protocol: 'wss:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'data:/example.com/',
base: 'http://example.org/foo/bar',
href: 'data:/example.com/',
origin: 'null',
protocol: 'data:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'javascript:/example.com/',
base: 'http://example.org/foo/bar',
href: 'javascript:/example.com/',
origin: 'null',
protocol: 'javascript:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'mailto:/example.com/',
base: 'http://example.org/foo/bar',
href: 'mailto:/example.com/',
origin: 'null',
protocol: 'mailto:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'http:example.com/',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/example.com/',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/example.com/',
search: '',
hash: '',
},
{
input: 'ftp:example.com/',
base: 'http://example.org/foo/bar',
href: 'ftp://example.com/',
origin: 'ftp://example.com',
protocol: 'ftp:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'https:example.com/',
base: 'http://example.org/foo/bar',
href: 'https://example.com/',
origin: 'https://example.com',
protocol: 'https:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'madeupscheme:example.com/',
base: 'http://example.org/foo/bar',
href: 'madeupscheme:example.com/',
origin: 'null',
protocol: 'madeupscheme:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'example.com/',
search: '',
hash: '',
},
{
input: 'ftps:example.com/',
base: 'http://example.org/foo/bar',
href: 'ftps:example.com/',
origin: 'null',
protocol: 'ftps:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'example.com/',
search: '',
hash: '',
},
{
input: 'ws:example.com/',
base: 'http://example.org/foo/bar',
href: 'ws://example.com/',
origin: 'ws://example.com',
protocol: 'ws:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'wss:example.com/',
base: 'http://example.org/foo/bar',
href: 'wss://example.com/',
origin: 'wss://example.com',
protocol: 'wss:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'data:example.com/',
base: 'http://example.org/foo/bar',
href: 'data:example.com/',
origin: 'null',
protocol: 'data:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'example.com/',
search: '',
hash: '',
},
{
input: 'javascript:example.com/',
base: 'http://example.org/foo/bar',
href: 'javascript:example.com/',
origin: 'null',
protocol: 'javascript:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'example.com/',
search: '',
hash: '',
},
{
input: 'mailto:example.com/',
base: 'http://example.org/foo/bar',
href: 'mailto:example.com/',
origin: 'null',
protocol: 'mailto:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'example.com/',
search: '',
hash: '',
},
{
input: '/a/b/c',
base: 'http://example.org/foo/bar',
href: 'http://example.org/a/b/c',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/a/b/c',
search: '',
hash: '',
},
{
input: '/a/ /c',
base: 'http://example.org/foo/bar',
href: 'http://example.org/a/%20/c',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/a/%20/c',
search: '',
hash: '',
},
{
input: '/a%2fc',
base: 'http://example.org/foo/bar',
href: 'http://example.org/a%2fc',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/a%2fc',
search: '',
hash: '',
},
{
input: '/a/%2f/c',
base: 'http://example.org/foo/bar',
href: 'http://example.org/a/%2f/c',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/a/%2f/c',
search: '',
hash: '',
},
{
input: '#β',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar#%CE%B2',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '',
hash: '#%CE%B2',
},
{
input: 'data:text/html,test#test',
base: 'http://example.org/foo/bar',
href: 'data:text/html,test#test',
origin: 'null',
protocol: 'data:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'text/html,test',
search: '',
hash: '#test',
},
{
input: 'tel:1234567890',
base: 'http://example.org/foo/bar',
href: 'tel:1234567890',
origin: 'null',
protocol: 'tel:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '1234567890',
search: '',
hash: '',
},
'# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/file.html',
{
input: 'file:c:\\foo\\bar.html',
base: 'file:///tmp/mock/path',
href: 'file:///c:/foo/bar.html',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/c:/foo/bar.html',
search: '',
hash: '',
},
{
input: ' File:c|////foo\\bar.html',
base: 'file:///tmp/mock/path',
href: 'file:///c:////foo/bar.html',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/c:////foo/bar.html',
search: '',
hash: '',
},
{
input: 'C|/foo/bar',
base: 'file:///tmp/mock/path',
href: 'file:///C:/foo/bar',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/foo/bar',
search: '',
hash: '',
},
{
input: '/C|\\foo\\bar',
base: 'file:///tmp/mock/path',
href: 'file:///C:/foo/bar',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/foo/bar',
search: '',
hash: '',
},
{
input: '//C|/foo/bar',
base: 'file:///tmp/mock/path',
href: 'file:///C:/foo/bar',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/foo/bar',
search: '',
hash: '',
},
{
input: '//server/file',
base: 'file:///tmp/mock/path',
href: 'file://server/file',
protocol: 'file:',
username: '',
password: '',
host: 'server',
hostname: 'server',
port: '',
pathname: '/file',
search: '',
hash: '',
},
{
input: '\\\\server\\file',
base: 'file:///tmp/mock/path',
href: 'file://server/file',
protocol: 'file:',
username: '',
password: '',
host: 'server',
hostname: 'server',
port: '',
pathname: '/file',
search: '',
hash: '',
},
{
input: '/\\server/file',
base: 'file:///tmp/mock/path',
href: 'file://server/file',
protocol: 'file:',
username: '',
password: '',
host: 'server',
hostname: 'server',
port: '',
pathname: '/file',
search: '',
hash: '',
},
{
input: 'file:///foo/bar.txt',
base: 'file:///tmp/mock/path',
href: 'file:///foo/bar.txt',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/foo/bar.txt',
search: '',
hash: '',
},
{
input: 'file:///home/me',
base: 'file:///tmp/mock/path',
href: 'file:///home/me',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/home/me',
search: '',
hash: '',
},
{
input: '//',
base: 'file:///tmp/mock/path',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: '///',
base: 'file:///tmp/mock/path',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: '///test',
base: 'file:///tmp/mock/path',
href: 'file:///test',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test',
search: '',
hash: '',
},
{
input: 'file://test',
base: 'file:///tmp/mock/path',
href: 'file://test/',
protocol: 'file:',
username: '',
password: '',
host: 'test',
hostname: 'test',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'file://localhost',
base: 'file:///tmp/mock/path',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'file://localhost/',
base: 'file:///tmp/mock/path',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'file://localhost/test',
base: 'file:///tmp/mock/path',
href: 'file:///test',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test',
search: '',
hash: '',
},
{
input: 'test',
base: 'file:///tmp/mock/path',
href: 'file:///tmp/mock/test',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/tmp/mock/test',
search: '',
hash: '',
},
{
input: 'file:test',
base: 'file:///tmp/mock/path',
href: 'file:///tmp/mock/test',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/tmp/mock/test',
search: '',
hash: '',
},
'# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/script-tests/path.js',
{
input: 'http://example.com/././foo',
base: 'about:blank',
href: 'http://example.com/foo',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo',
search: '',
hash: '',
},
{
input: 'http://example.com/./.foo',
base: 'about:blank',
href: 'http://example.com/.foo',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/.foo',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/.',
base: 'about:blank',
href: 'http://example.com/foo/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo/',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/./',
base: 'about:blank',
href: 'http://example.com/foo/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo/',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/bar/..',
base: 'about:blank',
href: 'http://example.com/foo/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo/',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/bar/../',
base: 'about:blank',
href: 'http://example.com/foo/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo/',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/..bar',
base: 'about:blank',
href: 'http://example.com/foo/..bar',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo/..bar',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/bar/../ton',
base: 'about:blank',
href: 'http://example.com/foo/ton',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo/ton',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/bar/../ton/../../a',
base: 'about:blank',
href: 'http://example.com/a',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/a',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/../../..',
base: 'about:blank',
href: 'http://example.com/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/../../../ton',
base: 'about:blank',
href: 'http://example.com/ton',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/ton',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/%2e',
base: 'about:blank',
href: 'http://example.com/foo/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo/',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/%2e%2',
base: 'about:blank',
href: 'http://example.com/foo/%2e%2',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo/%2e%2',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/%2e./%2e%2e/.%2e/%2e.bar',
base: 'about:blank',
href: 'http://example.com/%2e.bar',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/%2e.bar',
search: '',
hash: '',
},
{
input: 'http://example.com////../..',
base: 'about:blank',
href: 'http://example.com//',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '//',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/bar//../..',
base: 'about:blank',
href: 'http://example.com/foo/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo/',
search: '',
hash: '',
},
{
input: 'http://example.com/foo/bar//..',
base: 'about:blank',
href: 'http://example.com/foo/bar/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo/bar/',
search: '',
hash: '',
},
{
input: 'http://example.com/foo',
base: 'about:blank',
href: 'http://example.com/foo',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo',
search: '',
hash: '',
},
{
input: 'http://example.com/%20foo',
base: 'about:blank',
href: 'http://example.com/%20foo',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/%20foo',
search: '',
hash: '',
},
{
input: 'http://example.com/foo%',
base: 'about:blank',
href: 'http://example.com/foo%',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo%',
search: '',
hash: '',
},
{
input: 'http://example.com/foo%2',
base: 'about:blank',
href: 'http://example.com/foo%2',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo%2',
search: '',
hash: '',
},
{
input: 'http://example.com/foo%2zbar',
base: 'about:blank',
href: 'http://example.com/foo%2zbar',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo%2zbar',
search: '',
hash: '',
},
{
input: 'http://example.com/foo%2©zbar',
base: 'about:blank',
href: 'http://example.com/foo%2%C3%82%C2%A9zbar',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo%2%C3%82%C2%A9zbar',
search: '',
hash: '',
},
{
input: 'http://example.com/foo%41%7a',
base: 'about:blank',
href: 'http://example.com/foo%41%7a',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo%41%7a',
search: '',
hash: '',
},
{
input: 'http://example.com/foo\t\u0091%91',
base: 'about:blank',
href: 'http://example.com/foo%C2%91%91',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo%C2%91%91',
search: '',
hash: '',
},
{
input: 'http://example.com/foo%00%51',
base: 'about:blank',
href: 'http://example.com/foo%00%51',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foo%00%51',
search: '',
hash: '',
},
{
input: 'http://example.com/(%28:%3A%29)',
base: 'about:blank',
href: 'http://example.com/(%28:%3A%29)',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/(%28:%3A%29)',
search: '',
hash: '',
},
{
input: 'http://example.com/%3A%3a%3C%3c',
base: 'about:blank',
href: 'http://example.com/%3A%3a%3C%3c',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/%3A%3a%3C%3c',
search: '',
hash: '',
},
{
input: 'http://example.com/foo\tbar',
base: 'about:blank',
href: 'http://example.com/foobar',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/foobar',
search: '',
hash: '',
},
{
input: 'http://example.com\\\\foo\\\\bar',
base: 'about:blank',
href: 'http://example.com//foo//bar',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '//foo//bar',
search: '',
hash: '',
},
{
input: 'http://example.com/%7Ffp3%3Eju%3Dduvgw%3Dd',
base: 'about:blank',
href: 'http://example.com/%7Ffp3%3Eju%3Dduvgw%3Dd',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/%7Ffp3%3Eju%3Dduvgw%3Dd',
search: '',
hash: '',
},
{
input: 'http://example.com/@asdf%40',
base: 'about:blank',
href: 'http://example.com/@asdf%40',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/@asdf%40',
search: '',
hash: '',
},
{
input: 'http://example.com/你好你好',
base: 'about:blank',
href: 'http://example.com/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD',
search: '',
hash: '',
},
{
input: 'http://example.com/‥/foo',
base: 'about:blank',
href: 'http://example.com/%E2%80%A5/foo',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/%E2%80%A5/foo',
search: '',
hash: '',
},
{
input: 'http://example.com//foo',
base: 'about:blank',
href: 'http://example.com/%EF%BB%BF/foo',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/%EF%BB%BF/foo',
search: '',
hash: '',
},
{
input: 'http://example.com//foo//bar',
base: 'about:blank',
href: 'http://example.com/%E2%80%AE/foo/%E2%80%AD/bar',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/%E2%80%AE/foo/%E2%80%AD/bar',
search: '',
hash: '',
},
'# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/script-tests/relative.js',
{
input: 'http://www.google.com/foo?bar=baz#',
base: 'about:blank',
href: 'http://www.google.com/foo?bar=baz#',
origin: 'http://www.google.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.google.com',
hostname: 'www.google.com',
port: '',
pathname: '/foo',
search: '?bar=baz',
hash: '',
},
{
input: 'http://www.google.com/foo?bar=baz# »',
base: 'about:blank',
href: 'http://www.google.com/foo?bar=baz#%20%C2%BB',
origin: 'http://www.google.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.google.com',
hostname: 'www.google.com',
port: '',
pathname: '/foo',
search: '?bar=baz',
hash: '#%20%C2%BB',
},
{
input: 'data:test# »',
base: 'about:blank',
href: 'data:test#%20%C2%BB',
origin: 'null',
protocol: 'data:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'test',
search: '',
hash: '#%20%C2%BB',
},
{
input: 'http://www.google.com',
base: 'about:blank',
href: 'http://www.google.com/',
origin: 'http://www.google.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.google.com',
hostname: 'www.google.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://192.0x00A80001',
base: 'about:blank',
href: 'http://192.168.0.1/',
origin: 'http://192.168.0.1',
protocol: 'http:',
username: '',
password: '',
host: '192.168.0.1',
hostname: '192.168.0.1',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://www/foo%2Ehtml',
base: 'about:blank',
href: 'http://www/foo%2Ehtml',
origin: 'http://www',
protocol: 'http:',
username: '',
password: '',
host: 'www',
hostname: 'www',
port: '',
pathname: '/foo%2Ehtml',
search: '',
hash: '',
},
{
input: 'http://www/foo/%2E/html',
base: 'about:blank',
href: 'http://www/foo/html',
origin: 'http://www',
protocol: 'http:',
username: '',
password: '',
host: 'www',
hostname: 'www',
port: '',
pathname: '/foo/html',
search: '',
hash: '',
},
{
input: 'http://user:pass@/',
base: 'about:blank',
failure: true,
},
{
input: 'http://%25DOMAIN:foobar@foodomain.com/',
base: 'about:blank',
href: 'http://%25DOMAIN:foobar@foodomain.com/',
origin: 'http://foodomain.com',
protocol: 'http:',
username: '%25DOMAIN',
password: 'foobar',
host: 'foodomain.com',
hostname: 'foodomain.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:\\\\www.google.com\\foo',
base: 'about:blank',
href: 'http://www.google.com/foo',
origin: 'http://www.google.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.google.com',
hostname: 'www.google.com',
port: '',
pathname: '/foo',
search: '',
hash: '',
},
{
input: 'http://foo:80/',
base: 'about:blank',
href: 'http://foo/',
origin: 'http://foo',
protocol: 'http:',
username: '',
password: '',
host: 'foo',
hostname: 'foo',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://foo:81/',
base: 'about:blank',
href: 'http://foo:81/',
origin: 'http://foo:81',
protocol: 'http:',
username: '',
password: '',
host: 'foo:81',
hostname: 'foo',
port: '81',
pathname: '/',
search: '',
hash: '',
},
{
input: 'httpa://foo:80/',
base: 'about:blank',
href: 'httpa://foo:80/',
origin: 'null',
protocol: 'httpa:',
username: '',
password: '',
host: 'foo:80',
hostname: 'foo',
port: '80',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://foo:-80/',
base: 'about:blank',
failure: true,
},
{
input: 'https://foo:443/',
base: 'about:blank',
href: 'https://foo/',
origin: 'https://foo',
protocol: 'https:',
username: '',
password: '',
host: 'foo',
hostname: 'foo',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'https://foo:80/',
base: 'about:blank',
href: 'https://foo:80/',
origin: 'https://foo:80',
protocol: 'https:',
username: '',
password: '',
host: 'foo:80',
hostname: 'foo',
port: '80',
pathname: '/',
search: '',
hash: '',
},
{
input: 'ftp://foo:21/',
base: 'about:blank',
href: 'ftp://foo/',
origin: 'ftp://foo',
protocol: 'ftp:',
username: '',
password: '',
host: 'foo',
hostname: 'foo',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'ftp://foo:80/',
base: 'about:blank',
href: 'ftp://foo:80/',
origin: 'ftp://foo:80',
protocol: 'ftp:',
username: '',
password: '',
host: 'foo:80',
hostname: 'foo',
port: '80',
pathname: '/',
search: '',
hash: '',
},
{
input: 'ws://foo:80/',
base: 'about:blank',
href: 'ws://foo/',
origin: 'ws://foo',
protocol: 'ws:',
username: '',
password: '',
host: 'foo',
hostname: 'foo',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'ws://foo:81/',
base: 'about:blank',
href: 'ws://foo:81/',
origin: 'ws://foo:81',
protocol: 'ws:',
username: '',
password: '',
host: 'foo:81',
hostname: 'foo',
port: '81',
pathname: '/',
search: '',
hash: '',
},
{
input: 'ws://foo:443/',
base: 'about:blank',
href: 'ws://foo:443/',
origin: 'ws://foo:443',
protocol: 'ws:',
username: '',
password: '',
host: 'foo:443',
hostname: 'foo',
port: '443',
pathname: '/',
search: '',
hash: '',
},
{
input: 'ws://foo:815/',
base: 'about:blank',
href: 'ws://foo:815/',
origin: 'ws://foo:815',
protocol: 'ws:',
username: '',
password: '',
host: 'foo:815',
hostname: 'foo',
port: '815',
pathname: '/',
search: '',
hash: '',
},
{
input: 'wss://foo:80/',
base: 'about:blank',
href: 'wss://foo:80/',
origin: 'wss://foo:80',
protocol: 'wss:',
username: '',
password: '',
host: 'foo:80',
hostname: 'foo',
port: '80',
pathname: '/',
search: '',
hash: '',
},
{
input: 'wss://foo:81/',
base: 'about:blank',
href: 'wss://foo:81/',
origin: 'wss://foo:81',
protocol: 'wss:',
username: '',
password: '',
host: 'foo:81',
hostname: 'foo',
port: '81',
pathname: '/',
search: '',
hash: '',
},
{
input: 'wss://foo:443/',
base: 'about:blank',
href: 'wss://foo/',
origin: 'wss://foo',
protocol: 'wss:',
username: '',
password: '',
host: 'foo',
hostname: 'foo',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'wss://foo:815/',
base: 'about:blank',
href: 'wss://foo:815/',
origin: 'wss://foo:815',
protocol: 'wss:',
username: '',
password: '',
host: 'foo:815',
hostname: 'foo',
port: '815',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:/example.com/',
base: 'about:blank',
href: 'http://example.com/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'ftp:/example.com/',
base: 'about:blank',
href: 'ftp://example.com/',
origin: 'ftp://example.com',
protocol: 'ftp:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'https:/example.com/',
base: 'about:blank',
href: 'https://example.com/',
origin: 'https://example.com',
protocol: 'https:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'madeupscheme:/example.com/',
base: 'about:blank',
href: 'madeupscheme:/example.com/',
origin: 'null',
protocol: 'madeupscheme:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'file:/example.com/',
base: 'about:blank',
href: 'file:///example.com/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'ftps:/example.com/',
base: 'about:blank',
href: 'ftps:/example.com/',
origin: 'null',
protocol: 'ftps:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'ws:/example.com/',
base: 'about:blank',
href: 'ws://example.com/',
origin: 'ws://example.com',
protocol: 'ws:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'wss:/example.com/',
base: 'about:blank',
href: 'wss://example.com/',
origin: 'wss://example.com',
protocol: 'wss:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'data:/example.com/',
base: 'about:blank',
href: 'data:/example.com/',
origin: 'null',
protocol: 'data:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'javascript:/example.com/',
base: 'about:blank',
href: 'javascript:/example.com/',
origin: 'null',
protocol: 'javascript:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'mailto:/example.com/',
base: 'about:blank',
href: 'mailto:/example.com/',
origin: 'null',
protocol: 'mailto:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/example.com/',
search: '',
hash: '',
},
{
input: 'http:example.com/',
base: 'about:blank',
href: 'http://example.com/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'ftp:example.com/',
base: 'about:blank',
href: 'ftp://example.com/',
origin: 'ftp://example.com',
protocol: 'ftp:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'https:example.com/',
base: 'about:blank',
href: 'https://example.com/',
origin: 'https://example.com',
protocol: 'https:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'madeupscheme:example.com/',
base: 'about:blank',
href: 'madeupscheme:example.com/',
origin: 'null',
protocol: 'madeupscheme:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'example.com/',
search: '',
hash: '',
},
{
input: 'ftps:example.com/',
base: 'about:blank',
href: 'ftps:example.com/',
origin: 'null',
protocol: 'ftps:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'example.com/',
search: '',
hash: '',
},
{
input: 'ws:example.com/',
base: 'about:blank',
href: 'ws://example.com/',
origin: 'ws://example.com',
protocol: 'ws:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'wss:example.com/',
base: 'about:blank',
href: 'wss://example.com/',
origin: 'wss://example.com',
protocol: 'wss:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'data:example.com/',
base: 'about:blank',
href: 'data:example.com/',
origin: 'null',
protocol: 'data:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'example.com/',
search: '',
hash: '',
},
{
input: 'javascript:example.com/',
base: 'about:blank',
href: 'javascript:example.com/',
origin: 'null',
protocol: 'javascript:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'example.com/',
search: '',
hash: '',
},
{
input: 'mailto:example.com/',
base: 'about:blank',
href: 'mailto:example.com/',
origin: 'null',
protocol: 'mailto:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'example.com/',
search: '',
hash: '',
},
'# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/segments-userinfo-vs-host.html',
{
input: 'http:@www.example.com',
base: 'about:blank',
href: 'http://www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:/@www.example.com',
base: 'about:blank',
href: 'http://www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://@www.example.com',
base: 'about:blank',
href: 'http://www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:a:b@www.example.com',
base: 'about:blank',
href: 'http://a:b@www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: 'a',
password: 'b',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:/a:b@www.example.com',
base: 'about:blank',
href: 'http://a:b@www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: 'a',
password: 'b',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://a:b@www.example.com',
base: 'about:blank',
href: 'http://a:b@www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: 'a',
password: 'b',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://@pple.com',
base: 'about:blank',
href: 'http://pple.com/',
origin: 'http://pple.com',
protocol: 'http:',
username: '',
password: '',
host: 'pple.com',
hostname: 'pple.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http::b@www.example.com',
base: 'about:blank',
href: 'http://:b@www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: 'b',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:/:b@www.example.com',
base: 'about:blank',
href: 'http://:b@www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: 'b',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://:b@www.example.com',
base: 'about:blank',
href: 'http://:b@www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: 'b',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:/:@/www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http://user@/www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http:@/www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http:/@/www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http://@/www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'https:@/www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http:a:b@/www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http:/a:b@/www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http://a:b@/www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http::@/www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http:a:@www.example.com',
base: 'about:blank',
href: 'http://a@www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: 'a',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:/a:@www.example.com',
base: 'about:blank',
href: 'http://a@www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: 'a',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://a:@www.example.com',
base: 'about:blank',
href: 'http://a@www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: 'a',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://www.@pple.com',
base: 'about:blank',
href: 'http://www.@pple.com/',
origin: 'http://pple.com',
protocol: 'http:',
username: 'www.',
password: '',
host: 'pple.com',
hostname: 'pple.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http:@:www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http:/@:www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http://@:www.example.com',
base: 'about:blank',
failure: true,
},
{
input: 'http://:@www.example.com',
base: 'about:blank',
href: 'http://www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
'# Others',
{
input: '/',
base: 'http://www.example.com/test',
href: 'http://www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: '/test.txt',
base: 'http://www.example.com/test',
href: 'http://www.example.com/test.txt',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/test.txt',
search: '',
hash: '',
},
{
input: '.',
base: 'http://www.example.com/test',
href: 'http://www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: '..',
base: 'http://www.example.com/test',
href: 'http://www.example.com/',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'test.txt',
base: 'http://www.example.com/test',
href: 'http://www.example.com/test.txt',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/test.txt',
search: '',
hash: '',
},
{
input: './test.txt',
base: 'http://www.example.com/test',
href: 'http://www.example.com/test.txt',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/test.txt',
search: '',
hash: '',
},
{
input: '../test.txt',
base: 'http://www.example.com/test',
href: 'http://www.example.com/test.txt',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/test.txt',
search: '',
hash: '',
},
{
input: '../aaa/test.txt',
base: 'http://www.example.com/test',
href: 'http://www.example.com/aaa/test.txt',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/aaa/test.txt',
search: '',
hash: '',
},
{
input: '../../test.txt',
base: 'http://www.example.com/test',
href: 'http://www.example.com/test.txt',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/test.txt',
search: '',
hash: '',
},
{
input: '中/test.txt',
base: 'http://www.example.com/test',
href: 'http://www.example.com/%E4%B8%AD/test.txt',
origin: 'http://www.example.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example.com',
hostname: 'www.example.com',
port: '',
pathname: '/%E4%B8%AD/test.txt',
search: '',
hash: '',
},
{
input: 'http://www.example2.com',
base: 'http://www.example.com/test',
href: 'http://www.example2.com/',
origin: 'http://www.example2.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example2.com',
hostname: 'www.example2.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: '//www.example2.com',
base: 'http://www.example.com/test',
href: 'http://www.example2.com/',
origin: 'http://www.example2.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.example2.com',
hostname: 'www.example2.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'file:...',
base: 'http://www.example.com/test',
href: 'file:///...',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/...',
search: '',
hash: '',
},
{
input: 'file:..',
base: 'http://www.example.com/test',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'file:a',
base: 'http://www.example.com/test',
href: 'file:///a',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/a',
search: '',
hash: '',
},
'# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/host.html',
'Basic canonicalization, uppercase should be converted to lowercase',
{
input: 'http://ExAmPlE.CoM',
base: 'http://other.com/',
href: 'http://example.com/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://example example.com',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://Goo%20 goo%7C|.com',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://[]',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://[:]',
base: 'http://other.com/',
failure: true,
},
'U+3000 is mapped to U+0020 (space) which is disallowed',
{
input: 'http://GOO\u00A0\u3000goo.com',
base: 'http://other.com/',
failure: true,
},
'Other types of space (no-break, zero-width, zero-width-no-break) are name-prepped away to nothing. U+200B, U+2060, and U+FEFF, are ignored',
{
input: 'http://GOO\u200B\u2060\uFEFFgoo.com',
base: 'http://other.com/',
href: 'http://googoo.com/',
origin: 'http://googoo.com',
protocol: 'http:',
username: '',
password: '',
host: 'googoo.com',
hostname: 'googoo.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
'Leading and trailing C0 control or space',
{
input: '\u0000\u001B\u0004\u0012 http://example.com/\u001F \u000D ',
base: 'about:blank',
href: 'http://example.com/',
origin: 'http://example.com',
protocol: 'http:',
username: '',
password: '',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
'Ideographic full stop (full-width period for Chinese, etc.) should be treated as a dot. U+3002 is mapped to U+002E (dot)',
{
input: 'http://www.foo。bar.com',
base: 'http://other.com/',
href: 'http://www.foo.bar.com/',
origin: 'http://www.foo.bar.com',
protocol: 'http:',
username: '',
password: '',
host: 'www.foo.bar.com',
hostname: 'www.foo.bar.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
'Invalid unicode characters should fail... U+FDD0 is disallowed; %ef%b7%90 is U+FDD0',
{
input: 'http://\uFDD0zyx.com',
base: 'http://other.com/',
failure: true,
},
'This is the same as previous but escaped',
{
input: 'http://%ef%b7%90zyx.com',
base: 'http://other.com/',
failure: true,
},
'U+FFFD',
{
input: 'https://\uFFFD',
base: 'about:blank',
failure: true,
},
{
input: 'https://%EF%BF%BD',
base: 'about:blank',
failure: true,
},
{
input: 'https://x/\uFFFD?\uFFFD#\uFFFD',
base: 'about:blank',
href: 'https://x/%EF%BF%BD?%EF%BF%BD#%EF%BF%BD',
origin: 'https://x',
protocol: 'https:',
username: '',
password: '',
host: 'x',
hostname: 'x',
port: '',
pathname: '/%EF%BF%BD',
search: '?%EF%BF%BD',
hash: '#%EF%BF%BD',
},
"Test name prepping, fullwidth input should be converted to ASCII and NOT IDN-ized. This is 'Go' in fullwidth UTF-8/UTF-16.",
{
input: 'http://Go.com',
base: 'http://other.com/',
href: 'http://go.com/',
origin: 'http://go.com',
protocol: 'http:',
username: '',
password: '',
host: 'go.com',
hostname: 'go.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
'URL spec forbids the following. https://www.w3.org/Bugs/Public/show_bug.cgi?id=24257',
{
input: 'http://%41.com',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://%ef%bc%85%ef%bc%94%ef%bc%91.com',
base: 'http://other.com/',
failure: true,
},
'...%00 in fullwidth should fail (also as escaped UTF-8 input)',
{
input: 'http://%00.com',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://%ef%bc%85%ef%bc%90%ef%bc%90.com',
base: 'http://other.com/',
failure: true,
},
'Basic IDN support, UTF-8 and UTF-16 input should be converted to IDN',
{
input: 'http://你好你好',
base: 'http://other.com/',
href: 'http://xn--6qqa088eba/',
origin: 'http://xn--6qqa088eba',
protocol: 'http:',
username: '',
password: '',
host: 'xn--6qqa088eba',
hostname: 'xn--6qqa088eba',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'https://faß.ExAmPlE/',
base: 'about:blank',
href: 'https://xn--fa-hia.example/',
origin: 'https://xn--fa-hia.example',
protocol: 'https:',
username: '',
password: '',
host: 'xn--fa-hia.example',
hostname: 'xn--fa-hia.example',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'sc://faß.ExAmPlE/',
base: 'about:blank',
href: 'sc://fa%C3%9F.ExAmPlE/',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: 'fa%C3%9F.ExAmPlE',
hostname: 'fa%C3%9F.ExAmPlE',
port: '',
pathname: '/',
search: '',
hash: '',
},
'Invalid escaped characters should fail and the percents should be escaped. https://www.w3.org/Bugs/Public/show_bug.cgi?id=24191',
{
input: 'http://%zz%66%a.com',
base: 'http://other.com/',
failure: true,
},
'If we get an invalid character that has been escaped.',
{
input: 'http://%25',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://hello%00',
base: 'http://other.com/',
failure: true,
},
'Escaped numbers should be treated like IP addresses if they are.',
/*
{
input: 'http://%30%78%63%30%2e%30%32%35%30.01',
base: 'http://other.com/',
href: 'http://192.168.0.1/',
origin: 'http://192.168.0.1',
protocol: 'http:',
username: '',
password: '',
host: '192.168.0.1',
hostname: '192.168.0.1',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://%30%78%63%30%2e%30%32%35%30.01%2e',
base: 'http://other.com/',
href: 'http://192.168.0.1/',
origin: 'http://192.168.0.1',
protocol: 'http:',
username: '',
password: '',
host: '192.168.0.1',
hostname: '192.168.0.1',
port: '',
pathname: '/',
search: '',
hash: '',
},
*/
{
input: 'http://192.168.0.257',
base: 'http://other.com/',
failure: true,
},
'Invalid escaping in hosts causes failure',
{
input: 'http://%3g%78%63%30%2e%30%32%35%30%2E.01',
base: 'http://other.com/',
failure: true,
},
'A space in a host causes failure',
{
input: 'http://192.168.0.1 hello',
base: 'http://other.com/',
failure: true,
},
{
input: 'https://x x:12',
base: 'about:blank',
failure: true,
},
'Fullwidth and escaped UTF-8 fullwidth should still be treated as IP',
{
input: 'http://0Xc0.0250.01',
base: 'http://other.com/',
href: 'http://192.168.0.1/',
origin: 'http://192.168.0.1',
protocol: 'http:',
username: '',
password: '',
host: '192.168.0.1',
hostname: '192.168.0.1',
port: '',
pathname: '/',
search: '',
hash: '',
},
'Domains with empty labels',
{
input: 'http://./',
base: 'about:blank',
href: 'http://./',
origin: 'http://.',
protocol: 'http:',
username: '',
password: '',
host: '.',
hostname: '.',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://../',
base: 'about:blank',
href: 'http://../',
origin: 'http://..',
protocol: 'http:',
username: '',
password: '',
host: '..',
hostname: '..',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://0..0x300/',
base: 'about:blank',
href: 'http://0..0x300/',
origin: 'http://0..0x300',
protocol: 'http:',
username: '',
password: '',
host: '0..0x300',
hostname: '0..0x300',
port: '',
pathname: '/',
search: '',
hash: '',
},
'Broken IPv6',
{
input: 'http://[www.google.com]/',
base: 'about:blank',
failure: true,
},
{
input: 'http://[google.com]',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://[::1.2.3.4x]',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://[::1.2.3.]',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://[::1.2.]',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://[::1.]',
base: 'http://other.com/',
failure: true,
},
'Misc Unicode',
{
input: 'http://foo:💩@example.com/bar',
base: 'http://other.com/',
href: 'http://foo:%F0%9F%92%A9@example.com/bar',
origin: 'http://example.com',
protocol: 'http:',
username: 'foo',
password: '%F0%9F%92%A9',
host: 'example.com',
hostname: 'example.com',
port: '',
pathname: '/bar',
search: '',
hash: '',
},
'# resolving a fragment against any scheme succeeds',
{
input: '#',
base: 'test:test',
href: 'test:test#',
origin: 'null',
protocol: 'test:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'test',
search: '',
hash: '',
},
{
input: '#x',
base: 'mailto:x@x.com',
href: 'mailto:x@x.com#x',
origin: 'null',
protocol: 'mailto:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'x@x.com',
search: '',
hash: '#x',
},
{
input: '#x',
base: 'data:,',
href: 'data:,#x',
origin: 'null',
protocol: 'data:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: ',',
search: '',
hash: '#x',
},
{
input: '#x',
base: 'about:blank',
href: 'about:blank#x',
origin: 'null',
protocol: 'about:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'blank',
search: '',
hash: '#x',
},
{
input: '#',
base: 'test:test?test',
href: 'test:test?test#',
origin: 'null',
protocol: 'test:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'test',
search: '?test',
hash: '',
},
'# multiple @ in authority state',
{
input: 'https://@test@test@example:800/',
base: 'http://doesnotmatter/',
href: 'https://%40test%40test@example:800/',
origin: 'https://example:800',
protocol: 'https:',
username: '%40test%40test',
password: '',
host: 'example:800',
hostname: 'example',
port: '800',
pathname: '/',
search: '',
hash: '',
},
{
input: 'https://@@@example',
base: 'http://doesnotmatter/',
href: 'https://%40%40@example/',
origin: 'https://example',
protocol: 'https:',
username: '%40%40',
password: '',
host: 'example',
hostname: 'example',
port: '',
pathname: '/',
search: '',
hash: '',
},
'non-az-09 characters',
{
input: 'http://`{}:`{}@h/`{}?`{}',
base: 'http://doesnotmatter/',
href: 'http://%60%7B%7D:%60%7B%7D@h/%60%7B%7D?`{}',
origin: 'http://h',
protocol: 'http:',
username: '%60%7B%7D',
password: '%60%7B%7D',
host: 'h',
hostname: 'h',
port: '',
pathname: '/%60%7B%7D',
search: '?`{}',
hash: '',
},
"byte is ' and url is special",
{
input: "http://host/?'",
base: 'about:blank',
href: 'http://host/?%27',
origin: 'http://host',
protocol: 'http:',
username: '',
password: '',
host: 'host',
hostname: 'host',
port: '',
pathname: '/',
search: '?%27',
hash: '',
},
{
input: "notspecial://host/?'",
base: 'about:blank',
href: "notspecial://host/?'",
origin: 'null',
protocol: 'notspecial:',
username: '',
password: '',
host: 'host',
hostname: 'host',
port: '',
pathname: '/',
search: "?'",
hash: '',
},
'# Credentials in base',
{
input: '/some/path',
base: 'http://user@example.org/smth',
href: 'http://user@example.org/some/path',
origin: 'http://example.org',
protocol: 'http:',
username: 'user',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/some/path',
search: '',
hash: '',
},
{
input: '',
base: 'http://user:pass@example.org:21/smth',
href: 'http://user:pass@example.org:21/smth',
origin: 'http://example.org:21',
protocol: 'http:',
username: 'user',
password: 'pass',
host: 'example.org:21',
hostname: 'example.org',
port: '21',
pathname: '/smth',
search: '',
hash: '',
},
{
input: '/some/path',
base: 'http://user:pass@example.org:21/smth',
href: 'http://user:pass@example.org:21/some/path',
origin: 'http://example.org:21',
protocol: 'http:',
username: 'user',
password: 'pass',
host: 'example.org:21',
hostname: 'example.org',
port: '21',
pathname: '/some/path',
search: '',
hash: '',
},
'# a set of tests designed by zcorpan for relative URLs with unknown schemes',
{
input: 'i',
base: 'sc:sd',
failure: true,
},
{
input: 'i',
base: 'sc:sd/sd',
failure: true,
},
{
input: 'i',
base: 'sc:/pa/pa',
href: 'sc:/pa/i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/pa/i',
search: '',
hash: '',
},
{
input: 'i',
base: 'sc://ho/pa',
href: 'sc://ho/i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: 'ho',
hostname: 'ho',
port: '',
pathname: '/i',
search: '',
hash: '',
},
{
input: 'i',
base: 'sc:///pa/pa',
href: 'sc:///pa/i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/pa/i',
search: '',
hash: '',
},
{
input: '../i',
base: 'sc:sd',
failure: true,
},
{
input: '../i',
base: 'sc:sd/sd',
failure: true,
},
{
input: '../i',
base: 'sc:/pa/pa',
href: 'sc:/i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/i',
search: '',
hash: '',
},
{
input: '../i',
base: 'sc://ho/pa',
href: 'sc://ho/i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: 'ho',
hostname: 'ho',
port: '',
pathname: '/i',
search: '',
hash: '',
},
{
input: '../i',
base: 'sc:///pa/pa',
href: 'sc:///i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/i',
search: '',
hash: '',
},
{
input: '/i',
base: 'sc:sd',
failure: true,
},
{
input: '/i',
base: 'sc:sd/sd',
failure: true,
},
{
input: '/i',
base: 'sc:/pa/pa',
href: 'sc:/i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/i',
search: '',
hash: '',
},
{
input: '/i',
base: 'sc://ho/pa',
href: 'sc://ho/i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: 'ho',
hostname: 'ho',
port: '',
pathname: '/i',
search: '',
hash: '',
},
{
input: '/i',
base: 'sc:///pa/pa',
href: 'sc:///i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/i',
search: '',
hash: '',
},
{
input: '?i',
base: 'sc:sd',
failure: true,
},
{
input: '?i',
base: 'sc:sd/sd',
failure: true,
},
{
input: '?i',
base: 'sc:/pa/pa',
href: 'sc:/pa/pa?i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/pa/pa',
search: '?i',
hash: '',
},
{
input: '?i',
base: 'sc://ho/pa',
href: 'sc://ho/pa?i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: 'ho',
hostname: 'ho',
port: '',
pathname: '/pa',
search: '?i',
hash: '',
},
{
input: '?i',
base: 'sc:///pa/pa',
href: 'sc:///pa/pa?i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/pa/pa',
search: '?i',
hash: '',
},
{
input: '#i',
base: 'sc:sd',
href: 'sc:sd#i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'sd',
search: '',
hash: '#i',
},
{
input: '#i',
base: 'sc:sd/sd',
href: 'sc:sd/sd#i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'sd/sd',
search: '',
hash: '#i',
},
{
input: '#i',
base: 'sc:/pa/pa',
href: 'sc:/pa/pa#i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/pa/pa',
search: '',
hash: '#i',
},
{
input: '#i',
base: 'sc://ho/pa',
href: 'sc://ho/pa#i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: 'ho',
hostname: 'ho',
port: '',
pathname: '/pa',
search: '',
hash: '#i',
},
{
input: '#i',
base: 'sc:///pa/pa',
href: 'sc:///pa/pa#i',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/pa/pa',
search: '',
hash: '#i',
},
'# make sure that relative URL logic works on known typically non-relative schemes too',
{
input: 'about:/../',
base: 'about:blank',
href: 'about:/',
origin: 'null',
protocol: 'about:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'data:/../',
base: 'about:blank',
href: 'data:/',
origin: 'null',
protocol: 'data:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'javascript:/../',
base: 'about:blank',
href: 'javascript:/',
origin: 'null',
protocol: 'javascript:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'mailto:/../',
base: 'about:blank',
href: 'mailto:/',
origin: 'null',
protocol: 'mailto:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
'# unknown schemes and their hosts',
{
input: 'sc://ñ.test/',
base: 'about:blank',
href: 'sc://%C3%B1.test/',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '%C3%B1.test',
hostname: '%C3%B1.test',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: "sc://\u001F!\"$&'()*+,-.;<=>^_`{|}~/",
base: 'about:blank',
href: "sc://%1F!\"$&'()*+,-.;<=>^_`{|}~/",
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: "%1F!\"$&'()*+,-.;<=>^_`{|}~",
hostname: "%1F!\"$&'()*+,-.;<=>^_`{|}~",
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'sc://\u0000/',
base: 'about:blank',
failure: true,
},
{
input: 'sc:// /',
base: 'about:blank',
failure: true,
},
/*
{
input: 'sc://%/',
base: 'about:blank',
href: 'sc://%/',
protocol: 'sc:',
username: '',
password: '',
host: '%',
hostname: '%',
port: '',
pathname: '/',
search: '',
hash: '',
},
*/
{
input: 'sc://@/',
base: 'about:blank',
failure: true,
},
{
input: 'sc://tes@s:t@/',
base: 'about:blank',
failure: true,
},
{
input: 'sc://:/',
base: 'about:blank',
failure: true,
},
{
input: 'sc://:12/',
base: 'about:blank',
failure: true,
},
{
input: 'sc://[/',
base: 'about:blank',
failure: true,
},
{
input: 'sc://\\/',
base: 'about:blank',
failure: true,
},
{
input: 'sc://]/',
base: 'about:blank',
failure: true,
},
{
input: 'x',
base: 'sc://ñ',
href: 'sc://%C3%B1/x',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '%C3%B1',
hostname: '%C3%B1',
port: '',
pathname: '/x',
search: '',
hash: '',
},
'# unknown schemes and backslashes',
{
input: 'sc:\\../',
base: 'about:blank',
href: 'sc:\\../',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '\\../',
search: '',
hash: '',
},
'# unknown scheme with path looking like a password',
{
input: 'sc::a@example.net',
base: 'about:blank',
href: 'sc::a@example.net',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: ':a@example.net',
search: '',
hash: '',
},
'# unknown scheme with bogus percent-encoding',
{
input: 'wow:%NBD',
base: 'about:blank',
href: 'wow:%NBD',
origin: 'null',
protocol: 'wow:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '%NBD',
search: '',
hash: '',
},
{
input: 'wow:%1G',
base: 'about:blank',
href: 'wow:%1G',
origin: 'null',
protocol: 'wow:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '%1G',
search: '',
hash: '',
},
'# Hosts and percent-encoding',
{
input: 'ftp://example.com%80/',
base: 'about:blank',
failure: true,
},
{
input: 'ftp://example.com%A0/',
base: 'about:blank',
failure: true,
},
{
input: 'https://example.com%80/',
base: 'about:blank',
failure: true,
},
{
input: 'https://example.com%A0/',
base: 'about:blank',
failure: true,
},
/*
{
input: 'ftp://%e2%98%83',
base: 'about:blank',
href: 'ftp://xn--n3h/',
origin: 'ftp://xn--n3h',
protocol: 'ftp:',
username: '',
password: '',
host: 'xn--n3h',
hostname: 'xn--n3h',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'https://%e2%98%83',
base: 'about:blank',
href: 'https://xn--n3h/',
origin: 'https://xn--n3h',
protocol: 'https:',
username: '',
password: '',
host: 'xn--n3h',
hostname: 'xn--n3h',
port: '',
pathname: '/',
search: '',
hash: '',
},
*/
'# tests from jsdom/whatwg-url designed for code coverage',
{
input: 'http://127.0.0.1:10100/relative_import.html',
base: 'about:blank',
href: 'http://127.0.0.1:10100/relative_import.html',
origin: 'http://127.0.0.1:10100',
protocol: 'http:',
username: '',
password: '',
host: '127.0.0.1:10100',
hostname: '127.0.0.1',
port: '10100',
pathname: '/relative_import.html',
search: '',
hash: '',
},
{
input: 'http://facebook.com/?foo=%7B%22abc%22',
base: 'about:blank',
href: 'http://facebook.com/?foo=%7B%22abc%22',
origin: 'http://facebook.com',
protocol: 'http:',
username: '',
password: '',
host: 'facebook.com',
hostname: 'facebook.com',
port: '',
pathname: '/',
search: '?foo=%7B%22abc%22',
hash: '',
},
{
input: 'https://localhost:3000/jqueryui@1.2.3',
base: 'about:blank',
href: 'https://localhost:3000/jqueryui@1.2.3',
origin: 'https://localhost:3000',
protocol: 'https:',
username: '',
password: '',
host: 'localhost:3000',
hostname: 'localhost',
port: '3000',
pathname: '/jqueryui@1.2.3',
search: '',
hash: '',
},
'# tab/LF/CR',
{
input: 'h\tt\nt\rp://h\to\ns\rt:9\t0\n0\r0/p\ta\nt\rh?q\tu\ne\rry#f\tr\na\rg',
base: 'about:blank',
href: 'http://host:9000/path?query#frag',
origin: 'http://host:9000',
protocol: 'http:',
username: '',
password: '',
host: 'host:9000',
hostname: 'host',
port: '9000',
pathname: '/path',
search: '?query',
hash: '#frag',
},
'# Stringification of URL.searchParams',
{
input: '?a=b&c=d',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar?a=b&c=d',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '?a=b&c=d',
searchParams: 'a=b&c=d',
hash: '',
},
{
input: '??a=b&c=d',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar??a=b&c=d',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '??a=b&c=d',
searchParams: '%3Fa=b&c=d',
hash: '',
},
'# Scheme only',
{
input: 'http:',
base: 'http://example.org/foo/bar',
href: 'http://example.org/foo/bar',
origin: 'http://example.org',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/foo/bar',
search: '',
searchParams: '',
hash: '',
},
{
input: 'http:',
base: 'https://example.org/foo/bar',
failure: true,
},
{
input: 'sc:',
base: 'https://example.org/foo/bar',
href: 'sc:',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '',
search: '',
searchParams: '',
hash: '',
},
'# Percent encoding of fragments',
{
input: 'http://foo.bar/baz?qux#foo\bbar',
base: 'about:blank',
href: 'http://foo.bar/baz?qux#foo%08bar',
origin: 'http://foo.bar',
protocol: 'http:',
username: '',
password: '',
host: 'foo.bar',
hostname: 'foo.bar',
port: '',
pathname: '/baz',
search: '?qux',
searchParams: 'qux=',
hash: '#foo%08bar',
},
{
input: 'http://foo.bar/baz?qux#foo"bar',
base: 'about:blank',
href: 'http://foo.bar/baz?qux#foo%22bar',
origin: 'http://foo.bar',
protocol: 'http:',
username: '',
password: '',
host: 'foo.bar',
hostname: 'foo.bar',
port: '',
pathname: '/baz',
search: '?qux',
searchParams: 'qux=',
hash: '#foo%22bar',
},
{
input: 'http://foo.bar/baz?qux#foobar',
base: 'about:blank',
href: 'http://foo.bar/baz?qux#foo%3Ebar',
origin: 'http://foo.bar',
protocol: 'http:',
username: '',
password: '',
host: 'foo.bar',
hostname: 'foo.bar',
port: '',
pathname: '/baz',
search: '?qux',
searchParams: 'qux=',
hash: '#foo%3Ebar',
},
{
input: 'http://foo.bar/baz?qux#foo`bar',
base: 'about:blank',
href: 'http://foo.bar/baz?qux#foo%60bar',
origin: 'http://foo.bar',
protocol: 'http:',
username: '',
password: '',
host: 'foo.bar',
hostname: 'foo.bar',
port: '',
pathname: '/baz',
search: '?qux',
searchParams: 'qux=',
hash: '#foo%60bar',
},
'# IPv4 parsing (via https://github.com/nodejs/node/pull/10317)',
{
input: 'http://192.168.257',
base: 'http://other.com/',
href: 'http://192.168.1.1/',
origin: 'http://192.168.1.1',
protocol: 'http:',
username: '',
password: '',
host: '192.168.1.1',
hostname: '192.168.1.1',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://192.168.257.com',
base: 'http://other.com/',
href: 'http://192.168.257.com/',
origin: 'http://192.168.257.com',
protocol: 'http:',
username: '',
password: '',
host: '192.168.257.com',
hostname: '192.168.257.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://256',
base: 'http://other.com/',
href: 'http://0.0.1.0/',
origin: 'http://0.0.1.0',
protocol: 'http:',
username: '',
password: '',
host: '0.0.1.0',
hostname: '0.0.1.0',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://256.com',
base: 'http://other.com/',
href: 'http://256.com/',
origin: 'http://256.com',
protocol: 'http:',
username: '',
password: '',
host: '256.com',
hostname: '256.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://999999999',
base: 'http://other.com/',
href: 'http://59.154.201.255/',
origin: 'http://59.154.201.255',
protocol: 'http:',
username: '',
password: '',
host: '59.154.201.255',
hostname: '59.154.201.255',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://999999999.com',
base: 'http://other.com/',
href: 'http://999999999.com/',
origin: 'http://999999999.com',
protocol: 'http:',
username: '',
password: '',
host: '999999999.com',
hostname: '999999999.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://10000000000',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://10000000000.com',
base: 'http://other.com/',
href: 'http://10000000000.com/',
origin: 'http://10000000000.com',
protocol: 'http:',
username: '',
password: '',
host: '10000000000.com',
hostname: '10000000000.com',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://4294967295',
base: 'http://other.com/',
href: 'http://255.255.255.255/',
origin: 'http://255.255.255.255',
protocol: 'http:',
username: '',
password: '',
host: '255.255.255.255',
hostname: '255.255.255.255',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://4294967296',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://0xffffffff',
base: 'http://other.com/',
href: 'http://255.255.255.255/',
origin: 'http://255.255.255.255',
protocol: 'http:',
username: '',
password: '',
host: '255.255.255.255',
hostname: '255.255.255.255',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://0xffffffff1',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://256.256.256.256',
base: 'http://other.com/',
failure: true,
},
{
input: 'http://256.256.256.256.256',
base: 'http://other.com/',
href: 'http://256.256.256.256.256/',
origin: 'http://256.256.256.256.256',
protocol: 'http:',
username: '',
password: '',
host: '256.256.256.256.256',
hostname: '256.256.256.256.256',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'https://0x.0x.0',
base: 'about:blank',
href: 'https://0.0.0.0/',
origin: 'https://0.0.0.0',
protocol: 'https:',
username: '',
password: '',
host: '0.0.0.0',
hostname: '0.0.0.0',
port: '',
pathname: '/',
search: '',
hash: '',
},
'More IPv4 parsing (via https://github.com/jsdom/whatwg-url/issues/92)',
{
input: 'https://0x100000000/test',
base: 'about:blank',
failure: true,
},
{
input: 'https://256.0.0.1/test',
base: 'about:blank',
failure: true,
},
"# file URLs containing percent-encoded Windows drive letters (shouldn't work)",
{
input: 'file:///C%3A/',
base: 'about:blank',
href: 'file:///C%3A/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C%3A/',
search: '',
hash: '',
},
{
input: 'file:///C%7C/',
base: 'about:blank',
href: 'file:///C%7C/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C%7C/',
search: '',
hash: '',
},
'# file URLs relative to other file URLs (via https://github.com/jsdom/whatwg-url/pull/60)',
{
input: 'pix/submit.gif',
base: 'file:///C:/Users/Domenic/Dropbox/GitHub/tmpvar/jsdom/test/level2/html/files/anchor.html',
href: 'file:///C:/Users/Domenic/Dropbox/GitHub/tmpvar/jsdom/test/level2/html/files/pix/submit.gif',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/Users/Domenic/Dropbox/GitHub/tmpvar/jsdom/test/level2/html/files/pix/submit.gif',
search: '',
hash: '',
},
{
input: '..',
base: 'file:///C:/',
href: 'file:///C:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/',
search: '',
hash: '',
},
{
input: '..',
base: 'file:///',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
'# More file URL tests by zcorpan and annevk',
{
input: '/',
base: 'file:///C:/a/b',
href: 'file:///C:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/',
search: '',
hash: '',
},
{
input: '//d:',
base: 'file:///C:/a/b',
href: 'file:///d:',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/d:',
search: '',
hash: '',
},
{
input: '//d:/..',
base: 'file:///C:/a/b',
href: 'file:///d:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/d:/',
search: '',
hash: '',
},
{
input: '..',
base: 'file:///ab:/',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: '..',
base: 'file:///1:/',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: '',
base: 'file:///test?test#test',
href: 'file:///test?test',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test',
search: '?test',
hash: '',
},
{
input: 'file:',
base: 'file:///test?test#test',
href: 'file:///test?test',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test',
search: '?test',
hash: '',
},
{
input: '?x',
base: 'file:///test?test#test',
href: 'file:///test?x',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test',
search: '?x',
hash: '',
},
{
input: 'file:?x',
base: 'file:///test?test#test',
href: 'file:///test?x',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test',
search: '?x',
hash: '',
},
{
input: '#x',
base: 'file:///test?test#test',
href: 'file:///test?test#x',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test',
search: '?test',
hash: '#x',
},
{
input: 'file:#x',
base: 'file:///test?test#test',
href: 'file:///test?test#x',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test',
search: '?test',
hash: '#x',
},
'# File URLs and many (back)slashes',
{
input: 'file:\\\\//',
base: 'about:blank',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'file:\\\\\\\\',
base: 'about:blank',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'file:\\\\\\\\?fox',
base: 'about:blank',
href: 'file:///?fox',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '?fox',
hash: '',
},
{
input: 'file:\\\\\\\\#guppy',
base: 'about:blank',
href: 'file:///#guppy',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '#guppy',
},
{
input: 'file://spider///',
base: 'about:blank',
href: 'file://spider/',
protocol: 'file:',
username: '',
password: '',
host: 'spider',
hostname: 'spider',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'file:\\\\localhost//',
base: 'about:blank',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'file:///localhost//cat',
base: 'about:blank',
href: 'file:///localhost//cat',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/localhost//cat',
search: '',
hash: '',
},
{
input: 'file://\\/localhost//cat',
base: 'about:blank',
href: 'file:///localhost//cat',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/localhost//cat',
search: '',
hash: '',
},
{
input: 'file://localhost//a//../..//',
base: 'about:blank',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: '/////mouse',
base: 'file:///elephant',
href: 'file:///mouse',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/mouse',
search: '',
hash: '',
},
{
input: '\\//pig',
base: 'file://lion/',
href: 'file:///pig',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/pig',
search: '',
hash: '',
},
{
input: '\\/localhost//pig',
base: 'file://lion/',
href: 'file:///pig',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/pig',
search: '',
hash: '',
},
{
input: '//localhost//pig',
base: 'file://lion/',
href: 'file:///pig',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/pig',
search: '',
hash: '',
},
{
input: '/..//localhost//pig',
base: 'file://lion/',
href: 'file://lion/localhost//pig',
protocol: 'file:',
username: '',
password: '',
host: 'lion',
hostname: 'lion',
port: '',
pathname: '/localhost//pig',
search: '',
hash: '',
},
{
input: 'file://',
base: 'file://ape/',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
'# File URLs with non-empty hosts',
{
input: '/rooibos',
base: 'file://tea/',
href: 'file://tea/rooibos',
protocol: 'file:',
username: '',
password: '',
host: 'tea',
hostname: 'tea',
port: '',
pathname: '/rooibos',
search: '',
hash: '',
},
{
input: '/?chai',
base: 'file://tea/',
href: 'file://tea/?chai',
protocol: 'file:',
username: '',
password: '',
host: 'tea',
hostname: 'tea',
port: '',
pathname: '/',
search: '?chai',
hash: '',
},
"# Windows drive letter handling with the 'file:' base URL",
{
input: 'C|',
base: 'file://host/dir/file',
href: 'file:///C:',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:',
search: '',
hash: '',
},
{
input: 'C|#',
base: 'file://host/dir/file',
href: 'file:///C:#',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:',
search: '',
hash: '',
},
{
input: 'C|?',
base: 'file://host/dir/file',
href: 'file:///C:?',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:',
search: '',
hash: '',
},
{
input: 'C|/',
base: 'file://host/dir/file',
href: 'file:///C:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/',
search: '',
hash: '',
},
{
input: 'C|\n/',
base: 'file://host/dir/file',
href: 'file:///C:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/',
search: '',
hash: '',
},
{
input: 'C|\\',
base: 'file://host/dir/file',
href: 'file:///C:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/',
search: '',
hash: '',
},
{
input: 'C',
base: 'file://host/dir/file',
href: 'file://host/dir/C',
protocol: 'file:',
username: '',
password: '',
host: 'host',
hostname: 'host',
port: '',
pathname: '/dir/C',
search: '',
hash: '',
},
{
input: 'C|a',
base: 'file://host/dir/file',
href: 'file://host/dir/C|a',
protocol: 'file:',
username: '',
password: '',
host: 'host',
hostname: 'host',
port: '',
pathname: '/dir/C|a',
search: '',
hash: '',
},
'# Windows drive letter quirk in the file slash state',
{
input: '/c:/foo/bar',
base: 'file:///c:/baz/qux',
href: 'file:///c:/foo/bar',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/c:/foo/bar',
search: '',
hash: '',
},
{
input: '/c|/foo/bar',
base: 'file:///c:/baz/qux',
href: 'file:///c:/foo/bar',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/c:/foo/bar',
search: '',
hash: '',
},
{
input: 'file:\\c:\\foo\\bar',
base: 'file:///c:/baz/qux',
href: 'file:///c:/foo/bar',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/c:/foo/bar',
search: '',
hash: '',
},
{
input: '/c:/foo/bar',
base: 'file://host/path',
href: 'file:///c:/foo/bar',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/c:/foo/bar',
search: '',
hash: '',
},
'# Windows drive letter quirk with not empty host',
{
input: 'file://example.net/C:/',
base: 'about:blank',
href: 'file:///C:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/',
search: '',
hash: '',
},
{
input: 'file://1.2.3.4/C:/',
base: 'about:blank',
href: 'file:///C:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/',
search: '',
hash: '',
},
{
input: 'file://[1::8]/C:/',
base: 'about:blank',
href: 'file:///C:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/',
search: '',
hash: '',
},
'# Windows drive letter quirk (no host)',
{
input: 'file:/C|/',
base: 'about:blank',
href: 'file:///C:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/',
search: '',
hash: '',
},
{
input: 'file://C|/',
base: 'about:blank',
href: 'file:///C:/',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/C:/',
search: '',
hash: '',
},
'# file URLs without base URL by Rimas Misevičius',
{
input: 'file:',
base: 'about:blank',
href: 'file:///',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'file:?q=v',
base: 'about:blank',
href: 'file:///?q=v',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '?q=v',
hash: '',
},
{
input: 'file:#frag',
base: 'about:blank',
href: 'file:///#frag',
protocol: 'file:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '#frag',
},
'# IPv6 tests',
{
input: 'http://[1:0::]',
base: 'http://example.net/',
href: 'http://[1::]/',
origin: 'http://[1::]',
protocol: 'http:',
username: '',
password: '',
host: '[1::]',
hostname: '[1::]',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://[0:1:2:3:4:5:6:7:8]',
base: 'http://example.net/',
failure: true,
},
{
input: 'https://[0::0::0]',
base: 'about:blank',
failure: true,
},
{
input: 'https://[0:.0]',
base: 'about:blank',
failure: true,
},
{
input: 'https://[0:0:]',
base: 'about:blank',
failure: true,
},
{
input: 'https://[0:1:2:3:4:5:6:7.0.0.0.1]',
base: 'about:blank',
failure: true,
},
{
input: 'https://[0:1.00.0.0.0]',
base: 'about:blank',
failure: true,
},
{
input: 'https://[0:1.290.0.0.0]',
base: 'about:blank',
failure: true,
},
{
input: 'https://[0:1.23.23]',
base: 'about:blank',
failure: true,
},
'# Empty host',
{
input: 'http://?',
base: 'about:blank',
failure: true,
},
{
input: 'http://#',
base: 'about:blank',
failure: true,
},
'Port overflow (2^32 + 81)',
{
input: 'http://f:4294967377/c',
base: 'http://example.org/',
failure: true,
},
'Port overflow (2^64 + 81)',
{
input: 'http://f:18446744073709551697/c',
base: 'http://example.org/',
failure: true,
},
'Port overflow (2^128 + 81)',
{
input: 'http://f:340282366920938463463374607431768211537/c',
base: 'http://example.org/',
failure: true,
},
'# Non-special-URL path tests',
{
input: 'sc://ñ',
base: 'about:blank',
href: 'sc://%C3%B1',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '%C3%B1',
hostname: '%C3%B1',
port: '',
pathname: '',
search: '',
hash: '',
},
{
input: 'sc://ñ?x',
base: 'about:blank',
href: 'sc://%C3%B1?x',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '%C3%B1',
hostname: '%C3%B1',
port: '',
pathname: '',
search: '?x',
hash: '',
},
{
input: 'sc://ñ#x',
base: 'about:blank',
href: 'sc://%C3%B1#x',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '%C3%B1',
hostname: '%C3%B1',
port: '',
pathname: '',
search: '',
hash: '#x',
},
{
input: '#x',
base: 'sc://ñ',
href: 'sc://%C3%B1#x',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '%C3%B1',
hostname: '%C3%B1',
port: '',
pathname: '',
search: '',
hash: '#x',
},
{
input: '?x',
base: 'sc://ñ',
href: 'sc://%C3%B1?x',
origin: 'null',
protocol: 'sc:',
username: '',
password: '',
host: '%C3%B1',
hostname: '%C3%B1',
port: '',
pathname: '',
search: '?x',
hash: '',
},
{
input: 'sc://?',
base: 'about:blank',
href: 'sc://?',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '',
search: '',
hash: '',
},
{
input: 'sc://#',
base: 'about:blank',
href: 'sc://#',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '',
search: '',
hash: '',
},
{
input: '///',
base: 'sc://x/',
href: 'sc:///',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: '////',
base: 'sc://x/',
href: 'sc:////',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '//',
search: '',
hash: '',
},
{
input: '////x/',
base: 'sc://x/',
href: 'sc:////x/',
protocol: 'sc:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '//x/',
search: '',
hash: '',
},
{
input: 'tftp://foobar.com/someconfig;mode=netascii',
base: 'about:blank',
href: 'tftp://foobar.com/someconfig;mode=netascii',
origin: 'null',
protocol: 'tftp:',
username: '',
password: '',
host: 'foobar.com',
hostname: 'foobar.com',
port: '',
pathname: '/someconfig;mode=netascii',
search: '',
hash: '',
},
{
input: 'telnet://user:pass@foobar.com:23/',
base: 'about:blank',
href: 'telnet://user:pass@foobar.com:23/',
origin: 'null',
protocol: 'telnet:',
username: 'user',
password: 'pass',
host: 'foobar.com:23',
hostname: 'foobar.com',
port: '23',
pathname: '/',
search: '',
hash: '',
},
{
input: 'ut2004://10.10.10.10:7777/Index.ut2',
base: 'about:blank',
href: 'ut2004://10.10.10.10:7777/Index.ut2',
origin: 'null',
protocol: 'ut2004:',
username: '',
password: '',
host: '10.10.10.10:7777',
hostname: '10.10.10.10',
port: '7777',
pathname: '/Index.ut2',
search: '',
hash: '',
},
{
input: 'redis://foo:bar@somehost:6379/0?baz=bam&qux=baz',
base: 'about:blank',
href: 'redis://foo:bar@somehost:6379/0?baz=bam&qux=baz',
origin: 'null',
protocol: 'redis:',
username: 'foo',
password: 'bar',
host: 'somehost:6379',
hostname: 'somehost',
port: '6379',
pathname: '/0',
search: '?baz=bam&qux=baz',
hash: '',
},
{
input: 'rsync://foo@host:911/sup',
base: 'about:blank',
href: 'rsync://foo@host:911/sup',
origin: 'null',
protocol: 'rsync:',
username: 'foo',
password: '',
host: 'host:911',
hostname: 'host',
port: '911',
pathname: '/sup',
search: '',
hash: '',
},
{
input: 'git://github.com/foo/bar.git',
base: 'about:blank',
href: 'git://github.com/foo/bar.git',
origin: 'null',
protocol: 'git:',
username: '',
password: '',
host: 'github.com',
hostname: 'github.com',
port: '',
pathname: '/foo/bar.git',
search: '',
hash: '',
},
{
input: 'irc://myserver.com:6999/channel?passwd',
base: 'about:blank',
href: 'irc://myserver.com:6999/channel?passwd',
origin: 'null',
protocol: 'irc:',
username: '',
password: '',
host: 'myserver.com:6999',
hostname: 'myserver.com',
port: '6999',
pathname: '/channel',
search: '?passwd',
hash: '',
},
{
input: 'dns://fw.example.org:9999/foo.bar.org?type=TXT',
base: 'about:blank',
href: 'dns://fw.example.org:9999/foo.bar.org?type=TXT',
origin: 'null',
protocol: 'dns:',
username: '',
password: '',
host: 'fw.example.org:9999',
hostname: 'fw.example.org',
port: '9999',
pathname: '/foo.bar.org',
search: '?type=TXT',
hash: '',
},
{
input: 'ldap://localhost:389/ou=People,o=JNDITutorial',
base: 'about:blank',
href: 'ldap://localhost:389/ou=People,o=JNDITutorial',
origin: 'null',
protocol: 'ldap:',
username: '',
password: '',
host: 'localhost:389',
hostname: 'localhost',
port: '389',
pathname: '/ou=People,o=JNDITutorial',
search: '',
hash: '',
},
{
input: 'git+https://github.com/foo/bar',
base: 'about:blank',
href: 'git+https://github.com/foo/bar',
origin: 'null',
protocol: 'git+https:',
username: '',
password: '',
host: 'github.com',
hostname: 'github.com',
port: '',
pathname: '/foo/bar',
search: '',
hash: '',
},
{
input: 'urn:ietf:rfc:2648',
base: 'about:blank',
href: 'urn:ietf:rfc:2648',
origin: 'null',
protocol: 'urn:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'ietf:rfc:2648',
search: '',
hash: '',
},
{
input: 'tag:joe@example.org,2001:foo/bar',
base: 'about:blank',
href: 'tag:joe@example.org,2001:foo/bar',
origin: 'null',
protocol: 'tag:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'joe@example.org,2001:foo/bar',
search: '',
hash: '',
},
'# percent encoded hosts in non-special-URLs',
{
input: 'non-special://%E2%80%A0/',
base: 'about:blank',
href: 'non-special://%E2%80%A0/',
protocol: 'non-special:',
username: '',
password: '',
host: '%E2%80%A0',
hostname: '%E2%80%A0',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'non-special://H%4fSt/path',
base: 'about:blank',
href: 'non-special://H%4fSt/path',
protocol: 'non-special:',
username: '',
password: '',
host: 'H%4fSt',
hostname: 'H%4fSt',
port: '',
pathname: '/path',
search: '',
hash: '',
},
'# IPv6 in non-special-URLs',
{
input: 'non-special://[1:2:0:0:5:0:0:0]/',
base: 'about:blank',
href: 'non-special://[1:2:0:0:5::]/',
protocol: 'non-special:',
username: '',
password: '',
host: '[1:2:0:0:5::]',
hostname: '[1:2:0:0:5::]',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'non-special://[1:2:0:0:0:0:0:3]/',
base: 'about:blank',
href: 'non-special://[1:2::3]/',
protocol: 'non-special:',
username: '',
password: '',
host: '[1:2::3]',
hostname: '[1:2::3]',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'non-special://[1:2::3]:80/',
base: 'about:blank',
href: 'non-special://[1:2::3]:80/',
protocol: 'non-special:',
username: '',
password: '',
host: '[1:2::3]:80',
hostname: '[1:2::3]',
port: '80',
pathname: '/',
search: '',
hash: '',
},
{
input: 'non-special://[:80/',
base: 'about:blank',
failure: true,
},
{
input: 'blob:https://example.com:443/',
base: 'about:blank',
href: 'blob:https://example.com:443/',
protocol: 'blob:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'https://example.com:443/',
search: '',
hash: '',
},
{
input: 'blob:d3958f5c-0777-0845-9dcf-2cb28783acaf',
base: 'about:blank',
href: 'blob:d3958f5c-0777-0845-9dcf-2cb28783acaf',
protocol: 'blob:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: 'd3958f5c-0777-0845-9dcf-2cb28783acaf',
search: '',
hash: '',
},
'Invalid IPv4 radix digits',
{
input: 'http://0177.0.0.0189',
base: 'about:blank',
href: 'http://0177.0.0.0189/',
protocol: 'http:',
username: '',
password: '',
host: '0177.0.0.0189',
hostname: '0177.0.0.0189',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://0x7f.0.0.0x7g',
base: 'about:blank',
href: 'http://0x7f.0.0.0x7g/',
protocol: 'http:',
username: '',
password: '',
host: '0x7f.0.0.0x7g',
hostname: '0x7f.0.0.0x7g',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://0X7F.0.0.0X7G',
base: 'about:blank',
href: 'http://0x7f.0.0.0x7g/',
protocol: 'http:',
username: '',
password: '',
host: '0x7f.0.0.0x7g',
hostname: '0x7f.0.0.0x7g',
port: '',
pathname: '/',
search: '',
hash: '',
},
'Invalid IPv4 portion of IPv6 address',
{
input: 'http://[::127.0.0.0.1]',
base: 'about:blank',
failure: true,
},
'Uncompressed IPv6 addresses with 0',
{
input: 'http://[0:1:0:1:0:1:0:1]',
base: 'about:blank',
href: 'http://[0:1:0:1:0:1:0:1]/',
protocol: 'http:',
username: '',
password: '',
host: '[0:1:0:1:0:1:0:1]',
hostname: '[0:1:0:1:0:1:0:1]',
port: '',
pathname: '/',
search: '',
hash: '',
},
{
input: 'http://[1:0:1:0:1:0:1:0]',
base: 'about:blank',
href: 'http://[1:0:1:0:1:0:1:0]/',
protocol: 'http:',
username: '',
password: '',
host: '[1:0:1:0:1:0:1:0]',
hostname: '[1:0:1:0:1:0:1:0]',
port: '',
pathname: '/',
search: '',
hash: '',
},
'Percent-encoded query and fragment',
{
input: 'http://example.org/test?\u0022',
base: 'about:blank',
href: 'http://example.org/test?%22',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/test',
search: '?%22',
hash: '',
},
{
input: 'http://example.org/test?\u0023',
base: 'about:blank',
href: 'http://example.org/test?#',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/test',
search: '',
hash: '',
},
{
input: 'http://example.org/test?\u003C',
base: 'about:blank',
href: 'http://example.org/test?%3C',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/test',
search: '?%3C',
hash: '',
},
{
input: 'http://example.org/test?\u003E',
base: 'about:blank',
href: 'http://example.org/test?%3E',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/test',
search: '?%3E',
hash: '',
},
{
input: 'http://example.org/test?\u2323',
base: 'about:blank',
href: 'http://example.org/test?%E2%8C%A3',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/test',
search: '?%E2%8C%A3',
hash: '',
},
{
input: 'http://example.org/test?%23%23',
base: 'about:blank',
href: 'http://example.org/test?%23%23',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/test',
search: '?%23%23',
hash: '',
},
/*
{
input: 'http://example.org/test?%GH',
base: 'about:blank',
href: 'http://example.org/test?%GH',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/test',
search: '?%GH',
hash: '',
},
*/
{
input: 'http://example.org/test?a#%EF',
base: 'about:blank',
href: 'http://example.org/test?a#%EF',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/test',
search: '?a',
hash: '#%EF',
},
{
input: 'http://example.org/test?a#%GH',
base: 'about:blank',
href: 'http://example.org/test?a#%GH',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/test',
search: '?a',
hash: '#%GH',
},
'URLs that require a non-about:blank base. (Also serve as invalid base tests.)',
{
input: 'a',
base: 'about:blank',
failure: true,
},
{
input: 'a/',
base: 'about:blank',
failure: true,
},
{
input: 'a//',
base: 'about:blank',
failure: true,
},
"Bases that don't fail to parse but fail to be bases",
{
input: 'test-a-colon.html',
base: 'a:',
failure: true,
},
{
input: 'test-a-colon-b.html',
base: 'a:b',
failure: true,
},
'Other base URL tests, that must succeed',
{
input: 'test-a-colon-slash.html',
base: 'a:/',
href: 'a:/test-a-colon-slash.html',
protocol: 'a:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test-a-colon-slash.html',
search: '',
hash: '',
},
{
input: 'test-a-colon-slash-slash.html',
base: 'a://',
href: 'a:///test-a-colon-slash-slash.html',
protocol: 'a:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test-a-colon-slash-slash.html',
search: '',
hash: '',
},
{
input: 'test-a-colon-slash-b.html',
base: 'a:/b',
href: 'a:/test-a-colon-slash-b.html',
protocol: 'a:',
username: '',
password: '',
host: '',
hostname: '',
port: '',
pathname: '/test-a-colon-slash-b.html',
search: '',
hash: '',
},
{
input: 'test-a-colon-slash-slash-b.html',
base: 'a://b',
href: 'a://b/test-a-colon-slash-slash-b.html',
protocol: 'a:',
username: '',
password: '',
host: 'b',
hostname: 'b',
port: '',
pathname: '/test-a-colon-slash-slash-b.html',
search: '',
hash: '',
},
'Null code point in fragment',
{
input: 'http://example.org/test?a#b\u0000c',
base: 'about:blank',
href: 'http://example.org/test?a#bc',
protocol: 'http:',
username: '',
password: '',
host: 'example.org',
hostname: 'example.org',
port: '',
pathname: '/test',
search: '?a',
hash: '#bc',
},
];