Commit 6c8d2a21 authored by Camil Staps's avatar Camil Staps 🚀

Use @property-test-generator to generate values for Maps and the like

parent b36643c2
Subproject commit 537593aaa79e5d180d9b1d33124e4530c8553d85
Subproject commit 28d19cd2b939a405a16c8ceb3a6e30c18e74b758
......@@ -2,6 +2,7 @@ module makecleantest
import _SystemArray
import StdBool
import StdEnum
import StdFile
from StdFunc import o
import StdOrdList
......@@ -250,16 +251,25 @@ generatePropertyModule name print_options test_options me fes = (length props, j
[ "module " +++ name
, "import Gast, Gast.CommandLine"
, bootstrap
, generators_string
, start
: [gp.gp_implementation \\ gp <- props]
])
where
props = concatMap (generateProperties pvis) fes
props = concatMap (generateProperties pvis generators) fes
where pvis = fromMaybe [] $ docPropertyTestWith <$> me.me_documentation
bootstrap = case me.me_documentation of
Just d -> fromMaybe "" $ docPropertyBootstrap d
Nothing -> ""
bootstrap = fromMaybe "" (docPropertyBootstrap =<< me.me_documentation)
generators = [("gast_generator_" <+ i,type,imp) \\ i <- [0..]
& PropertyTestGenerator type imp <- fromMaybe [] (docPropertyTestGenerators <$> me.me_documentation)]
generators_string = join "\n\n" $ map makeGenerator $ generators
where
makeGenerator :: NamedTestGenerator -> String
makeGenerator (name, t, imp) = join "\n"
[ name +++ " :: " <+ t
, name +++ imp % (3, size imp - 1)
]
start = join "\n\t"
[ "Start w = exposeProperties"
......@@ -274,8 +284,10 @@ where
, gp_implementation :: !String
}
generateProperties :: ![PropertyVarInstantiation] !FunctionEntry -> [GeneratedProperty]
generateProperties pvis fe=:{fe_documentation=Just doc} =
:: NamedTestGenerator :== (String, Type, String)
generateProperties :: ![PropertyVarInstantiation] ![NamedTestGenerator] !FunctionEntry -> [GeneratedProperty]
generateProperties pvis generators fe=:{fe_documentation=Just doc} =
[gen i p config
\\ p <- doc.properties
, config <- configurations $ groupInstantiations $ pvis ++ docPropertyTestWith doc
......@@ -293,10 +305,19 @@ where
{ gp_name = name`
, gp_implementation = join "\n"
[ name` +++ " :: " +++ toString type
, join " " [name`:map fst ts] +++ " = " +++ imp
, join " " [name`:map fst3 ts`] +++ " = " +++ join " " [name` +++ "`":map snd3 ts`]
, "where"
, "\t" +++ join " " [name` +++ "`":map fst3 ts`] +++ " = " +++ replaceSubString "\n" "\n\t" imp
]
}
where
name` = if (i == 1) name (name +++ "_" +++ toString i)
type = fromJust $ assignAll vis $ Func (map snd ts) (Type "Property" []) []
generateProperties _ _ = []
type = fromJust $ assignAll vis $ Func (map thd3 ts`) (Type "Property" []) []
ts` = map resolveGenerators ts
resolveGenerators :: (String,Type) -> (String,String,Type)
resolveGenerators (arg,t) = case [(n,i) \\ (n,Func [i] r _,_) <- generators | r == t] of
[(n,i):_] -> (arg,"(" +++ n +++ " " +++ arg +++ ")",i)
[] -> (arg,arg,t)
generateProperties _ _ _ = []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment