module Pqi.Conformance.Operation.UnescapeBytea
( spec,
)
where
import qualified Pqi
import Pqi.Conformance.Prelude
import qualified Pqi.Conformance.Reference as Reference
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
"unescapeBytea" do
[ByteString]
-> (ByteString -> SpecWith ByteString) -> SpecWith ByteString
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [ByteString]
forall {a}. IsString a => [a]
cases \ByteString
input ->
String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it (ByteString -> String
forall a. Show a => a -> String
show ByteString
input) \ByteString
_ -> do
candidate <- Adapter -> ByteString -> IO (Maybe ByteString)
Pqi.unescapeBytea Adapter
adapter ByteString
input
reference <- Pqi.unescapeBytea Reference.adapter input
candidate `shouldBe` reference
where
cases :: [a]
cases =
[ a
"",
a
"\\x",
a
"\\x00",
a
"\\x00ff",
a
"\\x48656c6c6f",
a
"\\X48656C6C6F",
a
"\\xAbCd",
a
"Hello, world",
a
"h\233llo bytes",
a
"\\\\",
a
"\\001\\002\\003",
a
"a\\010b",
a
"\\x4",
a
"\\x4g",
a
"\\xzz",
a
"\\x61 62",
a
"\\377",
a
"\\400",
a
"\\000",
a
"\\1",
a
"\\18",
a
"\\8",
a
"a\\b",
a
"trailing\\",
a
"mixed\\134text"
]