Avoid orphan warning + refactor for 7.8 compat in test
Getty Ritter
8 years ago
10 | 10 | |
11 | 11 | import Test.QuickCheck |
12 | 12 | |
13 | iniEquiv :: I1.Ini -> Bool | |
14 | iniEquiv raw = case (i1, i2) of | |
13 | iniEquiv :: ArbIni -> Bool | |
14 | iniEquiv (ArbIni raw) = case (i1, i2) of | |
15 | 15 | (Right i1', Right i2') -> |
16 | 16 | let i1'' = lower i1' |
17 | 17 | i2'' = toMaps i2' |
28 | 28 | toMaps :: I2.Ini -> HashMap Text (HashMap Text Text) |
29 | 29 | toMaps (I2.Ini m) = fmap (fmap I2.vValue . I2.isVals) m |
30 | 30 | |
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 -> | |
35 | 40 | T.all (\ c -> isAlphaNum c || c == ' ') |
36 | 41 | 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) | |
39 | 47 | |
40 | 48 | main :: IO () |
41 | 49 | main = quickCheck iniEquiv |