@@ -54,14 +54,14 @@ import Data.Maybe (fromMaybe)
54
54
import Data.Scientific (Scientific , scientific )
55
55
import Data.Tagged (Tagged (.. ))
56
56
import Data.Text (Text )
57
- import Data.Time (UTCTime )
57
+ import Data.Time (UTCTime , ZonedTime )
58
58
import Data.Time.Format.Compat (parseTimeM , defaultTimeLocale )
59
59
import GHC.Generics (Generic )
60
60
import GHC.Generics.Generically (Generically (.. ))
61
61
import Instances ()
62
62
import Numeric.Natural (Natural )
63
63
import Test.Tasty (TestTree , testGroup )
64
- import Test.Tasty.HUnit (Assertion , assertFailure , assertEqual , testCase , (@?=) )
64
+ import Test.Tasty.HUnit (Assertion , assertFailure , assertEqual , testCase , testCaseSteps , (@?=) )
65
65
import Text.Printf (printf )
66
66
import UnitTests.NullaryConstructors (nullaryConstructors )
67
67
import qualified Data.ByteString as S
@@ -188,8 +188,8 @@ utcTimeGood = do
188
188
189
189
-- Test that a few non-timezone qualified timestamp formats get
190
190
-- rejected if decoding to UTCTime.
191
- utcTimeBad :: Assertion
192
- utcTimeBad = do
191
+ utcTimeBad :: ( String -> IO () ) -> Assertion
192
+ utcTimeBad info = do
193
193
verifyFailParse " 2000-01-01T12:13:00" -- missing Zulu time not allowed (some TZ required)
194
194
verifyFailParse " 2000-01-01 12:13:00" -- missing Zulu time not allowed (some TZ required)
195
195
verifyFailParse " 2000-01-01" -- date only not OK
@@ -199,10 +199,21 @@ utcTimeBad = do
199
199
verifyFailParse " 2015-01-03 12:13:00.Z" -- decimal at the end but no digits
200
200
verifyFailParse " 2015-01-03 12:13.000Z" -- decimal at the end, but no seconds
201
201
verifyFailParse " 2015-01-03 23:59:61Z" -- exceeds allowed seconds per day
202
+ verifyFailParse " 2015-01-03 12:13:00 Z" -- space before Zulu
203
+ verifyFailParse " 2015-01-03 12:13:00 +00:00" -- space before offset
202
204
where
203
- verifyFailParse (s :: LT. Text ) =
204
- let (dec :: Maybe UTCTime ) = decode . LT. encodeUtf8 $ LT. concat [" \" " , s, " \" " ] in
205
- assertEqual " verify failure" Nothing dec
205
+ verifyFailParse :: LT. Text -> Assertion
206
+ verifyFailParse s = do
207
+ info (LT. unpack s)
208
+ let bs = LT. encodeUtf8 $ LT. concat [" \" " , s, " \" " ]
209
+ let decU = decode bs :: Maybe UTCTime
210
+ let decZ = decode bs :: Maybe ZonedTime
211
+ assertIsNothing " verify failure UTCTime" decU
212
+ assertIsNothing " verify failure ZonedTime" decZ
213
+
214
+ assertIsNothing :: Show a => String -> Maybe a -> Assertion
215
+ assertIsNothing _ Nothing = return ()
216
+ assertIsNothing err (Just a) = assertFailure $ err ++ " " ++ show a
206
217
207
218
-- Non identifier keys should be escaped & enclosed in brackets
208
219
formatErrorExample :: Assertion
@@ -787,7 +798,7 @@ tests = testGroup "unit" [
787
798
]
788
799
, testGroup " utctime" [
789
800
testCase " good" utcTimeGood
790
- , testCase " bad" utcTimeBad
801
+ , testCaseSteps " bad" utcTimeBad
791
802
]
792
803
, testGroup " formatError" [
793
804
testCase " example 1" formatErrorExample
0 commit comments