Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Merge branch '2-parse-text-to-ast' of https://github.com/X-R-G-B/koaky
Browse files Browse the repository at this point in the history
…into 2-parse-text-to-ast
  • Loading branch information
guillaumeAbel committed Dec 4, 2023
2 parents 47ff922 + 0fd7729 commit a030bcd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ jobs:
tests.log
refresh-message-position: true
message-id: tests-cicd

- name: Exit Status
run: |
if [ ${{ steps.failedTest.outputs.failedTest }} == 'true' ]; then
exit 1
fi
19 changes: 15 additions & 4 deletions test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,30 @@ import Test.Tasty.HUnit
import Test.Tasty.Runners.Html

import AST
import TextToAST

main :: IO ()
main = defaultMainWithIngredients (htmlRunner : defaultIngredients) tests

tests :: TestTree
tests = testGroup "Tests" [unitTests]
tests = testGroup "Tests" [unitTestsASTEqual, unitTestsASTParse]

unitTests :: TestTree
unitTests = testGroup "Unit tests"
unitTestsASTEqual :: TestTree
unitTestsASTEqual = testGroup "AST Equal Tests"
[ testCase "Basic AST creation 0" $
assertEqual "define x 42" (Node "define" [Leaf (Symbol "x"), Leaf (Number 42)]) (Node "define" [Leaf (Symbol "x"), Leaf (Number 42)])
assertEqual "define x 42" (Node "define" (Just $ Leaf (Symbol "x")) (Just $ Leaf (Number 42))) (Node "define" (Just $ Leaf (Symbol "x")) (Just $ Leaf (Number 42)))
, testCase "Basic AST creation 1" $
assertEqual "foo" (Leaf (Symbol "foo")) (Leaf (Symbol "foo"))
, testCase "Basic AST creation 2" $
assertEqual "42" (Leaf (Number 42)) (Leaf (Number 42))
, testCase "Basic AST creation 3" $
assertEqual "#f" (Leaf (Boolean False)) (Leaf (Boolean False))
, testCase "Basic AST creation 4" $
assertEqual "#t" (Leaf (Boolean True)) (Leaf (Boolean True))
]

unitTestsASTParse :: TestTree
unitTestsASTParse = testGroup "AST Parse Tests"
[ testCase "Basic AST creation 0" $
assertEqual (textToAST "(foo abc def hij)") (Just $ (Node "foo" (Leaf (Symbol "abc"))) (Varidadic (Leaf (Symbol "def") (Leaf (Symbol "hij")))))
]

0 comments on commit a030bcd

Please sign in to comment.