Skip to content

Commit

Permalink
fix parse test issue (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyYakeley committed Sep 2, 2024
1 parent fdea1ed commit 1b7ba81
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions test/main/Test/Format/ParseTime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -613,23 +613,53 @@ parseEmptyTest _ =
parseEmptyTests :: TestTree
parseEmptyTests = nameTest "parse empty" $ allTypes $ \name p -> nameTest name $ parseEmptyTest p

prop_parse_s :: forall a. (Eq a, Show a, ParseTime a) => (UTCTime -> a) -> UTCTime -> Result
prop_parse_s f t =
let
str = format "%s%Q" t
found = parse False "%s%Q" str
expected = f t
in
compareResult (Just expected) found
class (Eq a, Show a, ParseTime a) => TestParse a where
nonPosixValue :: a -> Bool
nonPosixValue _ = False

instance TestParse UTCTime where
nonPosixValue (UTCTime _ dt) = dt >= 86400 || dt < 0

instance TestParse ZonedTime where
nonPosixValue (ZonedTime t _) = nonPosixValue t

instance TestParse TimeZone

instance TestParse LocalTime where
nonPosixValue (LocalTime _ t) = nonPosixValue t

prop_parse_sz :: forall a. (Eq a, Show a, ParseTime a) => (ZonedTime -> a) -> ZonedTime -> Result
instance TestParse Day

instance TestParse Month

instance TestParse DayOfWeek

instance TestParse TimeOfDay where
nonPosixValue (TimeOfDay _ _ s) = s >= 60 || s < 0

prop_parse_s :: forall a. TestParse a => (UTCTime -> a) -> UTCTime -> Result
prop_parse_s f t =
if nonPosixValue t
then succeeded
else
let
str = format "%s%Q" t
found = parse False "%s%Q" str
expected = f t
in
compareResult (Just expected) found

prop_parse_sz :: forall a. TestParse a => (ZonedTime -> a) -> ZonedTime -> Result
prop_parse_sz f t =
let
str = format "%s%Q %z" t
found = parse False "%s%Q %z" str
expected = f t
in
compareResult (Just expected) found
if nonPosixValue t
then succeeded
else
let
str = format "%s%Q %z" t
found = parse False "%s%Q %z" str
expected = f t
in
compareResult (Just expected) found

zeroTimeZone :: TimeZone
zeroTimeZone = TimeZone 0 False ""
Expand Down

0 comments on commit 1b7ba81

Please sign in to comment.