]> Git — Sourcephile - gargantext.git/blob - src-test/Parsers/Date.hs
changement du seuil
[gargantext.git] / src-test / Parsers / Date.hs
1 {-|
2 Module : Parsers.Date
3 Description :
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
12 -}
13
14 {-# LANGUAGE NoImplicitPrelude #-}
15
16 module Parsers.Date where
17
18
19 import Test.Hspec
20 import Test.QuickCheck
21
22 import Control.Applicative ((<*>))
23 import Data.Either (Either(..))
24 import Data.Time (ZonedTime(..))
25 import Data.Text (pack, Text)
26
27 import Text.Parsec.Error (ParseError)
28 import Duckling.Time.Types (toRFC3339)
29
30 -----------------------------------------------------------
31 import Gargantext.Prelude
32 import Gargantext.Text.Parsers.Date (fromRFC3339)
33 import Parsers.Types
34 -----------------------------------------------------------
35
36 fromRFC3339Inv :: Either ParseError ZonedTime -> Text
37 fromRFC3339Inv (Right z) = toRFC3339 z
38 fromRFC3339Inv (Left pe) = panic . pack $ show pe
39
40 testFromRFC3339 :: IO ()
41 testFromRFC3339 = hspec $ do
42 describe "Test fromRFC3339: " $ do
43 it "is the inverse of Duckling's toRFC3339" $ property $
44 ((==) <*> (fromRFC3339 . fromRFC3339Inv)) . Right . looseZonedTimePrecision
45
46 -- \x -> uncurry (==) $ (,) <*> (fromRFC3339 . fromRFC3339Inv) $ Right $ looseZonedTimePrecision x
47
48 -- \x -> let e = Right x :: Either ParseError ZonedTime
49 -- in fmap looseZonedTimePrecision e == (fromRFC3339 . fromRFC3339Inv ) (fmap looseZonedTimePrecision e)