-- | Coverage for 'Pqi.fnumber': resolving a column name to an index,
-- folding the argument the way @PQfnumber@ does (ASCII case folding outside
-- double quotes, quoted runs verbatim).
module Pqi.Conformance.Operation.Fnumber
  ( 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
"fnumber" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"resolves names like an identifier" \ByteString
conninfo ->
      Adapter
-> ByteString -> (Connection -> IO (Maybe [Maybe Int32])) -> 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 as foo, 2 as \"Bar\""
        for result \Result
r ->
          (ByteString -> IO (Maybe Int32))
-> [ByteString] -> 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) -> [a] -> f [b]
traverse
            (Result -> ByteString -> IO (Maybe Int32)
Pqi.fnumber Result
r)
            [ByteString
"foo", ByteString
"FOO", ByteString
"Foo", ByteString
"Bar", ByteString
"bar", ByteString
"\"Bar\"", ByteString
"\"foo\"", ByteString
"missing"]