Skip to content

Commit 2071eff

Browse files
QuickCheck test for encoding bool and double
1 parent 277f0d2 commit 2071eff

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tests/Codecs/QuickCheck.hs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import Test.QuickCheck.Monadic
88

99
import Data.Scientific as S
1010
import Data.Time
11+
import Text.Printf
12+
import Data.List as L
1113
import Data.UUID (UUID, fromWords)
1214
import Data.String (IsString)
1315
import qualified Data.ByteString as B
@@ -118,20 +120,30 @@ testCodecsEncodeDecode = testGroup "Codecs property 'encode . decode = id'"
118120
testCodecsEncodePrint :: TestTree
119121
testCodecsEncodePrint = testGroup
120122
"Codecs property 'Encoded value Postgres = value in Haskell'"
121-
[ mkCodecEncodeTest "uuid" PGT.uuid qBasic PE.uuid show
123+
[ mkCodecEncodeTest "bool" PGT.bool qBasic PE.bool displayBool
122124
, mkCodecEncodeTest "date" PGT.date qBasic PE.date show
123-
, mkCodecEncodeTest "timestamp" PGT.timestamp qBasic PE.timestamp show
124-
, mkCodecEncodeTest "timestamptz" PGT.timestamptz
125-
"SELECT ($1 at time zone 'UTC')||' UTC'" PE.timestamptz show
125+
, mkCodecEncodeTest "float8" PGT.float8
126+
"SELECT trim(to_char($1, '99999999999990.9999999999'))"
127+
PE.float8 (printf "%.10f")
128+
, mkCodecEncodeTest "int8" PGT.int8 qBasic PE.int8 show
126129
, mkCodecEncodeTest "interval" PGT.interval
127130
"SELECT extract(epoch from $1)||'s'" PE.interval show
128131
, mkCodecEncodeTest "numeric" PGT.numeric qBasic PE.numeric
129132
displayScientific
133+
, mkCodecEncodeTest "timestamp" PGT.timestamp qBasic PE.timestamp show
134+
, mkCodecEncodeTest "timestamptz" PGT.timestamptz
135+
"SELECT ($1 at time zone 'UTC')||' UTC'" PE.timestamptz show
136+
, mkCodecEncodeTest "uuid" PGT.uuid qBasic PE.uuid show
130137
]
131138
where
132139
qBasic = "SELECT $1"
140+
133141
displayScientific s | isInteger s = show $ ceiling s
134142
| otherwise = formatScientific S.Fixed Nothing s
143+
144+
displayBool False = "f"
145+
displayBool True = "t"
146+
135147
--
136148
-- Orphan instances
137149
--

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy