CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
index.js52 linesDownload Raw Back to test
1'use strict';2 3var test = require('tape');4 5var stopIterationIterator = require('../');6 7test('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			// @ts-expect-error13			function () { stopIterationIterator(); },14			SyntaxError,15			'throws a SyntaxError when StopIteration is not supported'16		);17 18		st.end();19	});20 21	t.test('StopIteration support', { skip: typeof StopIteration !== 'object' }, function (st) {22		// eslint-disable-next-line no-extra-parens23		var s = /** @type {Set<number> & { iterator(): SetIterator<number>}} */ (new Set([1, 2]));24 25		var i = s.iterator();26		st.equal(i.next(), 1, 'first item is 1');27		st.equal(i.next(), 2, 'second item is 2');28		try {29			i.next();30			st.fail();31		} catch (e) {32			st.equal(e, StopIteration, 'StopIteration thrown');33		}34 35		// eslint-disable-next-line no-extra-parens36		var m = /** @type {Map<number, string> & { iterator(): MapIterator<[string, number]>}} */ (new Map([[1, 'a'], [2, 'b']]));37		var mi = m.iterator();38		st.deepEqual(mi.next(), [1, 'a'], 'first item is 1 and a');39		st.deepEqual(mi.next(), [2, 'b'], 'second item is 2 and b');40		try {41			mi.next();42			st.fail();43		} catch (e) {44			st.equal(e, StopIteration, 'StopIteration thrown');45		}46 47		st.end();48	});49 50	t.end();51});52 
basant307/AI_Governance_Project · CoolFace