81 lines
2.4 KiB
Haskell
81 lines
2.4 KiB
Haskell
{-# LANGUAGE DuplicateRecordFields #-}
|
|
{-# LANGUAGE OverloadedRecordDot #-}
|
|
{-# HLINT ignore "Use const" #-}
|
|
{-# HLINT ignore "Unused LANGUAGE pragma" #-}
|
|
{-# HLINT ignore "Avoid lambda" #-}
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
|
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
|
|
{-# LANGUAGE TypeApplications #-}
|
|
|
|
module Test.Datalog.DigestedQuerySpec where
|
|
|
|
import Test.Hspec
|
|
import Datalog.DatalogParser
|
|
import Datalog.DigestedQuery
|
|
( DigestedQuery(..),
|
|
DigestedQueryCondition(..),
|
|
DigestedQueryEntry(..),
|
|
digestQuery )
|
|
|
|
|
|
spec :: Spec
|
|
spec = do
|
|
describe "DigestedQuery" $ do
|
|
it "can digest a basic query" $ do
|
|
digestQuery "?- parent(alice,X)." `shouldBe` DigestedQuery {
|
|
allBoundVariables = ["X"],
|
|
numSoughtVariables = 1,
|
|
conditions = [
|
|
DigestedQueryCondition {
|
|
__relation = "parent",
|
|
_entries = [
|
|
DigestedQueryEntryConstant $ Sym "alice",
|
|
DigestedQueryEntryVariable 0
|
|
]
|
|
}
|
|
]
|
|
}
|
|
it "can digest a query with all variables explicitly sought" $ do
|
|
digestQuery "?- knows(a,X), friend(X,Y) → X,Y." `shouldBe` DigestedQuery {
|
|
allBoundVariables = ["X", "Y"],
|
|
numSoughtVariables = 2,
|
|
conditions = [
|
|
DigestedQueryCondition {
|
|
__relation = "knows",
|
|
_entries = [
|
|
DigestedQueryEntryConstant $ Sym "a",
|
|
DigestedQueryEntryVariable 0
|
|
]
|
|
},
|
|
DigestedQueryCondition {
|
|
__relation = "friend",
|
|
_entries = [
|
|
DigestedQueryEntryVariable 0,
|
|
DigestedQueryEntryVariable 1
|
|
]
|
|
}
|
|
]
|
|
}
|
|
it "can digest a query with unsought variables" $ do
|
|
digestQuery "?- edge(A,B), edge(B,C) → A,C ." `shouldBe` DigestedQuery {
|
|
allBoundVariables = ["A", "C", "B"],
|
|
numSoughtVariables = 2,
|
|
conditions = [
|
|
DigestedQueryCondition {
|
|
__relation = "edge",
|
|
_entries = [
|
|
DigestedQueryEntryVariable 0,
|
|
DigestedQueryEntryVariable 2
|
|
]
|
|
},
|
|
DigestedQueryCondition {
|
|
__relation = "edge",
|
|
_entries = [
|
|
DigestedQueryEntryVariable 2,
|
|
DigestedQueryEntryVariable 1
|
|
]
|
|
}
|
|
]
|
|
}
|
|
|