git.iko.soy/typeable/postgresql-simple
on 8c153c4 help sign in
25 lines 939 B history raw
1module Bytea (testBytea) where
3import Common
4import qualified Data.ByteString as B
6testBytea :: TestEnv -> Test
7testBytea TestEnv{..} = TestList
8 [ testStr "empty" []
9 , testStr "\"hello\"" $ map (fromIntegral . fromEnum) ("hello" :: String)
10 , testStr "ascending" [0..255]
11 , testStr "descending" [255,254..0]
12 , testStr "ascending, doubled up" $ doubleUp [0..255]
13 , testStr "descending, doubled up" $ doubleUp [255,254..0]
14 ]
15 where
16 testStr label bytes = TestLabel label $ TestCase $ do
17 let bs = B.pack bytes
19 [Only h] <- query conn "SELECT md5(?::bytea)" [Binary bs]
20 assertBool "Haskell -> SQL conversion altered the string" $ md5 bs == h
22 [Only (Binary r)] <- query conn "SELECT ?::bytea" [Binary bs]
23 assertBool "SQL -> Haskell conversion altered the string" $ bs == r
25 doubleUp = concatMap (\x -> [x, x])