From b621e9b85717618a27fce7e11bf70f6285f77931 Mon Sep 17 00:00:00 2001 From: Ashley Yakeley Date: Wed, 6 Mar 2024 18:16:43 -0800 Subject: [PATCH] added tests and changelog entry for #232 --- changelog.md | 1 + test/main/Test/Format/ParseTime.hs | 33 +++++++++++++++++++----------- time.cabal | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/changelog.md b/changelog.md index f7d3a083..62481b93 100644 --- a/changelog.md +++ b/changelog.md @@ -50,6 +50,7 @@ - add instance Ord DayOfWeek - add instance Read DiffTime (and NominalDiffTime) - change instance Read UTCTime to allow omitted timezone +- parsing dates rejects ambiguity based on digits, even if there's only one valid date ## [1.10] - 2020-03-13 - remove deprecated functions parseTime, readTime, readsTime diff --git a/test/main/Test/Format/ParseTime.hs b/test/main/Test/Format/ParseTime.hs index b39123d5..93112dee 100644 --- a/test/main/Test/Format/ParseTime.hs +++ b/test/main/Test/Format/ParseTime.hs @@ -111,6 +111,7 @@ testParseTime = [ readsTests , simpleFormatTests , extests + , spacingTests , particularParseTests , badParseTests , defaultTimeZoneTests @@ -236,10 +237,10 @@ simpleFormatTests = , testReadSTime [(epoch, "")] "%QX" "X" ] -spacingTests :: (Show t, Eq t, ParseTime t) => t -> String -> String -> TestTree -spacingTests expected formatStr target = +spacingForFormatTests :: (Show t, Eq t, ParseTime t) => t -> String -> String -> TestTree +spacingForFormatTests expected formatStr target = testGroup - "particular" + formatStr [ parseTest False (Just expected) formatStr target , parseTest True (Just expected) formatStr target , parseTest False (Just expected) (formatStr ++ " ") (target ++ " ") @@ -250,18 +251,26 @@ spacingTests expected formatStr target = , parseTest True (Just expected) (" " ++ formatStr) (" " ++ target) ] +spacingTests :: TestTree +spacingTests = + testGroup + "spacing" + [ spacingForFormatTests epoch "%Q" "" + , spacingForFormatTests epoch "%Q" ".0" + , spacingForFormatTests epoch "%k" " 0" + , spacingForFormatTests epoch "%M" "00" + , spacingForFormatTests epoch "%m" "01" + , spacingForFormatTests (TimeZone 120 False "") "%z" "+0200" + , spacingForFormatTests (TimeZone 120 False "") "%Z" "+0200" + , spacingForFormatTests (TimeZone (-480) False "PST") "%Z" "PST" + ] + particularParseTests :: TestTree particularParseTests = testGroup "particular" - [ spacingTests epoch "%Q" "" - , spacingTests epoch "%Q" ".0" - , spacingTests epoch "%k" " 0" - , spacingTests epoch "%M" "00" - , spacingTests epoch "%m" "01" - , spacingTests (TimeZone 120 False "") "%z" "+0200" - , spacingTests (TimeZone 120 False "") "%Z" "+0200" - , spacingTests (TimeZone (-480) False "PST") "%Z" "PST" + [ parseTest @Day True Nothing "%-d%-m%0Y" "2122012" -- ISSUE #232 + , parseTest @Day True Nothing "%-d%-m%0Y" "2132012" -- ISSUE #232 ] badParseTests :: TestTree @@ -302,7 +311,7 @@ parseCentury :: String -> Integer -> TestTree parseCentury int c = parseTest False (Just (fromGregorian (c * 100) 1 1)) ("%-C" ++ int ++ "%y") ((show c) ++ int ++ "00") -parseTest :: (Show t, Eq t, ParseTime t) => Bool -> Maybe t -> String -> String -> TestTree +parseTest :: forall t. (Show t, Eq t, ParseTime t) => Bool -> Maybe t -> String -> String -> TestTree parseTest sp expected formatStr target = let found = parse sp formatStr target diff --git a/time.cabal b/time.cabal index 82393c07..6b307e9a 100644 --- a/time.cabal +++ b/time.cabal @@ -141,6 +141,7 @@ test-suite test-main default-language: Haskell2010 default-extensions: Rank2Types + TypeApplications GeneralizedNewtypeDeriving DeriveDataTypeable StandaloneDeriving