]> Git — Sourcephile - gargantext.git/blob - src-test/Parsers/Date.hs
Merge remote-tracking branch 'origin/dev-177-DoorWelcome' into dev
[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
15 module Parsers.Date where
16
17
18 import Test.Hspec
19 import Test.QuickCheck
20
21 import Control.Applicative ((<*>))
22 import Data.Either (Either(..))
23 import Data.Time (ZonedTime(..))
24 import Data.Text (pack, Text)
25
26 import Text.Parsec.Error (ParseError)
27 import Duckling.Time.Types (toRFC3339)
28
29 -----------------------------------------------------------
30 import Gargantext.Prelude
31 import Gargantext.Core.Text.Corpus.Parsers.Date.Parsec (fromRFC3339)
32 import Parsers.Types
33 -----------------------------------------------------------
34
35 fromRFC3339Inv :: Either ParseError ZonedTime -> Text
36 fromRFC3339Inv (Right z) = toRFC3339 z
37 fromRFC3339Inv (Left pe) = panic . pack $ show pe
38
39 testFromRFC3339 :: IO ()
40 testFromRFC3339 = hspec $ do
41 describe "Test fromRFC3339: " $ do
42 it "is the inverse of Duckling's toRFC3339" $ property $
43 ((==) <*> (fromRFC3339 . fromRFC3339Inv)) . Right . looseZonedTimePrecision
44
45 -- \x -> uncurry (==) $ (,) <*> (fromRFC3339 . fromRFC3339Inv) $ Right $ looseZonedTimePrecision x
46
47 -- \x -> let e = Right x :: Either ParseError ZonedTime
48 -- in fmap looseZonedTimePrecision e == (fromRFC3339 . fromRFC3339Inv ) (fmap looseZonedTimePrecision e)