-
Notifications
You must be signed in to change notification settings - Fork 5
/
Main.hs
82 lines (65 loc) · 2.67 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.String (fromString)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Data.Time.Clock.System as Time
import qualified Test.Tasty as Tasty
import Test.Tasty.QuickCheck ((===))
import qualified Test.Tasty.QuickCheck as QC
import qualified Test.Tasty.Runners as Tasty
import qualified Di.Core as Di
import qualified Di.Df1
import qualified Df1
--------------------------------------------------------------------------------
main :: IO ()
main = Tasty.defaultMainWithIngredients
[ Tasty.consoleTestReporter
, Tasty.listingTests
] tt
tt :: Tasty.TestTree
tt = Tasty.testGroup "di-df1"
[ QC.testProperty "fromDiLog . fromDf1Log == id" $ do
QC.forAllShrink QC.arbitrary QC.shrink $ \df1Log -> do
df1Log === Di.Df1.fromDiLog (Di.Df1.fromDf1Log df1Log)
, QC.testProperty "fromDf1Log . fromDiLog == id" $ do
QC.forAllShrink QC.arbitrary QC.shrink $ \diLog -> do
diLog === Di.Df1.fromDf1Log (Di.Df1.fromDiLog diLog)
]
instance QC.Arbitrary (Di.Log Df1.Level Df1.Path Df1.Message) where
arbitrary = Di.Log
<$> genSystemTime <*> QC.arbitrary <*> QC.arbitrary <*> QC.arbitrary
shrink (Di.Log a b c d) = Di.Log
<$> pure a <*> QC.shrink b <*> QC.shrink c <*> QC.shrink d
instance QC.Arbitrary Df1.Log where
arbitrary = Df1.Log
<$> genSystemTime <*> QC.arbitrary <*> QC.arbitrary <*> QC.arbitrary
shrink (Df1.Log a b c d) = Df1.Log
<$> pure a <*> QC.shrink b <*> QC.shrink c <*> QC.shrink d
instance QC.Arbitrary Df1.Path where
arbitrary = QC.oneof
[ Df1.Push <$> QC.arbitrary
, Df1.Attr <$> QC.arbitrary <*> QC.arbitrary ]
shrink (Df1.Push s) = Df1.Push <$> QC.shrink s
shrink (Df1.Attr k v) = Df1.Attr <$> QC.shrink k <*> QC.shrink v
instance QC.Arbitrary Df1.Level where
arbitrary = QC.elements [minBound .. minBound]
instance QC.Arbitrary Df1.Segment where
arbitrary = fromString <$> QC.arbitrary
shrink = map fromString . QC.shrink . TL.unpack . Df1.unSegment
instance QC.Arbitrary Df1.Key where
arbitrary = fromString <$> QC.arbitrary
shrink = map fromString . QC.shrink . TL.unpack . Df1.unKey
instance QC.Arbitrary Df1.Value where
arbitrary = fromString <$> QC.arbitrary
shrink = map fromString . QC.shrink . TL.unpack . Df1.unValue
instance QC.Arbitrary Df1.Message where
arbitrary = fromString <$> QC.arbitrary
shrink = map fromString . QC.shrink . TL.unpack . Df1.unMessage
genSystemTime :: QC.Gen Time.SystemTime
genSystemTime = do
a <- QC.choose (0, 253402300799) -- up to 4 digit years
b <- QC.choose (0, 1000000000)
pure (Time.MkSystemTime a b)