commit with infinitely recursing tests
This commit is contained in:
parent
763cae02b7
commit
cc3ed6a35d
@ -62,9 +62,9 @@ parseLiteral = Literal <$> decimal
|
||||
|
||||
parseBinaryExpr :: Parser Expr
|
||||
parseBinaryExpr = do
|
||||
lhs <- parseLiteral <|> parseExpr
|
||||
lhs <- parseExpr
|
||||
binOp <- parseOp
|
||||
rhs <- parseLiteral <|> parseExpr
|
||||
rhs <- parseExpr
|
||||
pure (BinaryExpr binOp lhs rhs)
|
||||
|
||||
parseOp :: Parser BinaryOp
|
||||
|
||||
@ -14,6 +14,10 @@ import Test.Hspec
|
||||
import Text.Megaparsec
|
||||
import SimpleParser
|
||||
|
||||
checkParse :: String -> Expr -> Expectation
|
||||
checkParse text expectedExpr =
|
||||
parse parseExpr "" text `shouldBe` Right expectedExpr
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "evaluate expressions" $ do
|
||||
@ -29,7 +33,8 @@ spec = do
|
||||
(BinaryExpr Divide (Literal 7) (Literal 3))
|
||||
) `shouldBe` 1
|
||||
it "can parse basic expressions" $ do
|
||||
parse parseExpr "" "2" `shouldBe` Right (Literal 2)
|
||||
parse parseExpr "" "2+3" `shouldBe` Right (BinaryExpr Add (Literal 2) (Literal 3))
|
||||
checkParse "2" (Literal 2)
|
||||
checkParse "2+3" (BinaryExpr Add (Literal 2) (Literal 3))
|
||||
checkParse "2+3+5" (BinaryExpr Add (BinaryExpr Add (Literal 2) (Literal 3)) (Literal 5))
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user