Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
updated the Parser.hs tests to work with the new ModuleMap API
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddy Westbrook committed May 17, 2018
1 parent 20ebf8a commit 1a2c0e5
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions tests/src/Tests/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,32 @@ import Test.Tasty
import Test.Tasty.HUnit

checkGroundTerm :: Term -> Bool
checkGroundTerm t = looseVars t == 0
checkGroundTerm t = looseVars t == emptyBitSet

namedMsg :: Ident -> String -> String
namedMsg sym msg = "In " ++ show sym ++ ": " ++ msg

checkEqn :: Ident -> DefEqn -> Assertion
checkEqn sym (DefEqn pats rhs) = do
let nbound = sum $ patBoundVarCount <$> pats
let lvd = emptyLocalVarDoc
& docShowLocalNames .~ False
& docShowLocalTypes .~ True
let msg = "Equation right hand side has unbound variables:\n"
++ show (ppDefEqn (ppTerm defaultPPOpts) emptyLocalVarDoc (ppIdent sym) (DefEqn pats rhs)) ++ "\n"
++ show (ppTerm defaultPPOpts lvd PrecNone rhs) ++ "\n"
++ show (looseVars rhs) ++ "\n"
++ show (ppTermDoc (ppTermF defaultPPOpts (\_ _ _ -> TermDoc . text . show) lvd PrecNone (looseVars <$> unwrapTermF rhs)))

assertEqual (namedMsg sym msg) 0 (looseVars rhs `shiftR` nbound)

checkDef :: Def -> Assertion
checkDef d = do
let sym = defIdent d
let tp = defType d
let tpProp = assertBool (namedMsg sym "Type is not ground.") (checkGroundTerm tp)
let eqProps = checkEqn sym <$> defEqs d
let bodyProps =
case defBody d of
Nothing -> []
Just body ->
assertBool (namedMsg sym "Body is not ground.") (checkGroundTerm body)

sequence_ (tpProp : eqProps)
sequence_ (tpProp : bodyProps)

checkModule :: Module -> Assertion
checkModule m = sequence_ $ checkDef <$> moduleDefs m
checkPrelude :: Assertion
checkPrelude =
do sc <- mkSharedContext
scLoadPreludeModule sc
modmap <- scGetModuleMap sc
traverse_ checkDef $ allModuleDefs modmap

parserTests :: [TestTree]
parserTests =
[ testCase "preludeModule" $ checkModule preludeModule
[ testCase "preludeModule" checkPrelude
]

0 comments on commit 1a2c0e5

Please sign in to comment.