Commit e6cb8d64 authored by Tadej Borovšak's avatar Tadej Borovšak
Browse files

Add more tests

parent beaf81d2
......@@ -2,8 +2,12 @@ import Test.Hspec
import Imp_AbsSyntax
import Imp_Lex
import Imp_Parse
import Imp_State
import Imp_Evaluator
gen_ast = imp_parse . imp_lex
eval = eval_s emp
eval_s s t = valof (evalCom s t) "x"
main :: IO ()
main = hspec $ do
......@@ -90,3 +94,30 @@ main = hspec $ do
Skip),
Skip)),
Skip))
describe "evalCom" $ do
it "handles numbers" $ do
3 `shouldBe`
(eval $ Assign ("x", Num 3))
it "handles vars" $ do
3 `shouldBe`
(eval_s (update emp "y" 3) $ Assign ("x", Loc "y"))
it "calculate sum" $ do
3 `shouldBe`
(eval $ Assign ("x", AOp ("+", Num 1, Num 2)))
it "subtract" $ do
3 `shouldBe`
(eval $ Assign ("x", AOp ("-", Num 5, Num 2)))
it "multiply" $ do
8 `shouldBe`
(eval $ Assign ("x", AOp ("*", Num 4, Num 2)))
it "handles truthy booleans" $ do
3 `shouldBe`
(eval $ Cond (Boolean True,
Assign ("x", Num 3),
Assign ("x", Num 5)))
it "handles falsy booleans" $ do
5 `shouldBe`
(eval $ Cond (Boolean False,
Assign ("x", Num 3),
Assign ("x", Num 5)))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment