-- | Coverage for 'Pqi.nfields': the column count across a multi-column
-- result, a zero-column result, and a command result.
module Pqi.Conformance.Operation.Nfields
  ( 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
"nfields" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"counts columns across result shapes" \ByteString
conninfo ->
      Adapter
-> ByteString
-> (Connection -> IO (Maybe Int32, Maybe Int32, Maybe Int32))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
        let countOf :: ByteString -> IO (Maybe Int32)
countOf ByteString
sql = Connection -> ByteString -> IO (Maybe Result)
Pqi.exec Connection
connection ByteString
sql IO (Maybe Result)
-> (Maybe Result -> IO (Maybe Int32)) -> IO (Maybe Int32)
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 Int32) -> Maybe Result -> IO (Maybe Int32)
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 -> IO Int32
Pqi.nfields
        several <- ByteString -> IO (Maybe Int32)
countOf ByteString
"select 1, 2, 3"
        zero <- countOf "select"
        command <- countOf "create temporary table conformance_nfields (id int4)"
        pure (several, zero, command)