Skip to content

Commit

Permalink
add additional generators
Browse files Browse the repository at this point in the history
  • Loading branch information
rsoeldner committed Oct 31, 2023
1 parent b987c4e commit c00ac75
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
31 changes: 31 additions & 0 deletions pact-core-tests/Pact/Core/Gen/Serialise.hs
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,42 @@ defCapGen = do
meta <- defCapMetaGen
DefCap name arity args ret term meta <$> infoGen

defSchemaGen :: Gen (DefSchema Type SpanInfo)
defSchemaGen = do
name <- identGen
schema <- _schema <$> schemaGen
DefSchema name schema <$> infoGen

defTableGen :: Gen (DefTable Name SpanInfo)
defTableGen = do
name <- identGen
schema <- ResolvedTable <$> schemaGen
DefTable name schema <$> infoGen

stepGen :: Gen (Step Name Type RawBuiltin SpanInfo)
stepGen = Gen.choice
[ Step <$> termGen <*> mt
, StepWithRollback <$> termGen <*> termGen <*> mt
]
where
mt = Gen.maybe (Gen.list (Range.linear 0 16) termGen)

defPactGen :: Gen (DefPact Name Type RawBuiltin SpanInfo)
defPactGen = do
name <- identGen
args <- Gen.list (Range.linear 0 16) argGen
ret <- Gen.maybe typeGen
steps <- Gen.nonEmpty (Range.linear 0 16) stepGen
DefPact name args ret steps <$> infoGen

defGen :: Gen (Def Name Type RawBuiltin SpanInfo)
defGen = Gen.choice
[ Dfun <$> defunGen
, DConst <$> defConstGen
, DCap <$> defCapGen
, DSchema <$> defSchemaGen
, DTable <$> defTableGen
, DPact <$> defPactGen
]


Expand Down
4 changes: 4 additions & 0 deletions pact-core-tests/Pact/Core/Test/SerialiseTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ tests = testGroup "Serialise Roundtrip"
, testProperty "DefCap" $ serialiseRoundtrip defCapGen
, testProperty "Def" $ serialiseRoundtrip defGen
, testProperty "Module" $ serialiseRoundtrip evalModuleGen
, testProperty "DefSchema" $ serialiseRoundtrip defSchemaGen
, testProperty "DefTable" $ serialiseRoundtrip defTableGen
, testProperty "Step" $ serialiseRoundtrip stepGen
, testProperty "DefPact" $ serialiseRoundtrip defPactGen
]
2 changes: 1 addition & 1 deletion pact-core/Pact/Core/IR/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ instance Show (TableSchema name) where
show (DesugaredTable t) = "DesugardTable(" <> show t <> ")"
show (ResolvedTable t) = "ResolvedTable(" <> show t <> ")"

data DefTable name info
data DefTablename info
= DefTable
{ _dtName :: Text
, _dtSchema :: TableSchema name
Expand Down

0 comments on commit c00ac75

Please sign in to comment.