effect-ts-laws
Version:
effect-ts law testing using fast-check.
102 lines • 3.95 kB
TypeScript
/**
* Arbitraries for basic effect-ts datatypes.
* @module
*/
import { Cause as CA, Either as EI, List as LI, Option as OP } from 'effect';
import type { Kind, TypeLambda } from 'effect/HKT';
import fc from 'fast-check';
import type { LiftArbitrary } from './types.js';
/**
* Returns an `Either` arbitrary given a pair of arbitraries for the underlying
* left and right values.
* @category arbitraries
*/
export declare const either: <A, E>(e: fc.Arbitrary<E>, a: fc.Arbitrary<A>) => fc.Arbitrary<EI.Either<A, E>>;
/**
* Returns an `Option` arbitrary given an arbitrary for the underlying value.
* @category arbitraries
*/
export declare const option: <A>(a: fc.Arbitrary<A>) => fc.Arbitrary<OP.Option<A>>;
/**
* An integer arbitrary small enough so that we can avoid having to think about
* numeric overflows in generated functions.
* @category arbitraries
*/
export declare const tinyInteger: fc.Arbitrary<number>;
/**
* A non-negative integer arbitrary small enough so that we can avoid having to
* think about numeric overflows in generated functions.
* @category arbitraries
*/
export declare const tinyNonNegative: fc.Arbitrary<number>;
/**
* A arbitrary for a tiny, possibly empty, string.
* @category arbitraries
*/
export declare const tinyString: fc.Arbitrary<string>;
/**
* An integer in the range 1…100.
* @category arbitraries
*/
export declare const tinyPositive: fc.Arbitrary<number>;
/**
* An array of tiny integers with max size fixed at 4.
* @category arbitraries
*/
export declare const tinyArray: <A>(a: fc.Arbitrary<A>) => fc.Arbitrary<A[]>;
/**
* An array of tiny integers with max size fixed at 4.
* @category arbitraries
*/
export declare const tinyIntegerArray: fc.Arbitrary<readonly number[]>;
/**
* Given a {@link LiftArbitrary} function, and 1..n `Arbitrary`s for
* different types `A₁, A₂, ...Aₙ`, returns the given list except every
* arbitrary for type `Aᵢ` has been replaced by an arbitrary for type
* `Kind<F, R, O, E, Aᵢ>`. For example:
* @example
* import {option, liftArbitraries, tinyPositive, tinyIntegerArray} from 'effect-ts-laws'
* import {OptionTypeLambda} from 'effect/Option'
* import fc from 'fast-check'
*
* const [positive, integerArray] = liftArbitraries<OptionTypeLambda>(
* option,
* )(
* tinyPositive,
* tinyIntegerArray,
* )
* // typeof positive ≡ fc.Arbitrary<Option<number>>
* // typeof integerArray ≡ fc.Arbitrary<Option<readonly number[]>>
*
* console.log(fc.sample(positive, {numRuns: 1}))
* console.table(fc.sample(integerArray, {numRuns: 1}))
* @category lifting
*/
export declare const liftArbitraries: <F extends TypeLambda, R = never, O = unknown, E = unknown>(liftArbitrary: LiftArbitrary<F, R, O, E>) => <const Arbs extends fc.Arbitrary<unknown>[]>(...arbs: Arbs) => { [K in keyof Arbs]: fc.Arbitrary<Kind<F, R, O, E, Arbs[K] extends fc.Arbitrary<infer T> ? T : never>>; };
/**
* Build an arbitrary error from an arbitrary of a message.
* @param message Arbitrary for the error message string.
* @returns Arbitrary error.
* @category arbitraries
*/
export declare const error: (message: fc.Arbitrary<string>) => fc.Arbitrary<Error>;
/**
* Build an arbitrary record with arbitrary string keys and
* values built from the given arbitrary.
* @param value Arbitrary for the record values.
* @returns Arbitrary record.
* @category arbitraries
*/
export declare const stringKeyRecord: <T>(value: fc.Arbitrary<T>) => fc.Arbitrary<Record<string, T>>;
/**
* Lift an arbitrary into an arbitrary for the effect-ts linked-list `List`
* type.
* @category arbitraries
*/
export declare const list: <A>(a: fc.Arbitrary<A>) => fc.Arbitrary<LI.List<A>>;
/**
* Arbitrary [Cause](https://effect-ts.github.io/effect/effect/Cause.ts.html).
* @category arbitraries
*/
export declare const cause: <A>(a: fc.Arbitrary<A>, defect?: fc.Arbitrary<unknown>) => fc.Arbitrary<CA.Cause<A>>;
//# sourceMappingURL=data.d.ts.map