git.iko.soy/typeable/postgresql-simple
on master help sign in
Add tests for the ZonedTime printer
70b92d2Leon P Smith
test/Time.hs+16−7
@@ -47,15 +47,15 @@ testTime :: TestEnv -> Test
47testTime env@TestEnv{..} = TestCase $ do
47testTime env@TestEnv{..} = TestCase $ do
48 initializeTable env
48 initializeTable env
49 execute_ conn "SET timezone TO 'UTC'"
49 execute_ conn "SET timezone TO 'UTC'"
50− checkRoundTrips env
50+ checkRoundTrips env "1860-01-01 00:00:00+00"
51 execute_ conn "SET timezone TO 'America/Chicago'" -- -5:00
51 execute_ conn "SET timezone TO 'America/Chicago'" -- -5:00
52− checkRoundTrips env
52+ checkRoundTrips env "1883-11-18 12:00:00-06"
53 execute_ conn "SET timezone TO 'Asia/Tokyo'" -- +9:00
53 execute_ conn "SET timezone TO 'Asia/Tokyo'" -- +9:00
54− checkRoundTrips env
54+ checkRoundTrips env "1888-01-01 00:00:00+09"
55 execute_ conn "SET timezone TO 'Asia/Kathmandu'" -- +5:45
55 execute_ conn "SET timezone TO 'Asia/Kathmandu'" -- +5:45
56− checkRoundTrips env
56+ checkRoundTrips env "1919-12-31 23:48:44+05:30"
57 execute_ conn "SET timezone TO 'America/St_Johns'" -- -3:30
57 execute_ conn "SET timezone TO 'America/St_Johns'" -- -3:30
58− checkRoundTrips env
58+ checkRoundTrips env "1935-03-30 00:00:52-03:30"
59
59
60initializeTable :: TestEnv -> IO ()
60initializeTable :: TestEnv -> IO ()
61initializeTable TestEnv{..} = withTransaction conn $ do
61initializeTable TestEnv{..} = withTransaction conn $ do
@@ -102,10 +102,19 @@ initializeTable TestEnv{..} = withTransaction conn $ do
102 pop "100 milliseconds" 6.3113904e10
102 pop "100 milliseconds" 6.3113904e10
103 pop "1 second" 6.3113904e9
103 pop "1 second" 6.3113904e9
104
104
105−checkRoundTrips :: TestEnv -> IO ()
105+checkRoundTrips :: TestEnv -> ByteString -> IO ()
106−checkRoundTrips TestEnv{..} = do
106+checkRoundTrips TestEnv{..} limit = do
107 yxs :: [(UTCTime, Int)] <- query_ conn [sql| SELECT y, x FROM testtime |]
107 yxs :: [(UTCTime, Int)] <- query_ conn [sql| SELECT y, x FROM testtime |]
108 forM_ yxs $ \yx -> do
108 forM_ yxs $ \yx -> do
109 res <- query conn [sql| SELECT y=? FROM testtime WHERE x=? |] yx
109 res <- query conn [sql| SELECT y=? FROM testtime WHERE x=? |] yx
110 assertBool "UTCTime did not round-trip from SQL to Haskell and back" $
110 assertBool "UTCTime did not round-trip from SQL to Haskell and back" $
111 res == [Only True]
111 res == [Only True]
112+
113+
114+ yxs :: [(ZonedTime, Int)] <- query conn [sql|
115+ SELECT y, x FROM testtime WHERE y > ?
116+ |] (Only limit)
117+ forM_ yxs $ \yx -> do
118+ res <- query conn [sql| SELECT y=? FROM testtime WHERE x=? |] yx
119+ assertBool "ZonedTime did not round-trip from SQL to Haskell and back" $
120+ res == [Only True]