Skip to content

Commit

Permalink
Added a test for clearFunctionList().
Browse files Browse the repository at this point in the history
  • Loading branch information
uhop committed Sep 18, 2024
1 parent a004a2d commit 189fd31
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion tests/test-transducers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import test from 'tape-six';

import {streamToArray} from './helpers.mjs';
import chain, {gen, none, finalValue} from '../src/index.js';
import chain, {gen, none, finalValue, clearFunctionList} from '../src/index.js';
import fromIterable from '../src/utils/readableFrom.js';

test.asPromise('transducers: smoke test', (t, resolve) => {
Expand Down Expand Up @@ -98,3 +98,43 @@ test.asPromise('transducers: embedded arrays', (t, resolve) => {
resolve();
});
});

test.asPromise('transducers: optimize function lists', (t, resolve) => {
const output = [],
c = chain([
fromIterable([1, 2, 3]),
gen(
x => x * x,
x => finalValue(x),
x => 2 * x + 1
),
x => x + 1,
streamToArray(output)
]);

c.on('end', () => {
t.deepEqual(output, [1, 4, 9]);
resolve();
});
});

test.asPromise("transducers: don't optimize function lists", (t, resolve) => {
const output = [],
c = chain([
fromIterable([1, 2, 3]),
clearFunctionList(
gen(
x => x * x,
x => finalValue(x),
x => 2 * x + 1
)
),
x => x + 1,
streamToArray(output)
]);

c.on('end', () => {
t.deepEqual(output, [2, 5, 10]);
resolve();
});
});

0 comments on commit 189fd31

Please sign in to comment.