git.iko.soy/typeable/postgresql-simple
on master help sign in
Add some smoke tests for hstore
103b75eLeon P Smith
postgresql-simple.cabal+1
@@ -103,6 +103,7 @@ test-suite test
103 build-depends: base
103 build-depends: base
104 , base16-bytestring
104 , base16-bytestring
105 , bytestring
105 , bytestring
106+ , containers
106 , cryptohash
107 , cryptohash
107 , HUnit
108 , HUnit
108 , postgresql-simple
109 , postgresql-simple
test/Main.hs+14−1
@@ -1,11 +1,14 @@
1{-# LANGUAGE ScopedTypeVariables #-}
1{-# LANGUAGE ScopedTypeVariables #-}
2import Common
2import Common
3import Database.PostgreSQL.Simple.FromField (FromField)
3import Database.PostgreSQL.Simple.FromField (FromField)
4+import Database.PostgreSQL.Simple.HStore
4import Control.Exception as E
5import Control.Exception as E
5import Control.Monad
6import Control.Monad
6import Data.ByteString (ByteString)
7import Data.ByteString (ByteString)
7import Data.Typeable
8import Data.Typeable
8import qualified Data.ByteString as B
9import qualified Data.ByteString as B
10+import qualified Data.Map as Map
11+import Data.Text(Text)
9import System.Exit (exitFailure)
12import System.Exit (exitFailure)
10import System.IO
13import System.IO
11import qualified Data.Vector as V
14import qualified Data.Vector as V
@@ -23,6 +26,7 @@ tests =
23 , TestLabel "Serializable" . testSerializable
26 , TestLabel "Serializable" . testSerializable
24 , TestLabel "Time" . testTime
27 , TestLabel "Time" . testTime
25 , TestLabel "Array" . testArray
28 , TestLabel "Array" . testArray
29+ , TestLabel "HStore" . testHStore
26 ]
30 ]
27
31
28testBytea :: TestEnv -> Test
32testBytea :: TestEnv -> Test
@@ -92,7 +96,6 @@ queryFailure conn q resultType = do
92 ++ show (typeOf resultType)
96 ++ show (typeOf resultType)
93 ++ " -> " ++ show val)
97 ++ " -> " ++ show val)
94
98
95−
96testArray :: TestEnv -> Test
99testArray :: TestEnv -> Test
97testArray TestEnv{..} = TestCase $ do
100testArray TestEnv{..} = TestCase $ do
98 xs <- query_ conn "SELECT '{1,2,3,4}'::_int4"
101 xs <- query_ conn "SELECT '{1,2,3,4}'::_int4"
@@ -103,6 +106,16 @@ testArray TestEnv{..} = TestCase $ do
103 queryFailure conn "SELECT '{1,2,3,4}'::_int4" (undefined :: V.Vector Bool)
106 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)
107 queryFailure conn "SELECT '{{1,2},{3,4}}'::_int4" (undefined :: V.Vector Int)
105
108
109+testHStore :: TestEnv -> Test
110+testHStore TestEnv{..} = TestCase $ do
111+ roundTrip [("foo","bar"),("bar","baz"),("baz","hello")]
112+ roundTrip [("fo\"o","bar"),("b\\ar","baz"),("baz","\"value\\with\"escapes")]
113+ where
114+ roundTrip :: [(Text,Text)] -> Assertion
115+ roundTrip xs = do
116+ let m = Only (HStoreMap (Map.fromList xs))
117+ m' <- query conn "SELECT ?::hstore" m
118+ [m] @?= m'
106
119
107------------------------------------------------------------------------
120------------------------------------------------------------------------
108
121