Skip to content

Commit

Permalink
pipe tests updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Jan 25, 2025
1 parent afc4ade commit 7c5e45e
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 224 deletions.
108 changes: 52 additions & 56 deletions tests/pipe/async-iterable-output.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Pipe, PipeOperationSequence, transform } from "../../src";
import { Pipe, transform } from "../../src";
import { createPipe, infinite, set, single } from "../../src";
import {
createAsyncGeneratorFixture,
Expand All @@ -22,21 +22,17 @@ describe.each([
...dataProviderForStrings(),
...dataProviderForSets(),
...dataProviderForMaps(),
] as Array<[Pipe<any>, AsyncIterable<number> | AsyncIterator<number>, PipeOperationSequence<unknown[]>, Array<unknown>]>)(
])(
"Async Pipe Create With Iterable Output Test",
(
pipe: Pipe<any>,
input: AsyncIterable<number> | AsyncIterator<number>,
expected: Array<unknown>,
) => {
(pipe, input, expected) => {
it("", async () => {
const result = await pipe(input) as Iterable<unknown>;
const result = await (pipe as Pipe<any>)(input) as AsyncIterable<unknown>;
expect(await transform.toArrayAsync(result)).toEqual(expected);
});
},
);

function dataProviderForArrays() {
function dataProviderForArrays(): Array<[Pipe<any[]> | Pipe<[any, any]>, Array<any>, Array<any>]> {
return [
[
// TODO output type never
Expand Down Expand Up @@ -131,7 +127,7 @@ function dataProviderForArrays() {
];
}

function dataProviderForGenerators() {
function dataProviderForGenerators(): Array<[Pipe<any[]> | Pipe<[any, any]>, Generator<any>, Array<any>]> {
return [
[
createPipe(),
Expand Down Expand Up @@ -160,7 +156,7 @@ function dataProviderForGenerators() {
],
[
createPipe(),
createIterableFixture([1, 1, 2, 2, 3, 4, 5]),
createGeneratorFixture([1, 1, 2, 2, 3, 4, 5]),
[1, 1, 2, 2, 3, 4, 5],
],
[
Expand Down Expand Up @@ -231,47 +227,10 @@ function dataProviderForGenerators() {
createGeneratorFixture([1, 1, 2, 2, 3, 4, 5]),
[1, 4, 9],
],
[
createPipe<[
AsyncIterable<number>,
AsyncIterable<number>,
AsyncIterable<number>,
AsyncIterable<number>,
AsyncIterable<number>,
]>(
(input) => single.limitAsync(input, 3),
set.distinctAsync,
(input) => single.mapAsync(input, (x) => x**2),
(input) => single.filterAsync(input, (x) => x < 10),
),
infinite.count(1, 2),
[1, 9],
],
[
createPipe(
(input: AsyncIterable<number>) => single.limitAsync(input, 3),
set.distinctAsync,
(input) => single.mapAsync(input, (x) => x**2),
(input) => single.filterAsync(input, (x) => x < 10),
),
infinite.count(1, 2),
[1, 9],
],
[
createPipe(
(input: AsyncIterable<unknown>) => single.mapAsync(input, (x) => Number(x)),
(input) => single.limitAsync(input, 3),
set.distinctAsync,
(input) => single.mapAsync(input, (x) => x**2),
(input) => single.filterAsync(input, (x) => x < 10),
),
infinite.count(1, 2),
[1, 9],
],
];
}

function dataProviderForIterables() {
function dataProviderForIterables(): Array<[Pipe<any[]> | Pipe<[any, any]>, Iterable<any>, Array<any>]> {
return [
[
createPipe(),
Expand Down Expand Up @@ -371,10 +330,47 @@ function dataProviderForIterables() {
createIterableFixture([1, 1, 2, 2, 3, 4, 5]),
[1, 4, 9],
],
[
createPipe<[
AsyncIterable<number>,
AsyncIterable<number>,
AsyncIterable<number>,
AsyncIterable<number>,
AsyncIterable<number>,
]>(
(input) => single.limitAsync(input, 3),
set.distinctAsync,
(input) => single.mapAsync(input, (x) => x**2),
(input) => single.filterAsync(input, (x) => x < 10),
),
infinite.count(1, 2),
[1, 9],
],
[
createPipe(
(input: AsyncIterable<number>) => single.limitAsync(input, 3),
set.distinctAsync,
(input) => single.mapAsync(input, (x) => x**2),
(input) => single.filterAsync(input, (x) => x < 10),
),
infinite.count(1, 2),
[1, 9],
],
[
createPipe(
(input: AsyncIterable<unknown>) => single.mapAsync(input, (x) => Number(x)),
(input) => single.limitAsync(input, 3),
set.distinctAsync,
(input) => single.mapAsync(input, (x) => x**2),
(input) => single.filterAsync(input, (x) => x < 10),
),
infinite.count(1, 2),
[1, 9],
],
];
}

function dataProviderForIterators() {
function dataProviderForIterators(): Array<[Pipe<any[]> | Pipe<[any, any]>, Iterator<any>, Array<any>]> {
return [
[
createPipe<[
Expand Down Expand Up @@ -467,7 +463,7 @@ function dataProviderForIterators() {
];
}

function dataProviderForAsyncGenerators() {
function dataProviderForAsyncGenerators(): Array<[Pipe<any[]> | Pipe<[any, any]>, AsyncGenerator<any>, Array<any>]> {
return [
[
createPipe(),
Expand Down Expand Up @@ -570,7 +566,7 @@ function dataProviderForAsyncGenerators() {
];
}

function dataProviderForAsyncIterables() {
function dataProviderForAsyncIterables(): Array<[Pipe<any[]> | Pipe<[any, any]>, AsyncIterable<any>, Array<any>]> {
return [
[
createPipe(),
Expand Down Expand Up @@ -673,7 +669,7 @@ function dataProviderForAsyncIterables() {
];
}

function dataProviderForAsyncIterators() {
function dataProviderForAsyncIterators(): Array<[Pipe<any[]> | Pipe<[any, any]>, AsyncIterator<any>, Array<any>]> {
return [
[
createPipe<[
Expand Down Expand Up @@ -766,7 +762,7 @@ function dataProviderForAsyncIterators() {
];
}

function dataProviderForStrings() {
function dataProviderForStrings(): Array<[Pipe<any[]> | Pipe<[any, any]>, string, Array<any>]> {
return [
[
createPipe(),
Expand Down Expand Up @@ -868,7 +864,7 @@ function dataProviderForStrings() {
];
}

function dataProviderForSets() {
function dataProviderForSets(): Array<[Pipe<any[]> | Pipe<[any, any]>, Set<any>, Array<any>]> {
return [
[
createPipe(),
Expand Down Expand Up @@ -971,7 +967,7 @@ function dataProviderForSets() {
];
}

function dataProviderForMaps() {
function dataProviderForMaps(): Array<[Pipe<any[]> | Pipe<[any, any]>, Map<any, any>, Array<any>]> {
return [
[
createPipe(),
Expand Down
Loading

0 comments on commit 7c5e45e

Please sign in to comment.