Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 30, 2024
1 parent c8cf491 commit 0ea5525
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/unit-global/es.set.difference.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ QUnit.test('Set#difference', assert => {
assert.deepEqual(from(new Set([1, 2, 3]).difference([3, 4])), [1, 2]);
assert.deepEqual(from(new Set([1, 2, 3]).difference(createIterable([3, 4]))), [1, 2]);

assert.same(new Set([42, 43]).difference({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}).size, 0);

assert.throws(() => new Set().difference({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set([1, 2, 3]).difference(), TypeError);

assert.throws(() => difference.call({}, [1, 2, 3]), TypeError);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit-global/es.set.intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ QUnit.test('Set#intersection', assert => {
assert.deepEqual(from(new Set([1, 2, 3]).intersection([2, 3, 4])), [2, 3]);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(createIterable([2, 3, 4]))), [2, 3]);

assert.deepEqual(from(new Set([42, 43]).intersection({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
})), [42, 43]);

assert.throws(() => new Set().intersection({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set([1, 2, 3]).intersection(), TypeError);

assert.throws(() => intersection.call({}, [1, 2, 3]), TypeError);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit-global/es.set.is-disjoint-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ QUnit.test('Set#isDisjointFrom', assert => {
assert.true(new Set([1]).isDisjointFrom(createIterable([2])));
assert.false(new Set([1]).isDisjointFrom(createIterable([1])));

assert.false(new Set([42, 43]).isDisjointFrom({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set().isDisjointFrom({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

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);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit-global/es.set.is-subset-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ QUnit.test('Set#isSubsetOf', assert => {
assert.true(new Set([1]).isSubsetOf(createIterable([1, 2, 3])));
assert.false(new Set([1]).isSubsetOf(createIterable([2, 3, 4])));

assert.true(new Set([42, 43]).isSubsetOf({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set().isSubsetOf({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set([1, 2, 3]).isSubsetOf(), TypeError);
assert.throws(() => isSubsetOf.call({}, [1, 2, 3]), TypeError);
assert.throws(() => isSubsetOf.call(undefined, [1, 2, 3]), TypeError);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit-global/es.set.is-superset-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ QUnit.test('Set#isSupersetOf', assert => {
assert.true(new Set([1, 2, 3]).isSupersetOf(createIterable([1])));
assert.false(new Set([2, 3, 4]).isSupersetOf(createIterable([1])));

assert.false(new Set([42, 43]).isSupersetOf({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set().isSupersetOf({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

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);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit-pure/es.set.difference.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ QUnit.test('Set#difference', assert => {
assert.deepEqual(from(new Set([1, 2, 3]).difference([3, 4])), [1, 2]);
assert.deepEqual(from(new Set([1, 2, 3]).difference(createIterable([3, 4]))), [1, 2]);

assert.same(new Set([42, 43]).difference({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}).size, 0);

assert.throws(() => new Set().difference({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set([1, 2, 3]).difference(), TypeError);

assert.throws(() => difference.call({}, [1, 2, 3]), TypeError);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit-pure/es.set.intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ QUnit.test('Set#intersection', assert => {
assert.deepEqual(from(new Set([1, 2, 3]).intersection([2, 3, 4])), [2, 3]);
assert.deepEqual(from(new Set([1, 2, 3]).intersection(createIterable([2, 3, 4]))), [2, 3]);

assert.deepEqual(from(new Set([42, 43]).intersection({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
})), [42, 43]);

assert.throws(() => new Set().intersection({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set([1, 2, 3]).intersection(), TypeError);

assert.throws(() => intersection.call({}, [1, 2, 3]), TypeError);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit-pure/es.set.is-disjoint-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ QUnit.test('Set#isDisjointFrom', assert => {
assert.true(new Set([1]).isDisjointFrom(createIterable([2])));
assert.false(new Set([1]).isDisjointFrom(createIterable([1])));

assert.false(new Set([42, 43]).isDisjointFrom({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set().isDisjointFrom({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

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);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit-pure/es.set.is-subset-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ QUnit.test('Set#isSubsetOf', assert => {
assert.true(new Set([1]).isSubsetOf(createIterable([1, 2, 3])));
assert.false(new Set([1]).isSubsetOf(createIterable([2, 3, 4])));

assert.true(new Set([42, 43]).isSubsetOf({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set().isSubsetOf({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set([1, 2, 3]).isSubsetOf(), TypeError);
assert.throws(() => isSubsetOf.call({}, [1, 2, 3]), TypeError);
assert.throws(() => isSubsetOf.call(undefined, [1, 2, 3]), TypeError);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit-pure/es.set.is-superset-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ QUnit.test('Set#isSupersetOf', assert => {
assert.true(new Set([1, 2, 3]).isSupersetOf(createIterable([1])));
assert.false(new Set([2, 3, 4]).isSupersetOf(createIterable([1])));

assert.false(new Set([42, 43]).isSupersetOf({
size: Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

assert.throws(() => new Set().isSupersetOf({
size: -Infinity,
has() {
return true;
},
keys() {
throw new Error('Unexpected call to |keys| method');
},
}));

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);
Expand Down

0 comments on commit 0ea5525

Please sign in to comment.