-- | Coverage for 'Pqi.exec': the simple-query protocol over a range of
-- result shapes, command tags, and degenerate inputs.
module Pqi.Conformance.Operation.Exec
  ( spec,
  )
where

import qualified Pqi
import Pqi.Conformance.Harness
import Pqi.Conformance.Prelude
import Pqi.Conformance.Scenario
import Test.Hspec

spec :: Pqi.Adapter -> SpecWith ByteString
spec :: Adapter -> SpecWith ByteString
spec Adapter
adapter =
  [Char] -> SpecWith ByteString -> SpecWith ByteString
forall a. HasCallStack => [Char] -> SpecWith a -> SpecWith a
describe [Char]
"exec" do
    let forCase :: [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
title ByteString
sql =
          [Char]
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
[Char] -> a -> SpecWith (Arg a)
it [Char]
title \ByteString
conninfo -> Adapter
-> ByteString
-> (Connection -> IO (Maybe ResultObservation))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo (ByteString -> Connection -> IO (Maybe ResultObservation)
execScenario ByteString
sql)
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"select literal" ByteString
"select 1"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"multi-row, multi-column" ByteString
"select i, i * 2 from generate_series (1, 3) as i"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"nulls and text" ByteString
"select null :: int4, 'hello' :: text, true"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"no rows" ByteString
"select 1 where false"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"zero columns" ByteString
"select"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"empty query" ByteString
""
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"semicolon only" ByteString
";"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"comment only" ByteString
"-- nothing to see here"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"whitespace only" ByteString
"   "
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"multiple statements take the last result" ByteString
"select 1; select 2, 3"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"non-ASCII text" ByteString
"select 'héllo🐘' as greeting"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"bytea hex output" ByteString
"select '\\xdeadbeef' :: bytea"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"large value" ByteString
"select repeat('x', 100000)"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"many rows" ByteString
"select i from generate_series (1, 1000) as i"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"show command" ByteString
"show server_version"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"set command" ByteString
"set application_name to 'conformance-exec'"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"DDL command tag" ByteString
"create temporary table conformance_exec (id int4)"
    [Char] -> ByteString -> SpecWith (Arg (ByteString -> IO ()))
forCase [Char]
"DDL with a notice" ByteString
"drop table if exists pqi_conformance_absent"