import System.Random
import Data.Word
import Test.HUnit.Utils
+import Text.ParserCombinators.Parsec
(@=?) :: (Eq a, Show a) => a -> a -> Result
expected @=? actual =
random g = randomR (minBound, maxBound) g
instance Arbitrary Char where
- arbitrary = sized $ \n -> choose (toEnum 0, min (toEnum n) maxBound)
- coarbitrary n = variant (if (fromEnum n) >= 0 then toEnum (2 * x) else toEnum (2 * x + 1))
+ arbitrary = sized $ \n -> choose (toEnum 0, min (toEnum (n * 0x50)) maxBound)
+ coarbitrary n = variant (toEnum (2 * x + 1))
where x = (abs . fromEnum $ n)::Int
-- Modified from HUnit
testCount n _ = testCountBase n ++
replicate (length (testCountBase n)) '\b'
+{- | Test a parser, forcing it to apply to all input. -}
+p parser input =
+ case parse parseTest "(none)" input of
+ Left _ -> Nothing
+ Right y -> Just y
+ where parseTest = do r <- parser
+ eof
+ return r
+