]> Git — Sourcephile - gargantext.git/blob - src-test/Parsers/Date.hs
[FIX] Count improving type.
[gargantext.git] / src-test / Parsers / Date.hs
1 {-# LANGUAGE NoImplicitPrelude #-}
2
3 module Parsers.Date where
4
5 import Gargantext.Prelude
6
7 import Test.Hspec
8 import Test.QuickCheck
9 import Parsers.Types
10
11 import Control.Applicative ((<*>))
12 import Data.Either (Either(..))
13 import Data.Time (ZonedTime(..))
14 import Data.Text (pack, Text)
15
16 import Text.Parsec.Error (ParseError)
17 import Duckling.Time.Types (toRFC3339)
18 import Gargantext.Parsers.Date (fromRFC3339)
19
20 fromRFC3339Inv :: Either ParseError ZonedTime -> Text
21 fromRFC3339Inv (Right z) = toRFC3339 z
22 fromRFC3339Inv (Left pe) = panic . pack $ show pe
23
24 testFromRFC3339 :: IO ()
25 testFromRFC3339 = hspec $ do
26 describe "Test fromRFC3339: " $ do
27 it "is the inverse of Duckling's toRFC3339" $ property $
28 ((==) <*> (fromRFC3339 . fromRFC3339Inv)) . Right . looseZonedTimePrecision
29
30 -- \x -> uncurry (==) $ (,) <*> (fromRFC3339 . fromRFC3339Inv) $ Right $ looseZonedTimePrecision x
31
32 -- \x -> let e = Right x :: Either ParseError ZonedTime
33 -- in fmap looseZonedTimePrecision e == (fromRFC3339 . fromRFC3339Inv ) (fmap looseZonedTimePrecision e)