]> gitweb @ CieloNegro.org - time-w3c.git/commitdiff
more tests
authorPHO <pho@cielonegro.org>
Thu, 11 Mar 2010 09:48:30 +0000 (18:48 +0900)
committerPHO <pho@cielonegro.org>
Thu, 11 Mar 2010 09:48:30 +0000 (18:48 +0900)
Data/Time/W3C/Format.hs
Data/Time/W3C/Types.hs
tests/ConversionTest.hs [new file with mode: 0644]
tests/FormatterTest.hs [new file with mode: 0644]
tests/W3CDateTimeUnitTest.hs
time-w3c.cabal

index d83d8c3897eee78aa2d7a7a1b05561dd5db10543..f3f9fac77d1bb37e79ee8b8fe3e8a8c9c9ed8c19 100644 (file)
@@ -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
                    ]
 
index 9f48f68be58dbc627f8f08a6e4d6b71a612f11e9..3a996cba2fe60574e7cf622848dfeb065b0fd746 100644 (file)
@@ -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 (file)
index 0000000..05cf179
--- /dev/null
@@ -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 (file)
index 0000000..fbe2fbc
--- /dev/null
@@ -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"
+           ]
index e9104dd64568e48957522d9cbcdd09887ee38f9e..905afe9702c8b1ca63e573b66b25a172ea858df6 100644 (file)
@@ -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
+           ]
index fef0996405b63bd823aa3143e3eae5312b9bf706..55f63ac9dc95a5d4b84778331608d1c61233a5dc 100644 (file)
@@ -62,6 +62,8 @@ Executable W3CDateTimeUnitTest
         ., tests
 
     Other-Modules:
+        ConversionTest
+        FormatterTest
         ParsecParserTest
 
     Extensions: