Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | 41x 15x 15x 41x 14x 14x 41x 1x 1x 41x | import type {ParameterOverrides} from '#law'
import type {
Mono,
MonomorphicGiven,
MonomorphicGivenOf,
TypeclassInstances,
} from '#laws'
import {
buildMonomorphicLaws,
monoArbitrary,
monoEquivalence,
monoMonoid,
} from '#laws'
import {pipe} from 'effect'
import type {TypeLambda} from 'effect/HKT'
import {
MonoProps,
propsArbitrary,
propsEquivalence,
propsMonoid,
} from '../laws/typeclass/monomorphic/props.js'
import {verboseLawSets} from './testLaws.js'
/**
* Test typeclass laws on the given instances of some datatype `F`. All laws are
* monomorphic on an underlying type `A`.
* @param given - Test options for the datatype under test.
* @category vitest
*/
export const testTypeclassLawsFor =
<F extends TypeLambda, A, R = never, O = unknown, E = unknown>(
given: MonomorphicGivenOf<F, A, R, O, E>,
) =>
<Ins extends TypeclassInstances<F, A, R, O, E>>(
/**
* Instances to test. Key is typeclass name and value is the instance under
* test. For example, `{ Monad: Option.Monad }` will run the monad typeclass
* laws on `Option`.
*/
instances: Ins,
/** Optional runtime `fast-check` parameters. */
parameters?: ParameterOverrides,
): void => {
pipe(
instances,
buildMonomorphicLaws(given),
verboseLawSets.withParameters(parameters),
)
}
/**
* Test typeclass laws on the given instances of some datatype `F`. All laws are
* monomorphic on an underlying type of `Option<number@.`.
* At the property `testTypeclassLaws.underlyingProps` you will find the same
* function, except it uses the underlying type `{x: number; y: string}, useful
* when testing laws on React components, as they can only accept a single
* object argument.
* @param given - Test options for the datatype under test.
* @category vitest
*/
export const testTypeclassLaws =
<F extends TypeLambda, R = never, O = unknown, E = unknown>(
given: MonomorphicGiven<F, R, O, E>,
) =>
<Ins extends TypeclassInstances<F, Mono, R, O, E>>(
/**
* Instances to test. Key is typeclass name and value is the instance under
* test. For example, `{ Monad: Option.Monad }` will run the monad typeclass
* laws on `Option`.
*/
instances: Ins,
/** Optional runtime `fast-check` parameters. */
parameters?: ParameterOverrides,
) => {
testTypeclassLawsFor({
...given,
a: monoArbitrary,
equalsA: monoEquivalence,
Monoid: monoMonoid,
})(instances, parameters)
}
const underlyingProps =
<F extends TypeLambda, R = never, O = unknown, E = unknown>(
given: MonomorphicGiven<F, R, O, E>,
) =>
<Ins extends TypeclassInstances<F, MonoProps, R, O, E>>(
/**
* Instances to test. Key is typeclass name and value is the
* instance under test. For example, `{ Monad: Option.Monad }` will run the
* monad typeclass laws on `Option`.
*/
instances: Ins,
/** Optional runtime `fast-check` parameters. */
parameters?: ParameterOverrides,
) => {
testTypeclassLawsFor({
...given,
a: propsArbitrary,
equalsA: propsEquivalence,
Monoid: propsMonoid,
})(instances, parameters)
}
/**
* Test typeclass laws on the given instances of some datatype `F`. All laws are
* monomorphic on an underlying type of `{x: number; y: string}`.
* @param given - Test options for the datatype under test.
* @category vitest
*/
testTypeclassLaws.underlyingProps = underlyingProps
|