1 module UnitTests
.Distribution
.Client
.IndexUtils
.Timestamp
(tests
) where
4 import Data
.Time
.Clock
.POSIX
5 import Distribution
.Parsec
(simpleParsec
)
6 import Distribution
.Pretty
(prettyShow
)
8 import Distribution
.Client
.IndexUtils
.Timestamp
11 import Test
.Tasty
.QuickCheck
15 [ testProperty
"Timestamp1" prop_timestamp1
16 , testProperty
"Timestamp2" prop_timestamp2
17 , testProperty
"Timestamp3" prop_timestamp3
18 , testProperty
"Timestamp4" prop_timestamp4
19 , testProperty
"Timestamp5" prop_timestamp5
22 -- test unixtime format parsing
23 prop_timestamp1
:: NonNegative
Int -> Bool
24 prop_timestamp1
(NonNegative t0
) = Just t
== simpleParsec
('@' : show t0
)
26 t
= epochTimeToTimestamp
$ toEnum t0
:: Timestamp
28 -- test prettyShow/simpleParse roundtrip
29 prop_timestamp2
:: Int -> Bool
30 prop_timestamp2 t0
= simpleParsec
(prettyShow t
) == Just t
32 t
= epochTimeToTimestamp
$ toEnum t0
:: Timestamp
34 -- test prettyShow against reference impl
35 prop_timestamp3
:: Int -> Bool
36 prop_timestamp3 t0
= refDisp t
== prettyShow t
38 t
= epochTimeToTimestamp
$ toEnum t0
:: Timestamp
41 maybe undefined (formatTime
undefined "%FT%TZ")
44 -- test utcTimeToTimestamp/timestampToUTCTime roundtrip
45 prop_timestamp4
:: Int -> Bool
47 (utcTimeToTimestamp
<$> timestampToUTCTime t
) == Just t
49 t
= epochTimeToTimestamp
$ toEnum t0
:: Timestamp
51 prop_timestamp5
:: Int -> Bool
52 prop_timestamp5 t0
= timestampToUTCTime t
== Just ut
54 t
= epochTimeToTimestamp
$ toEnum t0
:: Timestamp
55 ut
= posixSecondsToUTCTime
(fromIntegral t0
)