-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
esnext.set.intersection.js
38 lines (30 loc) · 1.88 KB
/
esnext.set.intersection.js
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
import { createIterable, createSetLike } from '../helpers/helpers';
QUnit.test('Set#intersection', assert => {
const { intersection } = Set.prototype;
const { from } = Array;
assert.isFunction(intersection);
assert.arity(intersection, 1);
assert.name(intersection, 'intersection');
assert.looksNative(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]))), [2, 3]);
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]))), [2, 3]);
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);
});