module Pqi.Conformance.Operation.Fformat
( spec,
)
where
import qualified Pqi as Lq
import Pqi.Conformance.Harness
import Pqi.Conformance.Prelude
import Test.Hspec
spec :: Lq.Adapter -> SpecWith ByteString
spec :: Adapter -> SpecWith ByteString
spec Adapter
adapter =
String -> SpecWith ByteString -> SpecWith ByteString
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"fformat" do
String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"follows the requested result format" \ByteString
conninfo ->
Adapter
-> ByteString
-> (Connection -> IO (Maybe [Format], Maybe [Format]))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
let formatsOf :: Format -> IO (Maybe [Format])
formatsOf Format
fmt =
Connection
-> ByteString
-> [Maybe (Word32, ByteString, Format)]
-> Format
-> IO (Maybe Result)
Lq.execParams Connection
connection ByteString
"select 1 :: int4, 'x' :: text" [] Format
fmt
IO (Maybe Result)
-> (Maybe Result -> IO (Maybe [Format])) -> IO (Maybe [Format])
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Result -> IO [Format]) -> Maybe Result -> IO (Maybe [Format])
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse \Result
r -> do
n <- Result -> IO Int32
Lq.nfields Result
r
traverse (Lq.fformat r) [0 .. n - 1]
textFormats <- Format -> IO (Maybe [Format])
formatsOf Format
Lq.Text
binaryFormats <- formatsOf Lq.Binary
pure (textFormats, binaryFormats)