1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
/* eslint-disable es/no-bigint -- safe */
if (typeof BigInt == 'function') QUnit.test('BigInt.range', assert => {
const { range } = BigInt;
const { from } = Array;
assert.isFunction(range);
assert.name(range, 'range');
assert.arity(range, 3);
assert.looksNative(range);
assert.nonEnumerable(BigInt, 'range');
let iterator = range(BigInt(1), BigInt(2));
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.deepEqual(iterator.next(), {
value: BigInt(1),
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
assert.deepEqual(from(range(BigInt(-1), BigInt(5))), [BigInt(-1), BigInt(0), BigInt(1), BigInt(2), BigInt(3), BigInt(4)]);
assert.deepEqual(from(range(BigInt(-5), BigInt(1))), [BigInt(-5), BigInt(-4), BigInt(-3), BigInt(-2), BigInt(-1), BigInt(0)]);
assert.deepEqual(
from(range(BigInt('9007199254740991'), BigInt('9007199254740992'), { inclusive: true })),
[BigInt('9007199254740991'), BigInt('9007199254740992')],
);
assert.deepEqual(from(range(BigInt(0), BigInt(0))), []);
assert.deepEqual(from(range(BigInt(0), BigInt(-5), BigInt(1))), []);
iterator = range(BigInt(1), BigInt(3));
assert.deepEqual(iterator.start, BigInt(1));
assert.deepEqual(iterator.end, BigInt(3));
assert.deepEqual(iterator.step, BigInt(1));
assert.false(iterator.inclusive);
iterator = range(BigInt(-1), BigInt(-3), { inclusive: true });
assert.deepEqual(iterator.start, BigInt(-1));
assert.deepEqual(iterator.end, BigInt(-3));
assert.same(iterator.step, BigInt(-1));
assert.true(iterator.inclusive);
iterator = range(BigInt(-1), BigInt(-3), { step: BigInt(4), inclusive() { /* empty */ } });
assert.same(iterator.start, BigInt(-1));
assert.same(iterator.end, BigInt(-3));
assert.same(iterator.step, BigInt(4));
assert.true(iterator.inclusive);
iterator = range(BigInt(0), BigInt(5));
assert.throws(() => Object.getOwnPropertyDescriptor(iterator, 'start').get.call({}), TypeError);
assert.throws(() => range(Infinity, BigInt(10), BigInt(0)), TypeError);
assert.throws(() => range(-Infinity, BigInt(10), BigInt(0)), TypeError);
assert.throws(() => range(BigInt(0), BigInt(10), Infinity), TypeError);
assert.throws(() => range(BigInt(0), BigInt(10), { step: Infinity }), TypeError);
assert.throws(() => range({}, BigInt(1)), TypeError);
assert.throws(() => range(BigInt(1), {}), TypeError);
});
|