diff --git a/src/arbitrary.ts b/src/arbitrary.ts index ca80a74..8322bc0 100644 --- a/src/arbitrary.ts +++ b/src/arbitrary.ts @@ -10,6 +10,7 @@ export type Arbitrary = BaseArbitrary & | NullArbitrary | UndefinedArbitrary | NeverArbitrary + | UnknownArbitrary | BooleanArbitrary | NumberArbitrary | BigIntArbitrary @@ -38,6 +39,10 @@ export type NeverArbitrary = { type: `never` } +export type UnknownArbitrary = { + type: `unknown` +} + export type BooleanArbitrary = { type: `boolean` } diff --git a/src/components.ts b/src/components.ts index 893a902..492096a 100644 --- a/src/components.ts +++ b/src/components.ts @@ -144,6 +144,8 @@ const ArbitraryDefinition = ({ return UndefinedArbitrary() case `never`: return NeverArbitrary() + case `unknown`: + return UnknownArbitrary() case `boolean`: return BooleanArbitrary() case `number`: @@ -177,6 +179,8 @@ const NeverArbitrary = (): Child => code` }) ` +const UnknownArbitrary = (): Child => code`fc.anything()` + const BooleanArbitrary = (): Child => code`fc.boolean()` const NumberArbitrary = ({ diff --git a/src/convert.ts b/src/convert.ts index e1279a4..6085546 100644 --- a/src/convert.ts +++ b/src/convert.ts @@ -121,8 +121,9 @@ const convertIntrinsic = (intrinsic: IntrinsicType): Arbitrary => { return convertVoid(intrinsic) case `never`: return convertNever(intrinsic) - case `ErrorType`: case `unknown`: + return convertUnknown(intrinsic) + case `ErrorType`: throw new Error(`Unhandled Intrinsic: ${intrinsic.name}`) } } @@ -136,6 +137,9 @@ const convertVoid = ($void: IntrinsicType): Arbitrary => const convertNever = (never: IntrinsicType): Arbitrary => memoize({ type: `never`, name: never.name }) +const convertUnknown = (unknown: IntrinsicType): Arbitrary => + memoize({ type: `unknown`, name: unknown.name }) + const convertScalar = ( program: Program, scalar: Scalar, @@ -312,6 +316,8 @@ const getArbitraryKey = (arbitrary: Arbitrary): ArbitraryKey => { return keyalesce([arbitrary.type, arbitrary.name]) case `never`: return keyalesce([arbitrary.type, arbitrary.name]) + case `unknown`: + return keyalesce([arbitrary.type, arbitrary.name]) case `boolean`: return keyalesce([arbitrary.type, arbitrary.name]) case `number`: @@ -431,6 +437,7 @@ const getDirectArbitraryDependencies = ( case `null`: case `undefined`: case `never`: + case `unknown`: case `boolean`: case `number`: case `bigint`: diff --git a/test/index.ts b/test/index.ts index a65169b..ff08624 100644 --- a/test/index.ts +++ b/test/index.ts @@ -91,6 +91,14 @@ test.each([ } `, }, + { + name: `unknown`, + code: ` + model M { + property: unknown + } + `, + }, { name: `boolean`, code: ` diff --git a/test/snapshots/unknown/arbitraries.js b/test/snapshots/unknown/arbitraries.js new file mode 100644 index 0000000..57bd5e2 --- /dev/null +++ b/test/snapshots/unknown/arbitraries.js @@ -0,0 +1,5 @@ +import * as fc from 'fast-check'; + +export const M = fc.record({ + property: fc.anything(), +}); \ No newline at end of file diff --git a/test/snapshots/unknown/samples.js b/test/snapshots/unknown/samples.js new file mode 100644 index 0000000..19fe71b --- /dev/null +++ b/test/snapshots/unknown/samples.js @@ -0,0 +1,38 @@ +export const samples = { + 'M': [ + { + 'property': [ + null + ] + }, + { + 'property': { + '2Spc0sZ': [ + '%.%}ayW&;' + ], + 'A$(;2O': [], + 'MU6\'': { + '^bu': '', + 'B.gE': false + } + } + }, + { + 'property': [ + ' ', + [ + true, + { + '"': 'n' + } + ] + ] + }, + { + 'property': 'g' + }, + { + 'property': [] + } + ] +}; \ No newline at end of file