gdritter repos config-ini / 108cab4
Merge pull request #2 from kquick/master Better generation of regular arbitrary text strings for test-ini-compat. G. D. Ritter authored 7 years ago GitHub committed 7 years ago
2 changed file(s) with 13 addition(s) and 7 deletion(s). Collapse all Expand all
33 dist
44 dist-newstyle
55 cabal.sandbox.config
6 _darcs
1 {-# LANGUAGE TypeSynonymInstances #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3
14 module Main where
25
3 import Data.Char
46 import Data.HashMap.Strict (HashMap)
57 import qualified Data.HashMap.Strict as HM
68 import qualified Data.Ini as I1
79 import qualified Data.Ini.Config.Raw as I2
10 import Data.Monoid
811 import Data.Text (Text)
912 import qualified Data.Text as T
1013
2831 toMaps :: I2.Ini -> HashMap Text (HashMap Text Text)
2932 toMaps (I2.Ini m) = fmap (fmap I2.vValue . I2.isVals) m
3033
34 type AlphaNumText = T.Text
35 instance Arbitrary AlphaNumText where
36 arbitrary = T.pack <$> (listOf1 $ elements $
37 ['a'..'z'] <> ['A'..'Z'] <> ['0'..'9'] <> [' '])
38
3139 newtype ArbIni = ArbIni I1.Ini deriving (Show)
3240
3341 instance Arbitrary ArbIni where
3442 arbitrary = (ArbIni . I1.Ini . HM.fromList) `fmap` listOf sections
3543 where sections = do
36 name <- str
44 name <- arbitrary :: Gen AlphaNumText
3745 sec <- section
3846 return (name, sec)
39 str = (T.pack `fmap` arbitrary) `suchThat` (\ t ->
40 T.all (\ c -> isAlphaNum c || c == ' ')
41 t && not (T.null t))
4247 section = HM.fromList `fmap` listOf kv
4348 kv = do
44 name <- str
45 val <- str
49 name <- arbitrary :: Gen AlphaNumText
50 val <- arbitrary :: Gen AlphaNumText
4651 return (name, val)
4752
4853 main :: IO ()