{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedRecordDot #-} {-# HLINT ignore "Use const" #-} {-# HLINT ignore "Unused LANGUAGE pragma" #-} {-# HLINT ignore "Avoid lambda" #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE NoFieldSelectors #-} {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} {-# LANGUAGE TypeApplications #-} module Test.DatalogParserSpec where import Test.Hspec import DatalogParser -- checkParse :: String -> Expr -> Expectation -- checkParse text expectedExpr = -- parse parseExpr "" text `shouldBe` Right expectedExpr -- checkEval :: String -> Int -> Expectation -- checkEval text expectedVal = -- fmap eval (parse parseExpr "" text) `shouldBe` Right expectedVal spec :: Spec spec = do describe "evaluate expressions" $ do it "parsing facts" $ do parseDatalog "parent(\"alice\", \"bob\")." `shouldBe` Right (Fact Literal { positive = True, predName = "parent", arguments = [Sym "alice", Sym "bob"] }) -- eval (BinaryExpr Add (Literal 2) (Literal 3) ) `shouldBe` 5 -- eval (BinaryExpr Subtract (Literal 2) (Literal 3) ) `shouldBe` -1 -- eval (BinaryExpr Multiply (Literal 2) (Literal 3) ) `shouldBe` 6 -- eval (BinaryExpr Divide (Literal 7) (Literal 3) ) `shouldBe` 2 -- eval (UnaryExpr Negate (Literal 7) ) `shouldBe` -7