effect@3.13.6
·
1017 commits
to main
since this release
Patch Changes
-
#4551
3154ce4Thanks @gcanti! - Arbitrary:makecalled onSchema.Classnow respects property annotations, closes #4550.Previously, when calling
Arbitrary.makeon aSchema.Class, property-specific annotations (such asarbitrary) were ignored, leading to unexpected values in generated instances.Before
Even though
ahad anarbitraryannotation, the generated values were random:import { Arbitrary, FastCheck, Schema } from "effect" class Class extends Schema.Class<Class>("Class")({ a: Schema.NumberFromString.annotations({ arbitrary: () => (fc) => fc.constant(1) }) }) {} console.log(FastCheck.sample(Arbitrary.make(Class), 5)) /* Example Output: [ Class { a: 2.6624670822171524e-44 }, Class { a: 3.4028177873105996e+38 }, Class { a: 3.402820626847944e+38 }, Class { a: 3.783505853677006e-44 }, Class { a: 3243685 } ] */
After
Now, the values respect the
arbitraryannotation and return the expected constant:import { Arbitrary, FastCheck, Schema } from "effect" class Class extends Schema.Class<Class>("Class")({ a: Schema.NumberFromString.annotations({ arbitrary: () => (fc) => fc.constant(1) }) }) {} console.log(FastCheck.sample(Arbitrary.make(Class), 5)) /* [ Class { a: 1 }, Class { a: 1 }, Class { a: 1 }, Class { a: 1 }, Class { a: 1 } ] */