Skip to content

Commit

Permalink
fix: share multiple nevers
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerAberbach committed Dec 8, 2024
1 parent db040c7 commit c212403
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,7 @@ const collectSharedArbitraries = (
)
}

const getDirectArbitraryDependencies = (
arbitrary: Arbitrary,
): Set<Arbitrary> => {
const getDirectArbitraryDependencies = (arbitrary: Arbitrary): Arbitrary[] => {
switch (arbitrary.type) {
case `null`:
case `undefined`:
Expand All @@ -535,24 +533,23 @@ const getDirectArbitraryDependencies = (
case `string`:
case `bytes`:
case `enum`:
return new Set()
return []
case `array`:
return new Set([arbitrary.value])
return [arbitrary.value]
case `dictionary`:
return new Set([arbitrary.key, arbitrary.value])
return [arbitrary.key, arbitrary.value]
case `union`:
return new Set(arbitrary.variants)
return arbitrary.variants
case `record`:
return new Set(
pipe(
values(arbitrary.properties),
map(property => property.arbitrary),
),
return pipe(
values(arbitrary.properties),
map(property => property.arbitrary),
reduce(toArray()),
)
case `merged`:
return new Set(arbitrary.arbitraries)
return arbitrary.arbitraries
case `reference`:
return new Set([arbitrary.arbitrary])
return [arbitrary.arbitrary]
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ test.each([
}
`,
},
{
name: `shared-never`,
code: `
model $Model {
property1: never,
property2: never
}
`,
},
{
name: `unknown`,
code: `
Expand Down
10 changes: 10 additions & 0 deletions test/snapshots/shared-never/arbitraries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as fc from 'fast-check';

const never = fc.constant(null).map(() => {
throw new Error('never');
});

export const $Model = fc.record({
property1: never,
property2: never,
});
3 changes: 3 additions & 0 deletions test/snapshots/shared-never/samples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const samples = {
'$Model': '[Error: never]'
};

0 comments on commit c212403

Please sign in to comment.