2026-01-21 11:24:30 +00:00
|
|
|
{-# 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.Datalog.NaiveDatabaseSpec where
|
|
|
|
|
|
|
|
|
|
import Test.Hspec
|
|
|
|
|
import Datalog.NaiveDatabase
|
2026-01-21 17:11:13 +00:00
|
|
|
import qualified Datalog.NaiveDatabase as NaiveDatabase
|
2026-01-21 11:24:30 +00:00
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
|
2026-01-21 18:01:06 +00:00
|
|
|
-- getConfig :: IO Config
|
|
|
|
|
-- getConfig = do
|
|
|
|
|
-- env <- lookupEnv "APP_ENV"
|
|
|
|
|
-- let fallbackHosts =
|
|
|
|
|
-- [ "localhost:8080"
|
|
|
|
|
-- , "127.0.0.1:9000"
|
|
|
|
|
-- , "backup.example.com"
|
|
|
|
|
-- ]
|
|
|
|
|
-- pure Config
|
|
|
|
|
-- { port = 3000
|
|
|
|
|
-- , hosts = fromMaybe fallbackHosts env
|
|
|
|
|
-- , logLevel = Info
|
|
|
|
|
-- }
|
2026-01-21 11:24:30 +00:00
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
|
spec = do
|
|
|
|
|
describe "dummy test" $ do
|
|
|
|
|
it "..." $ do
|
|
|
|
|
1 `shouldBe` (1 :: Int)
|
2026-01-21 17:11:13 +00:00
|
|
|
it "can accept facts and do basic queries" $ do
|
2026-01-21 18:01:06 +00:00
|
|
|
-- let fallbackHosts =
|
|
|
|
|
-- [ "localhost:8080"
|
|
|
|
|
-- , "127.0.0.1:9000"
|
|
|
|
|
-- , "backup.example.com"
|
|
|
|
|
-- ]
|
|
|
|
|
-- let names =
|
|
|
|
|
-- [ "Alice"
|
|
|
|
|
-- , "Bob"
|
|
|
|
|
-- , "Charlie"
|
|
|
|
|
-- , "Daphne"
|
|
|
|
|
-- , "Eve"
|
|
|
|
|
-- ]
|
|
|
|
|
-- let twig =
|
|
|
|
|
-- [ "xx"
|
|
|
|
|
-- , "yy " ]
|
|
|
|
|
-- let pig =
|
|
|
|
|
-- [ "parent(\"alice\", \"bob\")."
|
|
|
|
|
-- , "parent(\"bob\", \"carol\")."
|
|
|
|
|
-- ]
|
|
|
|
|
let db = NaiveDatabase.withFacts
|
|
|
|
|
[ "parent(\"alice\", \"bob\")."
|
|
|
|
|
, "parent(\"bob\", \"carol\")." ]
|
2026-01-21 17:11:13 +00:00
|
|
|
query db"?- parent(alice,X)." `shouldBe` "#NYI" -- ideally, 'bob'
|