Initial Sample.

This commit is contained in:
2024-06-03 20:23:50 +05:30
parent ef2b65f673
commit 5269ec3c66
2575 changed files with 282312 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import assert from 'assert';
import { parse } from './parse.js';
import { combineLatest } from '../../src/extras.js';
describe('extras/combineLatest', () => {
it('should emit arrays containing the most recent values', async () => {
let output = [];
await combineLatest(
parse('a-b-c-d'),
parse('-A-B-C-D')
).forEach(
value => output.push(value.join(''))
);
assert.deepEqual(output, [
'aA',
'bA',
'bB',
'cB',
'cC',
'dC',
'dD',
]);
});
it('should emit values in the correct order', async () => {
let output = [];
await combineLatest(
parse('-a-b-c-d'),
parse('A-B-C-D')
).forEach(
value => output.push(value.join(''))
);
assert.deepEqual(output, [
'aA',
'aB',
'bB',
'bC',
'cC',
'cD',
'dD',
]);
});
});

View File

@@ -0,0 +1,16 @@
import assert from 'assert';
import { parse } from './parse.js';
import { merge } from '../../src/extras.js';
describe('extras/merge', () => {
it('should emit all data from each input in parallel', async () => {
let output = '';
await merge(
parse('a-b-c-d'),
parse('-A-B-C-D')
).forEach(
value => output += value
);
assert.equal(output, 'aAbBcCdD');
});
});

View File

@@ -0,0 +1,11 @@
export function parse(string) {
return new Observable(async observer => {
await null;
for (let char of string) {
if (observer.closed) return;
else if (char !== '-') observer.next(char);
await null;
}
observer.complete();
});
}

View File

@@ -0,0 +1,21 @@
import assert from 'assert';
import { parse } from './parse.js';
import { zip } from '../../src/extras.js';
describe('extras/zip', () => {
it('should emit pairs of corresponding index values', async () => {
let output = [];
await zip(
parse('a-b-c-d'),
parse('-A-B-C-D')
).forEach(
value => output.push(value.join(''))
);
assert.deepEqual(output, [
'aA',
'bB',
'cC',
'dD',
]);
});
});