Verified Commit c19e946c authored by Camil Staps's avatar Camil Staps 🚀

Add support for test generators with multiple arguments

parent c81d400e
Pipeline #29290 passed with stage
in 4 minutes and 16 seconds
......@@ -389,9 +389,10 @@ where
:: NamedTestGenerator :== (String, PropertyTestGenerator)
:: GeneratedArgument =
{ ga_name :: !String // argument name
, ga_expr :: !String // expression (for PTG_Function)
, ga_ptg :: !Maybe NamedTestGenerator // the generator used
{ ga_arg :: !String // the name of the argument as stated
, ga_names :: ![String] // generated argument names
, ga_expr :: !String // expression (for PTG_Function)
, ga_ptg :: !Maybe NamedTestGenerator // the generator used
}
generateProperties :: !String ![PropertyVarInstantiation] ![NamedTestGenerator] !String
......@@ -426,7 +427,7 @@ where
, "\t(" +++ join " " lambdas +++ join " " [name`` +++ "`":[ga.ga_expr \\ ga <- gas]] +++ {')' \\ _ <- lambdas} +++ ")"
, "where"
, "\t" +++ name`` +++ "` :: " +++ toString type`
, "\t" +++ join " " [name`` +++ "`":[ga.ga_name \\ ga <- gas]] +++ " = (True" +++ concat [" /\\ _pre" <+ i \\ i <- [1..] & pre <- preconditions] +++ ") ==> _p"
, "\t" +++ join " " [name`` +++ "`":[ga.ga_arg \\ ga <- gas]] +++ " = (True" +++ concat [" /\\ _pre" <+ i \\ i <- [1..] & pre <- preconditions] +++ ") ==> _p"
, "\twhere"
, "\t\t_p = " +++ replaceSubString "\n" "\n\t\t\t" imp
: ["\t\t_pre" <+ i <+ " = " +++ s \\ s <- preconditions & i <- [1..]]
......@@ -442,22 +443,26 @@ where
where
resolveGenerators :: (String,Type) -> GeneratedArgument
resolveGenerators (arg,t) =
case [(n,i,ntg) \\ ntg=:(n,PTG_Function (Func [i] r _) _) <- generators | r == t] of
[(n,i,ntg):_] ->
{ ga_name = arg
, ga_expr = "(" +++ n +++ " " +++ arg +++ ")"
, ga_ptg = Just ntg
case [(n,is,ntg) \\ ntg=:(n,PTG_Function (Func is r _) _) <- generators | r == t] of
[(n,is,ntg):_] ->
{ ga_arg = arg
, ga_names = args
, ga_expr = "(" +++ join " " [n:args] +++ ")"
, ga_ptg = Just ntg
}
with args = [arg +++ "`" +++ toString i \\ _ <- is & i <- [0..]]
[] -> case [(n,ntg) \\ ntg=:(n,PTG_List r _) <- generators | r == t] of
[(n,ntg):_] ->
{ ga_name = arg
, ga_expr = arg
, ga_ptg = Just ntg
{ ga_arg = arg
, ga_names = [arg]
, ga_expr = arg
, ga_ptg = Just ntg
}
[] ->
{ ga_name = arg
, ga_expr = arg
, ga_ptg = Nothing
{ ga_arg = arg
, ga_names = [arg]
, ga_expr = arg
, ga_ptg = Nothing
}
lambdas = map makeLambda gas
......@@ -465,8 +470,8 @@ where
makeLambda :: GeneratedArgument -> String
makeLambda ga = case ga.ga_ptg of
Just (gen,PTG_List _ _)
-> "ForEach " +++ gen +++ " (\\" +++ ga.ga_name +++ "->"
-> "\\" +++ ga.ga_name +++ "->("
-> "ForEach " +++ gen +++ " (\\" +++ ga.ga_arg +++ "->"
-> "\\" +++ join " " ga.ga_names +++ "->("
fixname :: String -> String
fixname s = {if (isAlphanum c) c '_' \\ c <-: s}
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