Skip to content

Commit

Permalink
Arbitrary: fix bug related to refinements of declarations raising a w… (
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Dec 13, 2024
1 parent 8d978c5 commit 2408616
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-baboons-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Arbitrary: fix bug where refinements in declarations raised an incorrect missing annotation error, closes #4136
5 changes: 4 additions & 1 deletion packages/effect/src/Arbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ const go = (
return hook.value(ctx)
}
}
if (AST.isDeclaration(ast)) {
throw new Error(errors_.getArbitraryMissingAnnotationErrorMessage(path, ast))
}
const op = toOp(ast, ctx, path)
switch (op._tag) {
case "Succeed":
Expand All @@ -289,7 +292,7 @@ export const toOp = (
): Op => {
switch (ast._tag) {
case "Declaration":
throw new Error(errors_.getArbitraryMissingAnnotationErrorMessage(path, ast))
return new Succeed(go(ast, ctx, path))
case "Literal":
return new Succeed((fc) => fc.constant(ast.literal))
case "UniqueSymbol":
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6233,8 +6233,8 @@ export class DateFromSelf extends declare(
{
identifier: "DateFromSelf",
description: "a potentially invalid Date instance",
pretty: (): pretty_.Pretty<Date> => (date) => `new Date(${JSON.stringify(date)})`,
arbitrary: (): LazyArbitrary<Date> => (fc) => fc.date({ noInvalidDate: false }),
pretty: () => (date) => `new Date(${JSON.stringify(date)})`,
arbitrary: () => (fc) => fc.date({ noInvalidDate: false }),
equivalence: () => Equivalence.Date
}
) {}
Expand Down
7 changes: 7 additions & 0 deletions packages/effect/test/Schema/Arbitrary/Arbitrary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,13 @@ details: Generating an Arbitrary for this schema requires at least one enum`)
})

describe("Refinement", () => {
describe("declaration filters", () => {
it("ValidDateFromSelf", () => {
const schema = S.ValidDateFromSelf
expectValidArbitrary(schema)
})
})

describe("array filters", () => {
it("minItems", () => {
const schema = S.Array(S.String).pipe(S.minItems(2))
Expand Down

0 comments on commit 2408616

Please sign in to comment.