@@ -12,17 +12,22 @@ module Main (main) where
13import Control.Monad.Trans
13import Control.Monad.Trans
14import Data.ByteString (ByteString)
14import Data.ByteString (ByteString)
15+import Data.ByteString.Char8 (unpack)
15−import Data.Scientific (fromFloatDigits,Scientific)
16+import Data.Scientific (fromFloatDigits)
16import Data.Fixed (Fixed(MkFixed), Micro, Pico)
17import Data.Fixed (Fixed(MkFixed), Micro, Pico)
18+import Data.String (IsString(fromString))
17import Data.Time
19import Data.Time
18−import Squeal.PostgreSQL hiding (check, defaultMain)
20+import Squeal.PostgreSQL hiding (check, defaultMain, Group)
19import Hedgehog hiding (Range)
21import Hedgehog hiding (Range)
20import qualified Hedgehog.Gen as Gen
22import qualified Hedgehog.Gen as Gen
21import qualified Hedgehog.Main as Main
23import qualified Hedgehog.Main as Main
22import qualified Hedgehog.Range as Range
24import qualified Hedgehog.Range as Range
24main :: IO ()
26main :: IO ()
25−main = Main.defaultMain
27+main = Main.defaultMain [checkParallel roundtrips]
30+roundtrips = Group "roundtrips"
26 [ roundtrip int2 genInt16
31 [ roundtrip int2 genInt16
27 , roundtrip int4 genInt32
32 , roundtrip int4 genInt32
28 , roundtrip int8 genInt64
33 , roundtrip int8 genInt64
@@ -81,16 +86,16 @@ main = Main.defaultMain
81 s <- MkFixed . toInteger <$> Gen.int (Range.constant 0 59)
86 s <- MkFixed . toInteger <$> Gen.int (Range.constant 0 59)
82 return $ TimeOfDay h m s
87 return $ TimeOfDay h m s
83 genLocalTime = LocalTime <$> genDay <*> genTimeOfDay
88 genLocalTime = LocalTime <$> genDay <*> genTimeOfDay
84− genTimeZone = Gen.element $ map (read @TimeZone)
89+ -- genTimeZone = Gen.element $ map (read @TimeZone)
85− [ "UTC", "UT", "GMT", "EST", "EDT", "CST"
90+ -- [ "UTC", "UT", "GMT", "EST", "EDT", "CST"
86− , "CDT", "MST", "MDT", "PST", "PDT" ]
91+ -- , "CDT", "MST", "MDT", "PST", "PDT" ]
87− genTimeWithZone = (,) <$> genTimeOfDay <*> genTimeZone
92+ -- genTimeWithZone = (,) <$> genTimeOfDay <*> genTimeZone
90 :: (ToParam x ty, FromValue ty x, Show x, Eq x)
95 :: (ToParam x ty, FromValue ty x, Show x, Eq x)
91 => TypeExpression schemas ('NotNull ty)
96 => TypeExpression schemas ('NotNull ty)
93− -> IO Bool
98+ -> (PropertyName, Property)
94roundtrip = roundtripOn id
99roundtrip = roundtripOn id
96roundtripOn
101roundtripOn
@@ -98,13 +103,16 @@ roundtripOn
98 => (x -> x)
103 => (x -> x)
99 -> TypeExpression schemas ('NotNull ty)
104 -> TypeExpression schemas ('NotNull ty)
101− -> IO Bool
106+ -> (PropertyName, Property)
102−roundtripOn norm ty gen = check . property $ do
107+roundtripOn norm ty gen = propertyWithName $ do
103 x <- forAll gen
108 x <- forAll gen
104 Just (Only y) <- lift . withConnection connectionString $
109 Just (Only y) <- lift . withConnection connectionString $
105 firstRow =<< runQueryParams
110 firstRow =<< runQueryParams
106 (values_ (parameter @1 ty `as` #fromOnly)) (Only x)
111 (values_ (parameter @1 ty `as` #fromOnly)) (Only x)
107 norm x === y
112 norm x === y
114+ propertyWithName prop =
115+ (fromString (unpack (renderSQL ty)), property prop)
109maxPosFloat :: RealFloat a => a
117maxPosFloat :: RealFloat a => a
110maxPosFloat = x
118maxPosFloat = x
@@ -154,5 +162,5 @@ normalizeTimeOfDay (TimeOfDay h m s) = TimeOfDay h m
154normalizeLocalTime :: LocalTime -> LocalTime
162normalizeLocalTime :: LocalTime -> LocalTime
155normalizeLocalTime (LocalTime d t) = LocalTime d (normalizeTimeOfDay t)
163normalizeLocalTime (LocalTime d t) = LocalTime d (normalizeTimeOfDay t)
157−normalizeTimeWithZone :: (TimeOfDay, TimeZone) -> (TimeOfDay, TimeZone)
165+-- normalizeTimeWithZone :: (TimeOfDay, TimeZone) -> (TimeOfDay, TimeZone)
158−normalizeTimeWithZone (t, z) = (normalizeTimeOfDay t, z)
166+-- normalizeTimeWithZone (t, z) = (normalizeTimeOfDay t, z)