-- | Coverage for 'Pqi.escapeByteaConn': escaping binary data for a
-- @bytea@ literal across the full byte range.
module Pqi.Conformance.Operation.EscapeByteaConn
  ( spec,
  )
where

import qualified Data.ByteString as ByteString
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
"escapeByteaConn" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"escapes a range of binary inputs" \ByteString
conninfo ->
      Adapter
-> ByteString -> (Connection -> IO [Maybe ByteString]) -> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection ->
        (ByteString -> IO (Maybe ByteString))
-> [ByteString] -> IO [Maybe ByteString]
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) -> [a] -> f [b]
traverse (Connection -> ByteString -> IO (Maybe ByteString)
Pqi.escapeByteaConn Connection
connection) [ByteString]
byteaCases
  where
    byteaCases :: [ByteString]
byteaCases =
      [ ByteString
"",
        ByteString
"plain",
        ByteString
"\NUL\1\2\3",
        [Word8] -> ByteString
ByteString.pack [Word8
0 .. Word8
255]
      ]