@@ -1,10 +1,14 @@
1+{-# LANGUAGE ScopedTypeVariables #-}
1import Common
2import Common
3+import Database.PostgreSQL.Simple.FromField (FromField)
2import Control.Exception as E
4import Control.Exception as E
3import Control.Monad
5import Control.Monad
4import Data.ByteString (ByteString)
6import Data.ByteString (ByteString)
5import qualified Data.ByteString as B
8import qualified Data.ByteString as B
6import System.Exit (exitFailure)
9import System.Exit (exitFailure)
7import System.IO
10import System.IO
11+import qualified Data.Vector as V
9import Notify
13import Notify
10import Serializable
14import Serializable
@@ -18,6 +22,7 @@ tests =
18 , TestLabel "Notify" . testNotify
22 , TestLabel "Notify" . testNotify
19 , TestLabel "Serializable" . testSerializable
23 , TestLabel "Serializable" . testSerializable
20 , TestLabel "Time" . testTime
24 , TestLabel "Time" . testTime
25+ , TestLabel "Array" . testArray
23testBytea :: TestEnv -> Test
28testBytea :: TestEnv -> Test
@@ -75,6 +80,30 @@ testFold TestEnv{..} = TestCase $ do
83+queryFailure :: forall a. (FromField a, Typeable a, Show a)
84+ => Connection -> Query -> a -> Assertion
85+queryFailure conn q resultType = do
86+ x :: Either SomeException [Only a] <- E.try $ query_ conn q
89+ Right val -> assertFailure ("Did not fail as expected: "
92+ ++ show (typeOf resultType)
93+ ++ " -> " ++ show val)
96+testArray :: TestEnv -> Test
97+testArray TestEnv{..} = TestCase $ do
98+ xs <- query_ conn "SELECT '{1,2,3,4}'::_int4"
99+ xs @?= [Only (V.fromList [1,2,3,4 :: Int])]
100+ xs <- query_ conn "SELECT '{{1,2},{3,4}}'::_int4"
101+ xs @?= [Only (V.fromList [V.fromList [1,2],
102+ V.fromList [3,4 :: Int]])]
103+ queryFailure conn "SELECT '{1,2,3,4}'::_int4" (undefined :: V.Vector Bool)
104+ queryFailure conn "SELECT '{{1,2},{3,4}'::_int4" (undefined :: V.Vector Int)
78------------------------------------------------------------------------
107------------------------------------------------------------------------
80-- | Action for connecting to the database that will be used for testing.
109-- | Action for connecting to the database that will be used for testing.