Skip to content

Commit

Permalink
refactor: decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerAberbach committed Dec 7, 2024
1 parent ffc6c3a commit c43e975
Show file tree
Hide file tree
Showing 17 changed files with 630 additions and 130 deletions.
7 changes: 7 additions & 0 deletions src/arbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type Arbitrary = BaseArbitrary &
| IntegerArbitrary
| BigIntegerArbitrary
| FloatArbitrary
| DoubleArbitrary
| StringArbitrary
)

Expand Down Expand Up @@ -71,6 +72,12 @@ export type FloatArbitrary = {
max?: number
}

export type DoubleArbitrary = {
type: `double`
min?: number
max?: number
}

export type StringArbitrary = {
type: `string`
minLength?: number
Expand Down
15 changes: 15 additions & 0 deletions src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
ArrayArbitrary,
BigIntegerArbitrary,
DictionaryArbitrary,
DoubleArbitrary,
EnumArbitrary,
FloatArbitrary,
IntegerArbitrary,
Expand Down Expand Up @@ -145,6 +146,8 @@ const ArbitraryDefinition = ({
return BigIntegerArbitrary({ arbitrary })
case `float`:
return FloatArbitrary({ arbitrary })
case `double`:
return DoubleArbitrary({ arbitrary })
case `string`:
return StringArbitrary({ arbitrary })
}
Expand Down Expand Up @@ -243,6 +246,18 @@ const FloatArbitrary = ({ arbitrary }: { arbitrary: FloatArbitrary }): Child =>
]),
})})`

const DoubleArbitrary = ({
arbitrary,
}: {
arbitrary: DoubleArbitrary
}): Child =>
code`fc.double(${Options({
properties: new Map([
[`min`, arbitrary.min],
[`max`, arbitrary.max],
]),
})})`

const StringArbitrary = ({
arbitrary,
}: {
Expand Down
Loading

0 comments on commit c43e975

Please sign in to comment.