-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
es.array.iterator.js
100 lines (96 loc) · 2.4 KB
/
es.array.iterator.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import Symbol from 'core-js-pure/es/symbol';
import getIterator from 'core-js-pure/es/get-iterator';
import { keys, values, entries } from 'core-js-pure/es/array';
QUnit.test('Array#@@iterator', assert => {
assert.isFunction(values);
const iterator = getIterator(['q', 'w', 'e']);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Array Iterator');
assert.same(String(iterator), '[object Array Iterator]');
assert.deepEqual(iterator.next(), {
value: 'q',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'w',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'e',
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});
QUnit.test('Array#keys', assert => {
assert.isFunction(keys);
const iterator = keys(['q', 'w', 'e']);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Array Iterator');
assert.deepEqual(iterator.next(), {
value: 0,
done: false,
});
assert.deepEqual(iterator.next(), {
value: 1,
done: false,
});
assert.deepEqual(iterator.next(), {
value: 2,
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});
QUnit.test('Array#values', assert => {
assert.isFunction(values);
const iterator = values(['q', 'w', 'e']);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Array Iterator');
assert.deepEqual(iterator.next(), {
value: 'q',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'w',
done: false,
});
assert.deepEqual(iterator.next(), {
value: 'e',
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});
QUnit.test('Array#entries', assert => {
assert.isFunction(entries);
const iterator = entries(['q', 'w', 'e']);
assert.isIterator(iterator);
assert.isIterable(iterator);
assert.same(iterator[Symbol.toStringTag], 'Array Iterator');
assert.deepEqual(iterator.next(), {
value: [0, 'q'],
done: false,
});
assert.deepEqual(iterator.next(), {
value: [1, 'w'],
done: false,
});
assert.deepEqual(iterator.next(), {
value: [2, 'e'],
done: false,
});
assert.deepEqual(iterator.next(), {
value: undefined,
done: true,
});
});