-- | Coverage for 'Pqi.nparams': the parameter count of a
-- 'Pqi.describePrepared' result.
module Pqi.Conformance.Operation.Nparams
  ( spec,
  )
where

import qualified Pqi
import Pqi.Conformance.Harness
import Pqi.Conformance.Prelude
import Test.Hspec

spec :: Pqi.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
"nparams" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"counts the parameters of a prepared statement" \ByteString
conninfo ->
      Adapter -> ByteString -> (Connection -> IO (Maybe Int32)) -> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
        _ <- Connection
-> ByteString -> ByteString -> Maybe [Word32] -> IO (Maybe Result)
Pqi.prepare Connection
connection ByteString
"conformance_nparams" ByteString
"select $1 :: int4, $2 :: text" Maybe [Word32]
forall a. Maybe a
Nothing
        described <- Pqi.describePrepared connection "conformance_nparams"
        for described Pqi.nparams

    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"is zero for a parameterless statement" \ByteString
conninfo ->
      Adapter -> ByteString -> (Connection -> IO (Maybe Int32)) -> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
        _ <- Connection
-> ByteString -> ByteString -> Maybe [Word32] -> IO (Maybe Result)
Pqi.prepare Connection
connection ByteString
"conformance_nparams_zero" ByteString
"select 42" Maybe [Word32]
forall a. Maybe a
Nothing
        described <- Pqi.describePrepared connection "conformance_nparams_zero"
        for described Pqi.nparams