git.iko.soy/typeable/postgresql-simple
on master help sign in
Regression test for 5649f3800a206568bf9e817b889687e79be340be
commit7199c10f198c6f0be3e9172a856dba466ac0f7f4 authorLeon P Smith <leon@melding-monads.com> dateThu 27 Mar 2014, 17:47 (13 years ago) parentc262cc1
1 file changed+21−2
test/Main.hs+21−2
test/Main.hs+21−2
@@ -3,7 +3,7 @@
33{-# LANGUAGE ScopedTypeVariables #-}
44import Common
55import Database.PostgreSQL.Simple.FromField (FromField)
6−import Database.PostgreSQL.Simple.Types(Query(..))
6+import Database.PostgreSQL.Simple.Types(Query(..),Values(..))
77import Database.PostgreSQL.Simple.HStore
88import qualified Database.PostgreSQL.Simple.Transaction as ST
99import Control.Applicative
@@ -40,6 +40,7 @@ tests =
4040 , TestLabel "JSON" . testJSON
4141 , TestLabel "Savepoint" . testSavepoint
4242 , TestLabel "Unicode" . testUnicode
43+ , TestLabel "Values" . testValues
4344 ]
4445
4546testBytea :: TestEnv -> Test
@@ -249,13 +250,31 @@ testSavepoint TestEnv{..} = TestCase $ do
249250
250251testUnicode :: TestEnv -> Test
251252testUnicode TestEnv{..} = TestCase $ do
252− let q = Query . T.encodeUtf8
253+ let q = Query . T.encodeUtf8 -- Handle encoding ourselves to ensure
254+ -- the table gets created correctly.
253255 let messages = map Only ["привет","мир"] :: [Only Text]
254256 execute_ conn (q "CREATE TEMPORARY TABLE ру́сский (сообщение TEXT)")
255257 executeMany conn "INSERT INTO ру́сский (сообщение) VALUES (?)" messages
256258 messages' <- query_ conn "SELECT сообщение FROM ру́сский"
257259 sort messages @?= sort messages'
258260
261+testValues :: TestEnv -> Test
262+testValues TestEnv{..} = TestCase $ do
263+ execute_ conn "CREATE TEMPORARY TABLE values_test (x int, y text)"
264+ test (Values ["int4","text"] [])
265+ test (Values ["int4","text"] [(1,"hello")])
266+ test (Values ["int4","text"] [(1,"hello"),(2,"world")])
267+ test (Values ["int4","text"] [(1,"hello"),(2,"world"),(3,"goodbye")])
268+ test (Values [] [(1,"hello")])
269+ test (Values [] [(1,"hello"),(2,"world")])
270+ test (Values [] [(1,"hello"),(2,"world"),(3,"goodbye")])
271+ where
272+ test :: Values (Int, Text) -> Assertion
273+ test table@(Values _ vals) = do
274+ execute conn "INSERT INTO values_test ?" (Only table)
275+ vals' <- query_ conn "DELETE FROM values_test RETURNING *"
276+ sort vals @?= sort vals'
277+
259278data TestException
260279 = TestException
261280 deriving (Eq, Show, Typeable)