on master help sign in
Add two more test cases

Note that formatAsLogTime is tested against original formatting function. The only exception is that now it formats year with zero padding, as in rfc3339 (ISO8601). This should not be an issue for logging, since nobody is logging events that happened during dark ages or height of roman empire.

commit7cd9df349587d6d19f02a42490bc58628bbcd428 authorLeonid Onokhov <sopvop@gmail.com> dateThu 27 Oct 2016, 18:49 (10 years ago) parent41ac823
1 file changed+10−2
katip/test/Katip/Tests/Format/Time.hs+10−2
katip/test/Katip/Tests/Format/Time.hs+10−2
@@ -3,8 +3,8 @@ module Katip.Tests.Format.Time
33 ( tests
44 ) where
55
6−import Data.Aeson (toJSON)
7−import qualified Data.Text as Text
6+import Data.Aeson (toJSON)
7+import qualified Data.Text as Text
88import Data.Time
99import Data.Time.Clock.POSIX
1010import qualified Data.Time.Locale.Compat as LC
@@ -21,16 +21,22 @@ tests = testGroup "Katip.Format.Time"
2121 assertEqual "time 1" (formatDT t1) (formatAsLogTime t1)
2222 assertEqual "time 2" (formatDT t2) (formatAsLogTime t2)
2323 assertEqual "time 3" (formatDT t3) (formatAsLogTime t3)
24+ assertEqual "time 4" (formatDT t4) (formatAsLogTime t4)
25+ assertEqual "time 5" (formatDT t5) (formatAsLogTime t5)
2426
2527 , testCase "formatAsIso8601" $ do
2628 assertEqual "time 1" (formatDTISO t1) (formatAsIso8601 t1)
2729 assertEqual "time 2" (formatDTISO t2) (formatAsIso8601 t2)
2830 assertEqual "time 3" (formatDTISO t3) (formatAsIso8601 t3)
31+ assertEqual "time 4" (formatDTISO t4) (formatAsIso8601 t4)
32+ assertEqual "time 5" (formatDTISO t5) (formatAsIso8601 t5)
2933
3034 , testCase "formatAsIso8601 Aeson" $ do
3135 assertEqual "time 1" (toJSON t1) (toJSON $ formatAsIso8601 t1)
3236 assertEqual "time 2" (toJSON t2) (toJSON $ formatAsIso8601 t2)
3337 assertEqual "time 3" (toJSON t3) (toJSON $ formatAsIso8601 t3)
38+ assertEqual "time 4" (toJSON t4) (toJSON $ formatAsIso8601 t4)
39+ assertEqual "time 5" (toJSON t5) (toJSON $ formatAsIso8601 t5)
3440
3541
3642 , testProperty "LogTime same as Date.Time" $ \(ArbUTCTime t) ->
@@ -47,6 +53,8 @@ tests = testGroup "Katip.Format.Time"
4753 t1 = UTCTime (fromGregorian 2016 12 34) 5025.123456789012
4854 t2 = UTCTime (fromGregorian 2016 1 23) 5025.123
4955 t3 = UTCTime (fromGregorian 16 12 1) 025
56+ t4 = UTCTime (fromGregorian 2000 1 1) 0.000000000001
57+ t5 = UTCTime (fromGregorian 2000 12 31) 0.100000000001
5058
5159formatDT :: UTCTime -> Text.Text
5260formatDT = Text.pack . formatTime LC.defaultTimeLocale "%0Y-%m-%d %H:%M:%S"