Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
Arbitrary: remove NaN while generating numeric template literals (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Oct 19, 2023
1 parent 77b827e commit e9ff876
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-flies-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/schema": patch
---

Arbitrary: remove NaN while generating numeric template literals
6 changes: 4 additions & 2 deletions src/Arbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ export const go = (ast: AST.AST, constraints?: Constraints): Arbitrary<any> => {
return (fc) => fc.oneof(fc.object(), fc.array(fc.anything()))
case "TemplateLiteral": {
return (fc) => {
const string = fc.string({ maxLength: 5 })
const number = fc.float({ noDefaultInfinity: true }).filter((n) => !Number.isNaN(n))
const components: Array<FastCheck.Arbitrary<string | number>> = [fc.constant(ast.head)]
for (const span of ast.spans) {
if (AST.isStringKeyword(span.type)) {
components.push(fc.string({ maxLength: 5 }))
components.push(string)
} else {
components.push(fc.float({ noDefaultInfinity: true }))
components.push(number)
}
components.push(fc.constant(span.literal))
}
Expand Down

0 comments on commit e9ff876

Please sign in to comment.