a framework to enable sensible query enfgine tests

This commit is contained in:
Felix Dilke 2026-02-11 11:02:48 +00:00
parent 872a9ee791
commit a9ff3b4a5f
3 changed files with 23 additions and 15 deletions

View File

@ -65,9 +65,9 @@ withFacts =
withFactsAndRules :: [Text] -> [Text] -> InMemoryDB withFactsAndRules :: [Text] -> [Text] -> InMemoryDB
withFactsAndRules facts = foldr (addRule . extractRule) (withFacts facts) withFactsAndRules facts = foldr (addRule . extractRule) (withFacts facts)
query :: forall db . (DatalogDB db) => db -> Text -> Text -- query :: forall db . (DatalogDB db) => db -> Text -> Text
query db qText = -- query db qText =
case parseDatalog qText of -- case parseDatalog qText of
Right (Query texts literals) -> "#NYI" -- Right (Query texts literals) -> "#NYI"
Right otherStatement -> throw $ NonQueryException qText otherStatement -- Right otherStatement -> throw $ NonQueryException qText otherStatement
Left ex -> throw $ CannotParseStatementException qText ex -- Left ex -> throw $ CannotParseStatementException qText ex

View File

@ -178,14 +178,6 @@ spec = do
`shouldBe` Set.empty `shouldBe` Set.empty
Set.fromList (relationNames db) `shouldBe` Set.fromList [ "equivalent" ] Set.fromList (relationNames db) `shouldBe` Set.fromList [ "equivalent" ]
it "can do basic queries" do
let db :: InMemoryDB =
InMemoryDB.withFacts
[ "parent(\"alice\", \"bob\")."
, "parent(\"bob\", \"carol\")."
]
query db "?- parent(alice,X)." `shouldBe` "#NYI" -- ideally, 'bob'
(<<$>>) :: (Functor f1, Functor f2) => (a -> b) -> f1 (f2 a) -> f1 (f2 b) (<<$>>) :: (Functor f1, Functor f2) => (a -> b) -> f1 (f2 a) -> f1 (f2 b)
(<<$>>) = fmap fmap fmap (<<$>>) = fmap fmap fmap

View File

@ -14,9 +14,25 @@
module Test.Datalog.NaiveQESpec where module Test.Datalog.NaiveQESpec where
import Test.Hspec import Test.Hspec
import Datalog.InMemoryDB (InMemoryDB)
import qualified Datalog.InMemoryDB as InMemoryDB
import Datalog.QueryEngine (QueryEngine(query))
import qualified Datalog.QueryEngine as QueryEngine
import qualified Datalog.NaiveQE as NaiveQE
import Datalog.QueryEngine (queryEngine)
import Datalog.NaiveQE
spec :: Spec spec :: Spec
spec = do spec = do
describe "NaiveQESpec" do describe "NaiveQESpec" do
it "..." $ do it "..." $ do
1 `shouldBe` 1 1 `shouldBe` 1
it "can do basic queries" do
let db :: InMemoryDB =
InMemoryDB.withFacts
[ "parent(\"alice\", \"bob\")."
, "parent(\"bob\", \"carol\")."
]
qe :: NaiveQE InMemoryDB = queryEngine db
query qe "?- parent(alice,X)." `shouldBe` "#NYI" -- ideally, 'bob'