From: PHO Date: Thu, 11 Mar 2010 09:48:30 +0000 (+0900) Subject: more tests X-Git-Tag: RELEASE-0.1.0.1~8 X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-w3c.git;a=commitdiff_plain;h=4d1f3fc0f0050662a8c9150e0e5f039b72ada265 more tests --- diff --git a/Data/Time/W3C/Format.hs b/Data/Time/W3C/Format.hs index d83d8c3..f3f9fac 100644 --- a/Data/Time/W3C/Format.hs +++ b/Data/Time/W3C/Format.hs @@ -47,7 +47,7 @@ format = format' . convert , ":" , case properFraction second :: (Int, Pico) of (int, 0 ) -> show2 int - (int, frac) -> show2 int ++ tail (show frac) + (int, frac) -> show2 int ++ tail (showFixed True frac) , showTZ tz ] diff --git a/Data/Time/W3C/Types.hs b/Data/Time/W3C/Types.hs index 9f48f68..3a996cb 100644 --- a/Data/Time/W3C/Types.hs +++ b/Data/Time/W3C/Types.hs @@ -33,6 +33,9 @@ fetch name f a Nothing -> convError ("No " ++ name ++ " information in the given value") a Just b -> return b +instance Convertible W3CDateTime W3CDateTime where + safeConvert = return + instance Convertible Day W3CDateTime where safeConvert day = case toGregorian day of diff --git a/tests/ConversionTest.hs b/tests/ConversionTest.hs new file mode 100644 index 0000000..05cf179 --- /dev/null +++ b/tests/ConversionTest.hs @@ -0,0 +1,45 @@ +module ConversionTest + ( testData + ) + where + +import Data.Convertible +import Data.Time +import Data.Time.W3C +import Test.HUnit + + +instance Eq ZonedTime where + a == b + = zonedTimeToUTC a == zonedTimeToUTC b + + +testData :: [Test] +testData = [ convert (W3CDateTime 2010 (Just 1) (Just 2) Nothing Nothing Nothing Nothing) + ~?= + fromGregorian 2010 1 2 + + , convert (W3CDateTime 2010 (Just 1) (Just 2) (Just 3) (Just 4) (Just 5.666666) (Just utc)) + ~?= + ZonedTime { + zonedTimeToLocalTime = let day = fromGregorian 2010 1 2 + tod = TimeOfDay 3 4 5.666666 + in + LocalTime day tod + , zonedTimeZone = utc + } + + , convert (fromGregorian 2010 1 2) + ~?= + W3CDateTime 2010 (Just 1) (Just 2) Nothing Nothing Nothing Nothing + + , convert ZonedTime { + zonedTimeToLocalTime = let day = fromGregorian 2010 1 2 + tod = TimeOfDay 3 4 5.666666 + in + LocalTime day tod + , zonedTimeZone = utc + } + ~?= + W3CDateTime 2010 (Just 1) (Just 2) (Just 3) (Just 4) (Just 5.666666) (Just utc) + ] diff --git a/tests/FormatterTest.hs b/tests/FormatterTest.hs new file mode 100644 index 0000000..fbe2fbc --- /dev/null +++ b/tests/FormatterTest.hs @@ -0,0 +1,35 @@ +module FormatterTest + ( testData + ) + where + +import Data.Time +import Data.Time.W3C +import Test.HUnit + + +testData :: [Test] +testData = [ format (W3CDateTime 2010 Nothing Nothing Nothing Nothing Nothing Nothing) + ~?= + "2010" + + , format (W3CDateTime 2010 (Just 12) Nothing Nothing Nothing Nothing Nothing) + ~?= + "2010-12" + + , format (W3CDateTime 2010 (Just 12) (Just 31) Nothing Nothing Nothing Nothing) + ~?= + "2010-12-31" + + , format (W3CDateTime 2010 (Just 12) (Just 31) (Just 1) (Just 23) Nothing (Just utc)) + ~?= + "2010-12-31T01:23Z" + + , format (W3CDateTime 2010 (Just 12) (Just 31) (Just 1) (Just 23) (Just 45) (Just (hoursToTimeZone 9))) + ~?= + "2010-12-31T01:23:45+09:00" + + , format (W3CDateTime 2010 (Just 12) (Just 31) (Just 1) (Just 23) (Just 45.666666) (Just (hoursToTimeZone 9))) + ~?= + "2010-12-31T01:23:45.666666+09:00" + ] diff --git a/tests/W3CDateTimeUnitTest.hs b/tests/W3CDateTimeUnitTest.hs index e9104dd..905afe9 100644 --- a/tests/W3CDateTimeUnitTest.hs +++ b/tests/W3CDateTimeUnitTest.hs @@ -1,8 +1,13 @@ import Test.HUnit +import qualified ConversionTest +import qualified FormatterTest import qualified ParsecParserTest main :: IO () -main = runTestTT (test testData) >> return () +main = do runTestTT (test testData) >> return () testData :: [Test] -testData = ParsecParserTest.testData \ No newline at end of file +testData = [ "conversion" ~: ConversionTest.testData + , "parser" ~: ParsecParserTest.testData + , "formatter" ~: FormatterTest.testData + ] diff --git a/time-w3c.cabal b/time-w3c.cabal index fef0996..55f63ac 100644 --- a/time-w3c.cabal +++ b/time-w3c.cabal @@ -62,6 +62,8 @@ Executable W3CDateTimeUnitTest ., tests Other-Modules: + ConversionTest + FormatterTest ParsecParserTest Extensions: