-- | Coverage for 'Pqi.ftype': the data-type OID of each column, including
-- an out-of-range index.
module Pqi.Conformance.Operation.Ftype
  ( 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
"ftype" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"reports type OIDs and degrades out of range" \ByteString
conninfo ->
      Adapter
-> ByteString
-> (Connection -> IO (Maybe ([Word32], Word32)))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
        result <- Connection -> ByteString -> IO (Maybe Result)
Pqi.exec Connection
connection ByteString
"select 1 :: int4, 'x' :: text, true, 1.5 :: float8, 1 :: int2"
        for result \Result
r -> do
          n <- Result -> IO Int32
Pqi.nfields Result
r
          types <- traverse (Pqi.ftype r) [0 .. n - 1]
          outOfRange <- Pqi.ftype r 9
          pure (types, outOfRange)