@unsplash/sum-types-fast-check
Version:
fast-check bindings for @unsplash/sum-types.
42 lines • 1.19 kB
TypeScript
/**
* @since 0.1.0
*/
import * as Sum from "@unsplash/sum-types";
import fc from "fast-check";
import type { Arbitrary } from "fast-check";
declare type Tag<A> = A extends Sum.Member<infer B, any> ? B : never;
declare type Value<A> = A extends Sum.Member<any, infer B> ? B : never;
declare type Arbs<A extends Sum.AnyMember> = {
readonly [B in A as Tag<B>]: Arbitrary<Value<B>>;
};
/**
* An `Arbitrary` for nullary member constructors.
*
* @since 0.1.0
*/
export declare const nullaryArb: Arbitrary<null>;
/**
* Given an `Arbitrary` instance for each member of `A`, returns an `Arbitrary`
* instance for all `A`.
*
* @example
* import * as Sum from '@unsplash/sum-types'
* import { getArb, nullaryArb } from '@unsplash/sum-types-fast-check'
* import fc from 'fast-check'
*
* type Weather
* = Sum.Member<'Sun'>
* | Sum.Member<'Rain', number>
*
* const Weather = Sum.create<Weather>()
*
* const arbWeather = getArb(Weather)({
* Sun: nullaryArb,
* Rain: fc.integer(),
* })
*
* @since 0.1.0
*/
export declare const getArb: <A extends Sum.AnyMember>(sum: Sum.Sum<A>) => (arbs: Arbs<A>) => fc.Arbitrary<A>;
export {};
//# sourceMappingURL=index.d.ts.map