summaryrefslogtreecommitdiff
path: root/src/Test.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-07-24 20:54:56 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-07-24 20:54:56 +0200
commitc90a5abf0eeded8ff8a4aaee5ef35674236ed197 (patch)
treea00c45f0915aa916ccf50872dd32ca5ef0b6fc4f /src/Test.hs
parent7cefecfc3d491ae668a32cbc89668a055c0268de (diff)
Print relevant variable values after expect failure
Diffstat (limited to 'src/Test.hs')
-rw-r--r--src/Test.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/Test.hs b/src/Test.hs
index 25f3c09..e7e1255 100644
--- a/src/Test.hs
+++ b/src/Test.hs
@@ -8,7 +8,7 @@ module Test (
MonadEval(..),
VarName(..), textVarName, unpackVarName,
- Expr(..), eval,
+ Expr(..), eval, gatherVars,
Regex,
) where
@@ -23,6 +23,7 @@ import Text.Regex.TDFA
import Text.Regex.TDFA.Text
import Process
+import Util
data Test = Test
{ testName :: Text
@@ -84,3 +85,13 @@ eval (Regex xs) = do
Left err -> fail err
Right re -> return re
eval (BinOp f x y) = f <$> eval x <*> eval y
+
+gatherVars :: forall a m. MonadEval m => Expr a -> m [(VarName, Text)]
+gatherVars = fmap (uniq . sort) . helper
+ where
+ helper :: forall b. Expr b -> m [(VarName, Text)]
+ helper (StringVar var) = (:[]) . (var,) <$> lookupStringVar var
+ helper (StringLit _) = return []
+ helper (Concat es) = concat <$> mapM helper es
+ helper (Regex es) = concat <$> mapM helper es
+ helper (BinOp _ e f) = (++) <$> helper e <*> helper f