git.iko.soy/typeable/postgresql-simple
on master help sign in
Regression test for #90

The smoke test is hardly adequate, but it exposes the current issue.

commit1c4d2f35fd78a83d0e34fed33af47e8433d49b5e authorLeon P Smith <leon@melding-monads.com> dateMon 18 Nov 2013, 07:34 (13 years ago) parent8c58092
2 files changed+17
postgresql-simple.cabal+1 test/Main.hs+16
postgresql-simple.cabal+1
@@ -105,6 +105,7 @@ test-suite test
105105 , ScopedTypeVariables
106106
107107 build-depends: base
108+ , aeson
108109 , base16-bytestring
109110 , bytestring
110111 , containers
test/Main.hs+16
@@ -12,11 +12,13 @@ import Data.ByteString (ByteString)
1212import Data.IORef
1313import Data.Typeable
1414import qualified Data.ByteString as B
15+import Data.Map (Map)
1516import qualified Data.Map as Map
1617import Data.Text(Text)
1718import System.Exit (exitFailure)
1819import System.IO
1920import qualified Data.Vector as V
21+import Data.Aeson
2022
2123import Notify
2224import Serializable
@@ -32,6 +34,7 @@ tests =
3234 , TestLabel "Time" . testTime
3335 , TestLabel "Array" . testArray
3436 , TestLabel "HStore" . testHStore
37+ , TestLabel "JSON" . testJSON
3538 , TestLabel "Savepoint" . testSavepoint
3639 ]
3740
@@ -166,6 +169,19 @@ testHStore TestEnv{..} = TestCase $ do
166169 m' <- query conn "SELECT ?::hstore" m
167170 [m] @?= m'
168171
172+testJSON :: TestEnv -> Test
173+testJSON TestEnv{..} = TestCase $ do
174+ roundTrip (Map.fromList [] :: Map ByteString ByteString)
175+ roundTrip (Map.fromList [("foo","bar"),("bar","baz"),("baz","hello")] :: Map ByteString ByteString )
176+ roundTrip (Map.fromList [("fo\"o","bar"),("b\\ar","baz"),("baz","\"value\\with\"escapes")] :: Map ByteString ByteString)
177+ roundTrip (V.fromList [1,2,3,4,5::Int])
178+ where
179+ roundTrip :: ToJSON a => a -> Assertion
180+ roundTrip a = do
181+ let js = Only (toJSON a)
182+ js' <- query conn "SELECT ?::json" js
183+ [js] @?= js'
184+
169185testSavepoint :: TestEnv -> Test
170186testSavepoint TestEnv{..} = TestCase $ do
171187 True <- expectError ST.isNoActiveTransactionError $