From 51f3f8f21d5887666c1323d77acacd320759eec1 Mon Sep 17 00:00:00 2001 From: James Eversole Date: Thu, 19 Dec 2024 20:21:59 -0600 Subject: [PATCH] Additional tests Additional tests for both parsing and evaluation. 100% passing as of commit. --- test/Spec.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/Spec.hs b/test/Spec.hs index c6b568c..117d08c 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -80,6 +80,23 @@ parserTests = testGroup "Parser Tests" let input = "t (t t (t t))" let expected = TStem (TFork TLeaf (TStem TLeaf)) parseSapling input @?= expected + + , testCase "Parse empty list" $ do + let input = "[]" + let expected = SList [] + parseSapling input @?= expected + + , testCase "Parse multiple nested lists" $ do + let input = "[[t t] [t (t t)]]" + let expected = SList [SList [TLeaf, TLeaf], SList [TLeaf, TStem TLeaf]] + parseSapling input @?= expected + + , testCase "Parse whitespace variance" $ do + let input1 = "[t t]" + let input2 = "[ t t ]" + let expected = SList [TLeaf, TLeaf] + parseSapling input1 @?= expected + parseSapling input2 @?= expected ] integrationTests :: TestTree @@ -149,6 +166,20 @@ evaluationTests = testGroup "Evaluation Tests" let ast = parseSapling input (result $ evalSapling Map.empty ast) @?= toList [Leaf, Stem Leaf] + , testCase "Evaluate empty list" $ do + let input = "[]" + let ast = parseSapling input + (result $ evalSapling Map.empty ast) @?= toList [] + + , testCase "Evaluate variable dependency chain" $ do + let input = "x = t\ny = t x\nz = t y\nz" + let env = evalMulti Map.empty (parseMulti input) + (result env) @?= (Stem (Stem Leaf)) + + , testCase "Evaluate redefinition of variables" $ do + let input = "x = t t\nx = t\nx" + let env = evalMulti Map.empty (parseMulti input) + (result env) @?= Leaf ] propertyTests :: TestTree