[commit: packages/time] master: test parse %C %y (c3d1c28)

git at git.haskell.org git at git.haskell.org
Fri Jan 23 23:00:16 UTC 2015


Repository : ssh://git@git.haskell.org/time

On branch  : master
Link       : http://git.haskell.org/packages/time.git/commitdiff/c3d1c2821373e6dbc62923ab74d89c4a6b1b0b18

>---------------------------------------------------------------

commit c3d1c2821373e6dbc62923ab74d89c4a6b1b0b18
Author: Ashley Yakeley <ashley at semantic.org>
Date:   Sat May 7 21:29:05 2011 -0700

    test parse %C %y
    
    Ignore-this: 22f6db0e1424c95dece1fdf7740d982e
    
    darcs-hash:20110508042905-ac6dd-5026d47053631acb8848806368fb17bbf8bc9837


>---------------------------------------------------------------

c3d1c2821373e6dbc62923ab74d89c4a6b1b0b18
 test/TestParseTime.hs | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/test/TestParseTime.hs b/test/TestParseTime.hs
index 64a4504..5594f34 100644
--- a/test/TestParseTime.hs
+++ b/test/TestParseTime.hs
@@ -47,15 +47,27 @@ main = do
     exitWith (if good1 && good2 then ExitSuccess else ExitFailure 1)
 
 extests :: [(String,ExhaustiveTest)]
-extests = [("parse %y",MkExhaustiveTest [0..99] parseYY)]
+extests = [
+    ("parse %y",MkExhaustiveTest [0..99] parseYY),
+    ("parse %C %y 1900s",MkExhaustiveTest [0..99] (parseCYY 19)),
+    ("parse %C %y 2000s",MkExhaustiveTest [0..99] (parseCYY 20)),
+    ("parse %C %y 1400s",MkExhaustiveTest [0..99] (parseCYY 14)),
+    ("parse %C %y 700s",MkExhaustiveTest [0..99] (parseCYY 7))
+    ]
 
 -- | 1969 - 2068
 expectedYear :: Integer -> Integer
 expectedYear i | i >= 69 = 1900 + i
 expectedYear i = 2000 + i
 
+show2 :: Integer -> String
+show2 i = (show (div i 10)) ++ (show (mod i 10))
+
 parseYY :: Integer -> IO Bool
-parseYY i = return (parse "%y" ((show (div i 10)) ++ (show (mod i 10))) == Just (fromGregorian (expectedYear i) 1 1))
+parseYY i = return (parse "%y" (show2 i) == Just (fromGregorian (expectedYear i) 1 1))
+
+parseCYY :: Integer -> Integer -> IO Bool
+parseCYY c i = return (parse "%C %y" ((show2 c) ++ " " ++ (show2 i)) == Just (fromGregorian ((c * 100) + i) 1 1))
 
 checkAll :: RunTest p => [(String,p)] -> IO Bool
 checkAll ps = fmap and (mapM checkOne ps)



More information about the ghc-commits mailing list