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 db0d123
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions primer/test/Tests/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module Tests.Pretty where

import Foreword hiding (not)

import qualified Data.ByteString.Lazy as BS
import Data.ByteString.Lazy qualified as BS
import Data.String
import qualified Data.Text as T
import Data.Text qualified as T
import Prettyprinter (defaultLayoutOptions, layoutSmart)
import Prettyprinter.Internal.Type (Doc)
import Prettyprinter.Render.Terminal (AnsiStyle, renderStrict)
Expand All @@ -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 db0d123

Please sign in to comment.