git.iko.soy/typeable/postgresql-simple
on master help sign in
Add some smoke tests for hstore
commit103b75e57a6d54632737712ba309d5d6031261ce authorLeon P Smith <leon@melding-monads.com> dateFri 26 Apr 2013, 23:25 (14 years ago) parent13f22f6
2 files changed+15−1
postgresql-simple.cabal+1 test/Main.hs+14−1
postgresql-simple.cabal+1
@@ -103,6 +103,7 @@ test-suite test
103103 build-depends: base
104104 , base16-bytestring
105105 , bytestring
106+ , containers
106107 , cryptohash
107108 , HUnit
108109 , postgresql-simple
test/Main.hs+14−1
@@ -1,11 +1,14 @@
11{-# LANGUAGE ScopedTypeVariables #-}
22import Common
33import Database.PostgreSQL.Simple.FromField (FromField)
4+import Database.PostgreSQL.Simple.HStore
45import Control.Exception as E
56import Control.Monad
67import Data.ByteString (ByteString)
78import Data.Typeable
89import qualified Data.ByteString as B
10+import qualified Data.Map as Map
11+import Data.Text(Text)
912import System.Exit (exitFailure)
1013import System.IO
1114import qualified Data.Vector as V
@@ -23,6 +26,7 @@ tests =
2326 , TestLabel "Serializable" . testSerializable
2427 , TestLabel "Time" . testTime
2528 , TestLabel "Array" . testArray
29+ , TestLabel "HStore" . testHStore
2630 ]
2731
2832testBytea :: TestEnv -> Test
@@ -92,7 +96,6 @@ queryFailure conn q resultType = do
9296 ++ show (typeOf resultType)
9397 ++ " -> " ++ show val)
9498
95−
9699testArray :: TestEnv -> Test
97100testArray TestEnv{..} = TestCase $ do
98101 xs <- query_ conn "SELECT '{1,2,3,4}'::_int4"
@@ -103,6 +106,16 @@ testArray TestEnv{..} = TestCase $ do
103106 queryFailure conn "SELECT '{1,2,3,4}'::_int4" (undefined :: V.Vector Bool)
104107 queryFailure conn "SELECT '{{1,2},{3,4}}'::_int4" (undefined :: V.Vector Int)
105108
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'
106119
107120------------------------------------------------------------------------
108121