Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
QUnit.test('Iterator#map', assert => {
const { map } = Iterator.prototype;
assert.isFunction(map);
assert.arity(map, 1);
assert.nonEnumerable(Iterator.prototype, 'map');
assert.arrayEqual(map.call(createIterator([1, 2, 3]), it => it ** 2).toArray(), [1, 4, 9], 'basic functionality');
map.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
}).toArray();
assert.throws(() => map.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => map.call(null, () => { /* empty */ }), TypeError);
assert.throws(() => map.call({}, () => { /* empty */ }), TypeError);
assert.throws(() => map.call([], () => { /* empty */ }), TypeError);
assert.throws(() => map.call(createIterator([1]), undefined), TypeError);
assert.throws(() => map.call(createIterator([1]), null), TypeError);
assert.throws(() => map.call(createIterator([1]), {}), TypeError);
});QUnit.test('Iterator#every', assert => {
const { every } = Iterator.prototype;
assert.isFunction(every);
assert.arity(every, 1);
assert.nonEnumerable(Iterator.prototype, 'every');
assert.ok(every.call(createIterator([1, 2, 3]), it => typeof it == 'number'), 'basic functionality #1');
assert.ok(!every.call(createIterator([1, 2, 3]), it => it % 2), 'basic functionality #2');
every.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
assert.throws(() => every.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => every.call(null, () => { /* empty */ }), TypeError);
assert.throws(() => every.call({}, () => { /* empty */ }), TypeError);QUnit.test('Iterator#some', assert => {
const { some } = Iterator.prototype;
assert.isFunction(some);
assert.arity(some, 1);
assert.nonEnumerable(Iterator.prototype, 'some');
assert.ok(some.call(createIterator([1, 2, 3]), it => it % 2), 'basic functionality #1');
assert.ok(!some.call(createIterator([1, 2, 3]), it => typeof it == 'string'), 'basic functionality #2');
some.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
assert.throws(() => some.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => some.call(null, () => { /* empty */ }), TypeError);
assert.throws(() => some.call({}, () => { /* empty */ }), TypeError);QUnit.test('Iterator#forEach', assert => {
const { forEach } = Iterator.prototype;
assert.isFunction(forEach);
assert.arity(forEach, 1);
assert.nonEnumerable(Iterator.prototype, 'forEach');
const array = [];
forEach.call(createIterator([1, 2, 3]), it => array.push(it));
assert.arrayEqual(array, [1, 2, 3], 'basic functionality');
forEach.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
});
assert.throws(() => forEach.call(undefined, () => { /* empty */ }), TypeError);
assert.throws(() => forEach.call(null, () => { /* empty */ }), TypeError);
assert.throws(() => forEach.call({}, () => { /* empty */ }), TypeError);QUnit.test('Iterator#take', assert => {
const { take } = Iterator.prototype;
assert.isFunction(take);
assert.arity(take, 1);
assert.nonEnumerable(Iterator.prototype, 'take');
assert.arrayEqual(take.call(createIterator([1, 2, 3]), 2).toArray(), [1, 2], 'basic functionality');
assert.arrayEqual(take.call(createIterator([1, 2, 3]), 1.5).toArray(), [1], 'float');
assert.arrayEqual(take.call(createIterator([1, 2, 3]), 4).toArray(), [1, 2, 3], 'big');
assert.arrayEqual(take.call(createIterator([1, 2, 3]), 0).toArray(), [], 'zero');
assert.throws(() => take.call(undefined, 1), TypeError);
assert.throws(() => take.call(null, 1), TypeError);
assert.throws(() => take.call({}, 1), TypeError);
assert.throws(() => take.call([], 1), TypeError);
assert.throws(() => take.call(createIterator([1, 2, 3]), -1), RangeError, 'negative');
});QUnit.test('Iterator#flatMap', assert => {
const { flatMap } = Iterator.prototype;
assert.isFunction(flatMap);
assert.arity(flatMap, 1);
assert.nonEnumerable(Iterator.prototype, 'flatMap');
assert.arrayEqual(
flatMap.call(createIterator([1, [], 2, createIterable([3, 4]), [5, 6], 'ab']), it => typeof it == 'number' ? [-it] : it).toArray(),
[-1, -2, 3, 4, 5, 6, 'a', 'b'],
'basic functionality',
);
flatMap.call(createIterator([1]), function (arg) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 1, 'arguments length');
assert.same(arg, 1, 'argument');
return [arg];
}).toArray();QUnit.test('Iterator#drop', assert => {
const { drop } = Iterator.prototype;
assert.isFunction(drop);
assert.arity(drop, 1);
assert.nonEnumerable(Iterator.prototype, 'drop');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 1).toArray(), [2, 3], 'basic functionality');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 1.5).toArray(), [2, 3], 'float');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 4).toArray(), [], 'big');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 0).toArray(), [1, 2, 3], 'zero');
assert.throws(() => drop.call(undefined, 1), TypeError);
assert.throws(() => drop.call(null, 1), TypeError);
assert.throws(() => drop.call({}, 1), TypeError);
assert.throws(() => drop.call([], 1), TypeError);
assert.throws(() => drop.call(createIterator([1, 2, 3]), -1), RangeError, 'negative');
});QUnit.test('Iterator#reduce', assert => {
const { reduce } = Iterator.prototype;
assert.isFunction(reduce);
assert.arity(reduce, 1);
assert.nonEnumerable(Iterator.prototype, 'reduce');
assert.same(reduce.call(createIterator([1, 2, 3]), (a, b) => a + b, 1), 7, 'basic functionality');
assert.same(reduce.call(createIterator([1, 2, 3]), (a, b) => a + b), 6, 'basic functionality, no init');
reduce.call(createIterator([2]), function (a, b) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 2, 'arguments length');
assert.same(a, 1, 'argument 1');
assert.same(b, 2, 'argument 2');
}, 1);
assert.throws(() => reduce.call(undefined, (a, b) => a + b, 0), TypeError);
assert.throws(() => reduce.call(null, (a, b) => a + b, 0), TypeError);QUnit.test('Iterator#drop', assert => {
const { drop } = Iterator.prototype;
assert.isFunction(drop);
assert.arity(drop, 1);
assert.nonEnumerable(Iterator.prototype, 'drop');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 1).toArray(), [2, 3], 'basic functionality');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 1.5).toArray(), [2, 3], 'float');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 4).toArray(), [], 'big');
assert.arrayEqual(drop.call(createIterator([1, 2, 3]), 0).toArray(), [1, 2, 3], 'zero');
assert.throws(() => drop.call(undefined, 1), TypeError);
assert.throws(() => drop.call(null, 1), TypeError);
assert.throws(() => drop.call({}, 1), TypeError);
assert.throws(() => drop.call([], 1), TypeError);
assert.throws(() => drop.call(createIterator([1, 2, 3]), -1), RangeError, 'negative');
});QUnit.test('Iterator#reduce', assert => {
const { reduce } = Iterator.prototype;
assert.isFunction(reduce);
assert.arity(reduce, 1);
assert.nonEnumerable(Iterator.prototype, 'reduce');
assert.same(reduce.call(createIterator([1, 2, 3]), (a, b) => a + b, 1), 7, 'basic functionality');
assert.same(reduce.call(createIterator([1, 2, 3]), (a, b) => a + b), 6, 'basic functionality, no init');
reduce.call(createIterator([2]), function (a, b) {
assert.same(this, STRICT_THIS, 'this');
assert.same(arguments.length, 2, 'arguments length');
assert.same(a, 1, 'argument 1');
assert.same(b, 2, 'argument 2');
}, 1);
assert.throws(() => reduce.call(undefined, (a, b) => a + b, 0), TypeError);
assert.throws(() => reduce.call(null, (a, b) => a + b, 0), TypeError);
assert.throws(() => reduce.call({}, (a, b) => a + b, 0), TypeError);
assert.throws(() => reduce.call([], (a, b) => a + b, 0), TypeError);
assert.throws(() => reduce.call(createIterator([1]), undefined, 1), TypeError);
assert.throws(() => reduce.call(createIterator([1]), null, 1), TypeError);