-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmisc_test.ts
61 lines (50 loc) · 1.5 KB
/
misc_test.ts
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
// Test functionality that doesn’t exist in both async and sync versions
import * as assert from 'node:assert/strict';
import test from 'node:test';
import '../src/install.js';
import { XAsyncIterator } from '../src/library-async.js';
import { XIterator } from '../src/library-sync.js';
//========== Polyfill ==========
test('Polyfill: AsyncIterator.from(syncIterable)', async (t) => {
const syncIterable = ['x', 'y']
assert.deepEqual(
await AsyncIterator.from(syncIterable).toArray(),
['x', 'y']
);
});
test('Polyfill: toAsync', (t) => {
assert.ok(
['a', 'b', 'c'].values().toAsync() instanceof AsyncIterator
);
});
test('Polyfill: flatMap', async (t) => {
assert.deepEqual(
await createAsyncIterator()
.flatMap(x => createAsyncIterator()).toArray(),
['a','b','c', 'a','b','c', 'a','b','c']
);
});
//========== Library ==========
test('Library: XAsyncIterator.from(syncIterable)', async (t) => {
const syncIterable = ['x', 'y'];
assert.deepEqual(
await XAsyncIterator.from(syncIterable).toArray(),
['x', 'y']
);
});
test('Library: toAsync', (t) => {
assert.ok(
XIterator.from(['a', 'b', 'c']).toAsync() instanceof XAsyncIterator
);
});
test('Polyfill: flatMap', async (t) => {
assert.deepEqual(
await XAsyncIterator.from(createAsyncIterator())
.flatMap(x => createAsyncIterator()).toArray(),
['a','b','c', 'a','b','c', 'a','b','c']
);
});
//========== Helpers ==========
async function* createAsyncIterator() {
yield 'a'; yield 'b'; yield 'c';
}