Adding more tests

This commit is contained in:
Zoe Roux
2021-11-04 13:55:11 +01:00
parent 91939d600d
commit 5ad9baa133
2 changed files with 15 additions and 5 deletions
+4 -3
View File
@@ -3,9 +3,10 @@ import Expressions
eval :: Statement -> LispEnv -> Either String (String, LispEnv)
eval (Expr expr) env = evalS expr env
eval (Atom (ASymbol symb)) env = case getSymbolValue symb env of
Just v -> Right (show v, env)
Nothing -> Left $ "**Error: Variable not bound " ++ symb ++ "**"
eval (Atom (ASymbol symb)) env =
case getSymbolValue symb env of
Just v -> Right (show v, env)
Nothing -> Left $ "**Error: Variable not bound " ++ symb ++ "**"
eval (Atom atom) env = Right (show atom, env)
getSymbolValue :: String -> LispEnv -> Maybe Atom
+11 -2
View File
@@ -1,12 +1,21 @@
import Test.HUnit
import System.Exit ( exitFailure, exitSuccess )
import BasicParser
import Data.Char
charTest :: Test
charTest = TestCase (assertEqual "char '123'," (Just '1', "23") (parse char "123"))
charTest = "char '123'," ~: (Just '1', "23") ~=? parse pChar "123"
charIfTest :: Test
charIfTest = "charIf isSpace ' 1 23'," ~: (Just ' ', "1 23") ~=? parse (pCharIf isSpace) " 1 23"
charIfFailureTest :: Test
charIfFailureTest = "charIf isSpace '1 23'," ~: (Nothing, "1 23") ~=? parse (pCharIf isSpace) "1 23"
tests :: Test
tests = TestList [TestLabel "Basic parser char" charTest]
tests = TestList [
TestLabel "Basic parser" charTest, charIfTest, charIfFailureTest
]
main :: IO ()
main = do