commit with infinitely recursing tests

This commit is contained in:
Felix Dilke 2026-01-15 10:15:07 +00:00
parent 763cae02b7
commit cc3ed6a35d
2 changed files with 9 additions and 4 deletions

View File

@ -62,9 +62,9 @@ parseLiteral = Literal <$> decimal
parseBinaryExpr :: Parser Expr parseBinaryExpr :: Parser Expr
parseBinaryExpr = do parseBinaryExpr = do
lhs <- parseLiteral <|> parseExpr lhs <- parseExpr
binOp <- parseOp binOp <- parseOp
rhs <- parseLiteral <|> parseExpr rhs <- parseExpr
pure (BinaryExpr binOp lhs rhs) pure (BinaryExpr binOp lhs rhs)
parseOp :: Parser BinaryOp parseOp :: Parser BinaryOp

View File

@ -14,6 +14,10 @@ import Test.Hspec
import Text.Megaparsec import Text.Megaparsec
import SimpleParser import SimpleParser
checkParse :: String -> Expr -> Expectation
checkParse text expectedExpr =
parse parseExpr "" text `shouldBe` Right expectedExpr
spec :: Spec spec :: Spec
spec = do spec = do
describe "evaluate expressions" $ do describe "evaluate expressions" $ do
@ -29,7 +33,8 @@ spec = do
(BinaryExpr Divide (Literal 7) (Literal 3)) (BinaryExpr Divide (Literal 7) (Literal 3))
) `shouldBe` 1 ) `shouldBe` 1
it "can parse basic expressions" $ do it "can parse basic expressions" $ do
parse parseExpr "" "2" `shouldBe` Right (Literal 2) checkParse "2" (Literal 2)
parse parseExpr "" "2+3" `shouldBe` Right (BinaryExpr Add (Literal 2) (Literal 3)) checkParse "2+3" (BinaryExpr Add (Literal 2) (Literal 3))
checkParse "2+3+5" (BinaryExpr Add (BinaryExpr Add (Literal 2) (Literal 3)) (Literal 5))