-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve pattern handling by merging multiple patterns into a union, c… (
- Loading branch information
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
"effect": patch | ||
--- | ||
|
||
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 using `FastCheck.stringMatching`. | ||
|
||
**Example** | ||
|
||
```ts | ||
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) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters