Skip to content

Commit

Permalink
refactor: prettyTest variable names + make curried
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Aldis committed Jul 25, 2022
1 parent 507f50d commit 28fe7fa
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions primer/test/Tests/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ exprHandler = (prettyExpr defaultPrettyOptions . astDefExpr, "Expr")
typeHandler :: PrettyTestHandler
typeHandler = (prettyType defaultPrettyOptions . astDefType, "Type")

prettyTest :: (String, Def) -> PrettyTestHandler -> TestTree
prettyTest (n, d) h = goldenVsString hname path bs
prettyTest :: String -> Def -> PrettyTestHandler -> TestTree
prettyTest name def handler = goldenVsString hname path bs
where
dname = n
hname = T.unpack (snd h)
path = "test/outputs/Pretty/" ++ dname ++ "/" ++ hname
bs = case d of
hname = T.unpack (snd handler)
path = "test/outputs/Pretty/" ++ name ++ "/" ++ hname
bs = case def of
DefPrim _ -> exitFailure
DefAST e -> docToBS (fst h e)
DefAST e -> docToBS (fst handler e)

prettyTestGroup :: (ModuleName -> S (GVarName, Def)) -> TestTree
prettyTestGroup x = testGroup dname (map (prettyTest (dname, d)) [exprHandler, typeHandler])
prettyTestGroup x = testGroup dname (map (prettyTest dname d) [exprHandler, typeHandler])
where
(n, d) = create' $ x $ mkSimpleModuleName "Module"
dname = T.unpack . unName . baseName $ n
Expand Down

0 comments on commit 28fe7fa

Please sign in to comment.