git.iko.soy/typeable/attoparsec
on master help sign in
Add a few more simple tests
commitf35bd656964ef3037a209502d6a805466ef899a9 authorBryan O'Sullivan <bos@serpentine.com> dateFri 16 Jan 2009, 17:08 (18 years ago) parent2e06910
2 files changed+56−6
Data/Attoparsec.hs+1 tests/QC.hs+55−6
Data/Attoparsec.hs+1
@@ -39,6 +39,7 @@ module Data.Attoparsec
3939 , skipWhile
4040 , stringTransform
4141 , takeAll
42+ , takeCount
4243 , takeTill
4344 , takeWhile
4445 , takeWhile1
tests/QC.hs+55−6
@@ -1,11 +1,11 @@
11module Main (main) where
22
33import Control.Applicative
4−import Data.Attoparsec
4+import Data.Attoparsec as P
55import Data.List (isInfixOf)
66import Data.Maybe (isJust)
77import Data.Word (Word8)
8−import Control.Monad
8+import Control.Monad (forM_)
99import Debug.Trace
1010import System.IO
1111import Test.QuickCheck
@@ -38,13 +38,50 @@ prop_anyWord8 (NonEmpty s) = isJust $ maybeP anyWord8 s
3838prop_notWord8 (w, NonEmpty s) = v /= w ==> maybeP (notWord8 w) s == Just v
3939 where v = L.head s
4040
41−--p :: Testable a => a -> Int -> IO ()
42−p prop count = limCheck count prop
41+prop_string s = maybeP (string s) s == Just s
42+
43+prop_skipWhile (w,s) =
44+ let (h,t) = L.span (==w) s
45+ in case parse (skipWhile (==w)) s of
46+ (t',Right ()) -> t == t'
47+ _ -> False
48+
49+prop_takeCount (k,s) =
50+ k >= 0 ==>
51+ case maybeP (takeCount k) s of
52+ Nothing -> j > L.length s
53+ Just s' -> j <= L.length s
54+ where j = fromIntegral k
55+
56+prop_takeWhile (w,s) =
57+ let (h,t) = L.span (==w) s
58+ in case parse (P.takeWhile (==w)) s of
59+ (t',Right h') -> t == t' && h == h'
60+ _ -> False
61+
62+prop_takeWhile1 (w, NonEmpty s) =
63+ let (h,t) = L.span (==w) s
64+ in case parse (P.takeWhile (==w)) s of
65+ (t',Right h') -> t == t' && h == h'
66+ _ -> False
4367
68+prop_takeTill (w, s) =
69+ let (h,t) = L.break (==w) s
70+ in case parse (P.takeTill (==w)) s of
71+ (t',Right h') -> t == t' && h == h'
72+ _ -> False
73+
74+prop_takeWhile1_empty = maybeP (P.takeWhile1 undefined) L.empty == Nothing
75+
76+prop_notEmpty_string s = case maybeP (notEmpty (string s)) s of
77+ Nothing -> L.null s
78+ Just s' -> not (L.null s) && s == s'
79+
80+main :: IO ()
4481main = do
4582 args <- getArgs
4683 let n = case args of
47− [] -> 100
84+ [] -> 500
4885 [k] -> read k
4986 _ -> error "too many arguments"
5087 forM_ tests $ \(name,prop) -> do
@@ -53,11 +90,23 @@ main = do
5390 hFlush stdout
5491 prop n
5592
93+p :: Testable a => a -> Int -> IO ()
94+p prop count = limCheck count prop
95+
96+tests :: [(String, Int -> IO ())]
5697tests = [
5798 ("nonEmptyList", p prop_nonEmptyList),
5899 ("nonEmptyBS", p prop_nonEmptyBS),
59100 ("nonEmptyLBS", p prop_nonEmptyLBS),
60101 ("word8", p prop_word8),
61102 ("notWord8", p prop_notWord8),
62− ("anyWord8", p prop_anyWord8)
103+ ("anyWord8", p prop_anyWord8),
104+ ("string", p prop_string),
105+ ("skipWhile", p prop_skipWhile),
106+ ("takeCount", p prop_takeCount),
107+ ("takeWhile", p prop_takeWhile),
108+ ("takeWhile1", p prop_takeWhile1),
109+ ("takeWhile1_empty", p prop_takeWhile1_empty),
110+ ("takeTill", p prop_takeTill),
111+ ("notEmpty_string", p prop_notEmpty_string)
63112 ]