import Data.Map.Strict (Map, fromList, toList)
import Text.ParserCombinators.Parsec
import qualified Text.Parsec.ByteString as ParsecBS
+import Test.QuickCheck
data BVal = Bint Integer
| Bstr ByteString
| Bdict (Map String BVal)
deriving (Ord, Eq, Show)
+instance Arbitrary ByteString where
+ arbitrary = pack <$> arbitrary
+
+instance Arbitrary BVal where
+ arbitrary = sized bval
+ where
+ bval :: Int -> Gen BVal
+ bval 0 = oneof [ Bint <$> arbitrary
+ , Bstr <$> arbitrary]
+ bval n = oneof [ Bint <$> arbitrary
+ , Bstr <$> arbitrary
+ , Blist <$> vectorOf n arbitrary
+ , do keys <- vectorOf n arbitrary
+ vals <- vectorOf n arbitrary
+ return $ Bdict $ fromList $ zip keys vals ]
+
-- getters
bValToInteger :: BVal -> Maybe Integer
bValToInteger (Bint x) = Just x