gdritter repos config-ini / 6def6c6
Updates for new Hedgehog versions Getty Ritter 7 years ago
1 changed file(s) with 21 addition(s) and 13 deletion(s). Collapse all Expand all
1 {-# LANGUAGE TypeSynonymInstances #-}
12 {-# LANGUAGE TemplateHaskell #-}
3 {-# LANGUAGE OverloadedStrings #-}
4 {-# OPTIONS_GHC -fno-warn-orphans #-}
25
36 module Main where
47
58 import qualified Data.Foldable as Fold
9 import Data.Function (on)
610 import Data.HashMap.Strict (HashMap)
711 import qualified Data.HashMap.Strict as HM
812 import qualified Data.Ini as I1
913 import qualified Data.Ini.Config.Raw as I2
10 import Data.List (nub)
14 import Data.List (nubBy)
1115 import qualified Data.Sequence as Seq
1216 import Data.Text (Text)
1317 import qualified Data.Text as T
1620 import qualified Hedgehog.Gen as Gen
1721 import qualified Hedgehog.Range as Range
1822
19 prop_iniEquiv :: Property
20 prop_iniEquiv = property $ do
23 propIniEquiv :: Property
24 propIniEquiv = property $ do
2125 raw <- forAll mkIni
2226 let printed = I1.printIniWith I1.defaultWriteIniSettings raw
2327 i1 = I1.parseIni printed
2933 in i1'' === i2''
3034 _ -> failure
3135
32 prop_revIniEquiv :: Property
33 prop_revIniEquiv = property $ do
36 propRevIniEquiv :: Property
37 propRevIniEquiv = property $ do
3438 raw <- forAll mkRichIni
3539 let printed = I2.printIni raw
3640 i1 = I1.parseIni printed
4044 lower i1' === toMaps i2'
4145 _ -> failure
4246
43 prop_iniSelfEquiv :: Property
44 prop_iniSelfEquiv = property $ do
47 propIniSelfEquiv :: Property
48 propIniSelfEquiv = property $ do
4549 raw <- forAll mkRichIni
4650 Right (toMaps raw) === fmap toMaps (I2.parseIni (I2.printIni raw))
4751
6973 return (I1.Ini (HM.fromList ss))
7074
7175 mkComments :: Monad m => Gen m (Seq.Seq I2.BlankLine)
72 mkComments = fmap (Seq.fromList . nub) $ Gen.list (Range.linear 0 5) $
76 mkComments = fmap Seq.fromList $ Gen.list (Range.linear 0 5) $
7377 Gen.choice
7478 [ return I2.BlankLine
7579 , I2.CommentLine <$> Gen.element ";#" <*> textChunk
7781
7882 mkRichIni :: Monad m => Gen m I2.Ini
7983 mkRichIni = do
80 ss <- Gen.list (Range.linear 0 10) $ do
84 ss <- Gen.list (Range.linear 0 100) $ do
8185 name <- textChunk
82 section <- Gen.list (Range.linear 0 10) $ do
86 section <- Gen.list (Range.linear 0 100) $ do
8387 k <- textChunk
8488 v <- textChunk
8589 cs <- mkComments
8892 )
8993 cs <- mkComments
9094 return ( T.toLower name
91 , I2.IniSection name (Seq.fromList section) 0 0 cs
95 , I2.IniSection name (Seq.fromList (nubBy ((==) `on` fst) section)) 0 0 cs
9296 )
93 return (I2.Ini (Seq.fromList ss))
97 return (I2.Ini (Seq.fromList (nubBy ((==) `on` fst) ss)))
9498
9599 main :: IO ()
96100 main = do
97 _ <- $$(checkConcurrent)
101 _ <- checkParallel $ Group "Test.Example"
102 [ ("propIniEquiv", propIniEquiv)
103 , ("propRevIniEquiv", propRevIniEquiv)
104 , ("propIniSelfEquiv", propIniSelfEquiv)
105 ]
98106 return ()