-- | Coverage for 'Pqi.getisnull': whether a cell is SQL @NULL@,
-- distinguishing a null from an empty string.
module Pqi.Conformance.Operation.Getisnull
  ( 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
"getisnull" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"distinguishes null, empty, and non-empty cells" \ByteString
conninfo ->
      Adapter
-> ByteString
-> (Connection -> IO (Maybe (Bool, Bool, Bool)))
-> 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 'x' :: text, '' :: text, null :: int4"
        for result \Result
r -> do
          nonEmpty <- Result -> Int32 -> Int32 -> IO Bool
Pqi.getisnull Result
r Int32
0 Int32
0
          empty <- Pqi.getisnull r 0 1
          nullCell <- Pqi.getisnull r 0 2
          pure (nonEmpty, empty, nullCell)