gdritter repos config-ini / 2e69d67
Avoid orphan warning + refactor for 7.8 compat in test Getty Ritter 7 years ago
1 changed file(s) with 16 addition(s) and 8 deletion(s). Collapse all Expand all
1010
1111 import Test.QuickCheck
1212
13 iniEquiv :: I1.Ini -> Bool
14 iniEquiv raw = case (i1, i2) of
13 iniEquiv :: ArbIni -> Bool
14 iniEquiv (ArbIni raw) = case (i1, i2) of
1515 (Right i1', Right i2') ->
1616 let i1'' = lower i1'
1717 i2'' = toMaps i2'
2828 toMaps :: I2.Ini -> HashMap Text (HashMap Text Text)
2929 toMaps (I2.Ini m) = fmap (fmap I2.vValue . I2.isVals) m
3030
31 instance Arbitrary I1.Ini where
32 arbitrary = (I1.Ini . HM.fromList) <$> listOf sections
33 where sections = (,) <$> str <*> section
34 str = (T.pack <$> arbitrary) `suchThat` (\ t ->
31 newtype ArbIni = ArbIni I1.Ini deriving (Show)
32
33 instance Arbitrary ArbIni where
34 arbitrary = (ArbIni . I1.Ini . HM.fromList) `fmap` listOf sections
35 where sections = do
36 name <- str
37 sec <- section
38 return (name, sec)
39 str = (T.pack `fmap` arbitrary) `suchThat` (\ t ->
3540 T.all (\ c -> isAlphaNum c || c == ' ')
3641 t && not (T.null t))
37 section = HM.fromList <$> listOf kv
38 kv = (,) <$> str <*> str
42 section = HM.fromList `fmap` listOf kv
43 kv = do
44 name <- str
45 val <- str
46 return (name, val)
3947
4048 main :: IO ()
4149 main = quickCheck iniEquiv