]> Git — Sourcephile - gargantext.git/blob - src-test/Parsers/Date.hs
[BIN] Command line options with help: ~/.local/bin/gargantext --help
[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.Tuple (uncurry)
13 import Data.Either (Either(..))
14 import Data.Time (ZonedTime(..))
15 import Data.Text (pack, Text)
16
17 import Text.Parsec.Error (ParseError)
18 import Duckling.Time.Types (toRFC3339)
19 import Gargantext.Parsers.Date (fromRFC3339)
20
21 fromRFC3339Inv :: Either ParseError ZonedTime -> Text
22 fromRFC3339Inv (Right z) = toRFC3339 z
23 fromRFC3339Inv (Left pe) = panic . pack $ show pe
24
25 testFromRFC3339 :: IO ()
26 testFromRFC3339 = hspec $ do
27 describe "Test fromRFC3339: " $ do
28 it "is the inverse of Duckling's toRFC3339" $ property $
29 ((==) <*> (fromRFC3339 . fromRFC3339Inv)) . Right . looseZonedTimePrecision
30
31 -- \x -> uncurry (==) $ (,) <*> (fromRFC3339 . fromRFC3339Inv) $ Right $ looseZonedTimePrecision x
32
33 -- \x -> let e = Right x :: Either ParseError ZonedTime
34 -- in fmap looseZonedTimePrecision e == (fromRFC3339 . fromRFC3339Inv ) (fmap looseZonedTimePrecision e)