Permalink
January 18, 2023 20:50
Newer
100644
48 lines (38 sloc)
1.14 KB
Ignoring revisions in .git-blame-ignore-revs.
1
'use strict';
2
3
var test = require('tape');
4
5
var stopIterationIterator = require('../');
6
7
test('stopIterationIterator', function (t) {
8
t.equal(typeof stopIterationIterator, 'function', 'stopIterationIterator is a function');
9
10
t.test('no StopIteration support', { skip: typeof StopIteration === 'object' }, function (st) {
11
st['throws'](
12
function () { stopIterationIterator(); },
13
SyntaxError,
14
'throws a SyntaxError when StopIteration is not supported'
15
);
16
17
st.end();
18
});
19
20
t.test('StopIteration support', { skip: typeof StopIteration !== 'object' }, function (st) {
21
var s = new Set([1, 2]);
22
23
var i = s.iterator();
24
st.equal(i.next(), 1, 'first item is 1');
25
st.equal(i.next(), 2, 'second item is 2');
26
try {
27
i.next();
28
st.fail();
29
} catch (e) {
30
st.equal(e, StopIteration, 'StopIteration thrown');
31
}
32
33
var m = new Map([[1, 'a'], [2, 'b']]);
34
var mi = m.iterator();
35
st.deepEqual(mi.next(), [1, 'a'], 'first item is 1 and a');
36
st.deepEqual(mi.next(), [2, 'b'], 'second item is 2 and b');
37
try {
38
mi.next();
39
st.fail();
40
} catch (e) {
41
st.equal(e, StopIteration, 'StopIteration thrown');
42
}
43
44
st.end();
45
});
46
47
t.end();
48
});