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

Commit

Permalink
Interpreter v.0: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeAbel committed Dec 5, 2023
1 parent 97bbbf7 commit 7da3907
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/TextToAST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module TextToAST
textToAST
) where

import Debug.Trace
import AST
import Data.Int (Int64)
import Data.Char (isDigit)
Expand Down Expand Up @@ -74,10 +73,10 @@ nextToParse str | skipableChar (head str) = nextToParse (dropWhile skipableChar
(dropWhile notSkipableChar (dropWhile skipableChar str))

countAtoms :: String -> Int -> Int
countAtoms str depth | depth >= 2 = trace ("maxdepth") $ 2
countAtoms str depth | depth >= 2 = 2
| not (null $ takeWhile
(/= ')')
(dropWhile skipableChar str)) = trace ("+1atom, str: " ++ str ++ " parseRes: " ++ (nextToParse str)) $
(dropWhile skipableChar str)) =
countAtoms (nextToParse str) (depth + 1)
| otherwise = depth

Expand Down
26 changes: 26 additions & 0 deletions test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,30 @@ unitTestsASTParse = testGroup "AST Parse Tests"
(Just $ Leaf (Boolean True))
)
(textToAST "(foo ((def)) #t)")
, testCase "(do (re (mi)) 12)" $
assertEqual "(do (re (mi)) 12)"
(Just $ Node "do"
(Just $ Node "re"
(Just $ Leaf (Symbol "mi"))
(Just $ Empty)
)
(Just $ Leaf (Number 12))
)
(textToAST "(do (re (mi)) 12)")
, testCase "(do (re (mi)) 12 (re (mi)))" $
assertEqual "(do (re (mi)) 12 (re (mi)))"
(Just $ Node "do"
(Just $ Node "re"
(Just $ Leaf (Symbol "mi"))
(Just $ Empty)
)
(Just $ Variadic
(Just $ Leaf (Number 12))
(Just $ Node "re"
(Just $ Leaf (Symbol "mi"))
(Just $ Empty)
)
)
)
(textToAST "(do (re (mi)) 12 (re (mi)))")
]

0 comments on commit 7da3907

Please sign in to comment.