Patch Changes
-
#4244
d7dac48
Thanks @gcanti! - Improve pattern handling by merging multiple patterns into a union, closes #4243.Previously, the algorithm always prioritized the first pattern when multiple patterns were encountered.
This fix introduces a merging strategy that combines patterns into a union (e.g.,
(?:${pattern1})|(?:${pattern2})
). By doing so, all patterns have an equal chance to generate values when usingFastCheck.stringMatching
.Example
import { Arbitrary, FastCheck, Schema } from "effect" // /^[^A-Z]*$/ (given by Lowercase) + /^0x[0-9a-f]{40}$/ const schema = Schema.Lowercase.pipe(Schema.pattern(/^0x[0-9a-f]{40}$/)) const arb = Arbitrary.make(schema) // Before this fix, the first pattern would always dominate, // making it impossible to generate values const sample = FastCheck.sample(arb, { numRuns: 100 }) console.log(sample)
-
#4252
1d7fd2b
Thanks @gcanti! - Fix: CorrectArbitrary.make
to support nestedTemplateLiteral
s.Previously,
Arbitrary.make
did not properly handle nestedTemplateLiteral
schemas, resulting in incorrect or empty outputs. This fix ensures that nested template literals are processed correctly, producing valid arbitrary values.Before
import { Arbitrary, FastCheck, Schema as S } from "effect" const schema = S.TemplateLiteral( "<", S.TemplateLiteral("h", S.Literal(1, 2)), ">" ) const arb = Arbitrary.make(schema) console.log(FastCheck.sample(arb, { numRuns: 10 })) /* Output: [ '<>', '<>', '<>', '<>', '<>', '<>', '<>', '<>', '<>', '<>' ] */
After
import { Arbitrary, FastCheck, Schema as S } from "effect" const schema = S.TemplateLiteral( "<", S.TemplateLiteral("h", S.Literal(1, 2)), ">" ) const arb = Arbitrary.make(schema) console.log(FastCheck.sample(arb, { numRuns: 10 })) /* Output: [ '<h2>', '<h2>', '<h2>', '<h2>', '<h2>', '<h1>', '<h2>', '<h1>', '<h1>', '<h1>' ] */
-
#4252
1d7fd2b
Thanks @gcanti! - Fix: AllowSchema.TemplateLiteral
to handle strings with linebreaks, closes #4251.Before
import { Schema } from "effect" const schema = Schema.TemplateLiteral("a: ", Schema.String) console.log(Schema.decodeSync(schema)("a: b \n c")) // throws: ParseError: Expected `a: ${string}`, actual "a: b \n c"
After
import { Schema } from "effect" const schema = Schema.TemplateLiteral("a: ", Schema.String) console.log(Schema.decodeSync(schema)("a: b \n c")) /* Output: a: b c */