@@ -1,20 +1,27 @@
1module Main (main) where
1module Main (main) where
3−import qualified Streamly.Internal.Data.Parser.ParserD as D
3+import qualified Streamly.Internal.Data.Parser.ParserD as P
4import qualified Streamly.Internal.Prelude as S
4import qualified Streamly.Internal.Prelude as S
5import qualified Streamly.Internal.Data.Fold as FL
5import qualified Streamly.Internal.Data.Fold as FL
7-- import Data.List (partition)
7-- import Data.List (partition)
9−import Test.Hspec(hspec, describe)
9+import Test.Hspec(Spec, hspec, describe)
10+import qualified Test.Hspec as H
10import Test.Hspec.QuickCheck
11import Test.Hspec.QuickCheck
12+import Test.QuickCheck (arbitrary, forAll, choose, elements, Property,
11−import Test.QuickCheck (forAll, choose, Property, property, listOf, vectorOf, counterexample, (.&&.), Gen)
13+ property, listOf, vectorOf, counterexample,
13import Test.QuickCheck.Monadic (monadicIO, PropertyM, assert, monitor)
16import Test.QuickCheck.Monadic (monadicIO, PropertyM, assert, monitor)
17+import Control.Exception (SomeException(..))
14import Control.Monad.IO.Class (MonadIO(..))
18import Control.Monad.IO.Class (MonadIO(..))
15import Control.Monad (when)
19import Control.Monad (when)
16import Data.List ((\\))
20import Data.List ((\\))
18min_value :: Int
25min_value :: Int
19min_value = 0
26min_value = 0
@@ -56,59 +63,59 @@ chooseInt = choose
56fromFold :: Property
63fromFold :: Property
58 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
65 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
59− case (==) <$> (S.parseD (D.fromFold FL.sum) (S.fromList ls)) <*> (S.fold FL.sum (S.fromList ls)) of
66+ case (==) <$> (S.parseD (P.fromFold FL.sum) (S.fromList ls)) <*> (S.fold FL.sum (S.fromList ls)) of
60 Right is_equal -> is_equal
67 Right is_equal -> is_equal
61 Left _ -> False
68 Left _ -> False
63any :: Property
70any :: Property
65 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
72 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
66− case S.parseD (D.any (> mid_value)) (S.fromList ls) of
73+ case S.parseD (P.any (> mid_value)) (S.fromList ls) of
67 Right r -> r == (Prelude.any (> mid_value) ls)
74 Right r -> r == (Prelude.any (> mid_value) ls)
68 Left _ -> False
75 Left _ -> False
70all :: Property
77all :: Property
72 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
79 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
73− case S.parseD (D.all (> mid_value)) (S.fromList ls) of
80+ case S.parseD (P.all (> mid_value)) (S.fromList ls) of
74 Right r -> r == (Prelude.all (> mid_value) ls)
81 Right r -> r == (Prelude.all (> mid_value) ls)
75 Left _ -> False
82 Left _ -> False
77yield :: Property
84yield :: Property
79 forAll (chooseInt (min_value, max_value)) $ \x ->
86 forAll (chooseInt (min_value, max_value)) $ \x ->
80− case S.parseD (D.yield x) (S.fromList [1 :: Int]) of
87+ case S.parseD (P.yield x) (S.fromList [1 :: Int]) of
81 Right r -> r == x
88 Right r -> r == x
82 Left _ -> False
89 Left _ -> False
84yieldM :: Property
91yieldM :: Property
86 forAll (chooseInt (min_value, max_value)) $ \x ->
93 forAll (chooseInt (min_value, max_value)) $ \x ->
87− case S.parseD (D.yieldM $ return x) (S.fromList [1 :: Int]) of
94+ case S.parseD (P.yieldM $ return x) (S.fromList [1 :: Int]) of
88 Right r -> r == x
95 Right r -> r == x
89 Left _ -> False
96 Left _ -> False
91die :: Property
98die :: Property
93 property $
100 property $
94− case S.parseD (D.die "die test") (S.fromList [0 :: Int]) of
101+ case S.parseD (P.die "die test") (S.fromList [0 :: Int]) of
95 Right _ -> False
102 Right _ -> False
96 Left _ -> True
103 Left _ -> True
98dieM :: Property
105dieM :: Property
100 property $
107 property $
101− case S.parseD (D.dieM (Right "die test")) (S.fromList [0 :: Int]) of
108+ case S.parseD (P.dieM (Right "die test")) (S.fromList [0 :: Int]) of
102 Right _ -> False
109 Right _ -> False
103 Left _ -> True
110 Left _ -> True
105-- Element Parser Tests
112-- Element Parser Tests
107peekPass :: Property
114peekPass :: Property
108−peekPass =
115+peekPass =
109 forAll (chooseInt (1, max_length)) $ \list_length ->
116 forAll (chooseInt (1, max_length)) $ \list_length ->
110 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
117 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
111− case S.parseD D.peek (S.fromList ls) of
118+ case S.parseD P.peek (S.fromList ls) of
112 Right head_value -> case ls of
119 Right head_value -> case ls of
113 head_ls : _ -> head_value == head_ls
120 head_ls : _ -> head_value == head_ls
114 _ -> False
121 _ -> False
@@ -116,40 +123,40 @@ peekPass =
117peekFail :: Property
124peekFail :: Property
118peekFail =
125peekFail =
119− property (case S.parseD D.peek (S.fromList []) of
126+ property (case S.parseD P.peek (S.fromList []) of
120 Right _ -> False
127 Right _ -> False
121 Left _ -> True)
128 Left _ -> True)
123eofPass :: Property
130eofPass :: Property
124−eofPass =
131+eofPass =
125− property (case S.parseD D.eof (S.fromList []) of
132+ property (case S.parseD P.eof (S.fromList []) of
126 Right _ -> True
133 Right _ -> True
127 Left _ -> False)
134 Left _ -> False)
129eofFail :: Property
136eofFail :: Property
130−eofFail =
137+eofFail =
131 forAll (chooseInt (1, max_length)) $ \list_length ->
138 forAll (chooseInt (1, max_length)) $ \list_length ->
132 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
139 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
133− case S.parseD D.eof (S.fromList ls) of
140+ case S.parseD P.eof (S.fromList ls) of
134 Right _ -> False
141 Right _ -> False
135 Left _ -> True
142 Left _ -> True
137satisfyPass :: Property
144satisfyPass :: Property
138−satisfyPass =
145+satisfyPass =
139 forAll (chooseInt (mid_value, max_value)) $ \first_element ->
146 forAll (chooseInt (mid_value, max_value)) $ \first_element ->
140 forAll (listOf (chooseInt (min_value, max_value))) $ \ls_tail ->
147 forAll (listOf (chooseInt (min_value, max_value))) $ \ls_tail ->
142 ls = first_element : ls_tail
149 ls = first_element : ls_tail
143 predicate = (>= mid_value)
150 predicate = (>= mid_value)
145− case S.parseD (D.satisfy predicate) (S.fromList ls) of
152+ case S.parseD (P.satisfy predicate) (S.fromList ls) of
146 Right r -> r == first_element
153 Right r -> r == first_element
147 Left _ -> False
154 Left _ -> False
149satisfy :: Property
156satisfy :: Property
150−satisfy =
157+satisfy =
151 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
158 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
152− case S.parseD (D.satisfy predicate) (S.fromList ls) of
159+ case S.parseD (P.satisfy predicate) (S.fromList ls) of
153 Right r -> case ls of
160 Right r -> case ls of
154 [] -> False
161 [] -> False
155 (x : _) -> predicate x && (r == x)
162 (x : _) -> predicate x && (r == x)
@@ -162,19 +169,19 @@ satisfy =
162-- Sequence Parsers Tests
169-- Sequence Parsers Tests
164take :: Property
171take :: Property
166 forAll (chooseInt (min_value, max_value)) $ \n ->
173 forAll (chooseInt (min_value, max_value)) $ \n ->
167 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
174 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
168− case S.parseD (D.take n FL.toList) (S.fromList ls) of
175+ case S.parseD (P.take n FL.toList) (S.fromList ls) of
169 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
176 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
170 Left _ -> property False
177 Left _ -> property False
172takeEQPass :: Property
179takeEQPass :: Property
173−takeEQPass =
180+takeEQPass =
174 forAll (chooseInt (min_value, max_value)) $ \n ->
181 forAll (chooseInt (min_value, max_value)) $ \n ->
175 forAll (chooseInt (n, max_value)) $ \list_length ->
182 forAll (chooseInt (n, max_value)) $ \list_length ->
176 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
183 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
177− case S.parseD (D.takeEQ n FL.toList) (S.fromList ls) of
184+ case S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
178 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
185 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
179 Left _ -> property False
186 Left _ -> property False
@@ -182,11 +189,11 @@ takeEQ :: Property
183 forAll (chooseInt (min_value, max_value)) $ \n ->
190 forAll (chooseInt (min_value, max_value)) $ \n ->
184 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
191 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
186 list_length = Prelude.length ls
193 list_length = Prelude.length ls
188− case S.parseD (D.takeEQ n FL.toList) (S.fromList ls) of
195+ case S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
189− Right parsed_list ->
196+ Right parsed_list ->
190 if (n <= list_length) then
197 if (n <= list_length) then
191 checkListEqual parsed_list (Prelude.take n ls)
198 checkListEqual parsed_list (Prelude.take n ls)
@@ -194,11 +201,11 @@ takeEQ =
194 Left _ -> property (n > list_length)
201 Left _ -> property (n > list_length)
196takeGEPass :: Property
203takeGEPass :: Property
197−takeGEPass =
204+takeGEPass =
198 forAll (chooseInt (min_value, max_value)) $ \n ->
205 forAll (chooseInt (min_value, max_value)) $ \n ->
199 forAll (chooseInt (n, max_value)) $ \list_length ->
206 forAll (chooseInt (n, max_value)) $ \list_length ->
200 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
207 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
201− case S.parseD (D.takeGE n FL.toList) (S.fromList ls) of
208+ case S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
202 Right parsed_list -> checkListEqual parsed_list ls
209 Right parsed_list -> checkListEqual parsed_list ls
203 Left _ -> property False
210 Left _ -> property False
@@ -206,54 +213,65 @@ takeGE :: Property
207 forAll (chooseInt (min_value, max_value)) $ \n ->
214 forAll (chooseInt (min_value, max_value)) $ \n ->
208 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
215 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
210 list_length = Prelude.length ls
217 list_length = Prelude.length ls
212− case S.parseD (D.takeGE n FL.toList) (S.fromList ls) of
219+ case S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
213− Right parsed_list ->
220+ Right parsed_list ->
214 if (n <= list_length) then
221 if (n <= list_length) then
215 checkListEqual parsed_list ls
222 checkListEqual parsed_list ls
217 property False
224 property False
218 Left _ -> property (n > list_length)
225 Left _ -> property (n > list_length)
229+ -> FL.Fold (Either SomeException) Int [Int]
230+ -> P.Parser (Either SomeException) Int [Int]
232+ -> (Int -> [Int] -> [Int])
234+nLessThanEqual0 tk ltk =
235+ forAll (elements [0, (-1)]) $ \n ->
236+ forAll (listOf arbitrary) $ \ls ->
237+ case S.parseD (tk n FL.toList) (S.fromList ls) of
238+ Right parsed_list -> checkListEqual parsed_list (ltk n ls)
239+ Left _ -> property False
241+takeProperties :: Spec
243+ describe "take combinators when n <= 0/" $ do
244+ prop "take n FL.toList = []" $
245+ nLessThanEqual0 P.take (\_ -> const [])
246+ prop "takeEQ n FL.toList = []" $
247+ nLessThanEqual0 P.takeEQ (\_ -> const [])
248+ prop "takeGE n FL.toList xs = xs" $
249+ nLessThanEqual0 P.takeGE (\_ -> id)
252+-- XXX lookAhead can't deal with EOF which in this case means when
253+-- n==list_length, this test will fail. So excluding that case for now.
220lookAheadPass :: Property
254lookAheadPass :: Property
221lookAheadPass =
255lookAheadPass =
222− forAll (chooseInt (min_value + 1, max_value)) $ \n ->
256+ forAll (chooseInt (min_value, max_value)) $ \n ->
224− takeWithoutConsume = D.lookAhead $ D.take n FL.toList
258+ takeWithoutConsume = P.lookAhead $ P.take n FL.toList
225 parseTwice = do
259 parseTwice = do
226 parsed_list_1 <- takeWithoutConsume
260 parsed_list_1 <- takeWithoutConsume
227 parsed_list_2 <- takeWithoutConsume
261 parsed_list_2 <- takeWithoutConsume
228 return (parsed_list_1, parsed_list_2)
262 return (parsed_list_1, parsed_list_2)
230− forAll (chooseInt (n, max_value)) $ \list_length ->
264+ forAll (chooseInt (n+1, max_value)) $ \list_length ->
231 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
265 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
232 case S.parseD parseTwice (S.fromList ls) of
266 case S.parseD parseTwice (S.fromList ls) of
233 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
267 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
234 Left _ -> property $ False
268 Left _ -> property $ False
236−lookAheadFail :: Property
238− forAll (chooseInt (min_value + 1, max_value)) $ \n ->
240− takeWithoutConsume = D.lookAhead $ D.take n FL.toList
242− parsed_list_1 <- takeWithoutConsume
243− parsed_list_2 <- takeWithoutConsume
244− return (parsed_list_1, parsed_list_2)
246− forAll (chooseInt (min_value, n - 1)) $ \list_length ->
247− forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
248− case S.parseD parseTwice (S.fromList ls) of
252lookAhead :: Property
270lookAhead :: Property
253lookAhead =
271lookAhead =
254− forAll (chooseInt (min_value, max_value)) $ \n ->
272+ forAll (chooseInt (min_value, max_value)) $ \n ->
256− takeWithoutConsume = D.lookAhead $ D.take n FL.toList
274+ takeWithoutConsume = P.lookAhead $ P.take n FL.toList
257 parseTwice = do
275 parseTwice = do
258 parsed_list_1 <- takeWithoutConsume
276 parsed_list_1 <- takeWithoutConsume
259 parsed_list_2 <- takeWithoutConsume
277 parsed_list_2 <- takeWithoutConsume
@@ -269,7 +287,7 @@ lookAhead =
269takeWhile :: Property
287takeWhile :: Property
270takeWhile =
288takeWhile =
271 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
289 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
272− case S.parseD (D.takeWhile predicate FL.toList) (S.fromList ls) of
290+ case S.parseD (P.takeWhile predicate FL.toList) (S.fromList ls) of
273 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile predicate ls)
291 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile predicate ls)
274 Left _ -> property False
292 Left _ -> property False
@@ -278,10 +296,10 @@ takeWhile =
278takeWhile1 :: Property
296takeWhile1 :: Property
279takeWhile1 =
297takeWhile1 =
280 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
298 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
281− case S.parseD (D.takeWhile1 predicate FL.toList) (S.fromList ls) of
299+ case S.parseD (P.takeWhile1 predicate FL.toList) (S.fromList ls) of
282 Right parsed_list -> case ls of
300 Right parsed_list -> case ls of
283 [] -> property False
301 [] -> property False
284− (x : _) ->
302+ (x : _) ->
285 if predicate x then
303 if predicate x then
286 checkListEqual parsed_list (Prelude.takeWhile predicate ls)
304 checkListEqual parsed_list (Prelude.takeWhile predicate ls)
@@ -291,21 +309,21 @@ takeWhile1 =
291 (x : _) -> property (not $ predicate x)
309 (x : _) -> property (not $ predicate x)
293 predicate = (== 0)
311 predicate = (== 0)
295sliceSepBy :: Property
313sliceSepBy :: Property
296sliceSepBy =
314sliceSepBy =
297 forAll (listOf (chooseInt (0, 1))) $ \ls ->
315 forAll (listOf (chooseInt (0, 1))) $ \ls ->
298− case S.parseD (D.sliceSepBy predicate FL.toList) (S.fromList ls) of
316+ case S.parseD (P.sliceSepBy predicate FL.toList) (S.fromList ls) of
299 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile (not . predicate) ls)
317 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile (not . predicate) ls)
300 Left _ -> property False
318 Left _ -> property False
302 predicate = (== 1)
320 predicate = (== 1)
304sliceSepByMax :: Property
322sliceSepByMax :: Property
305−sliceSepByMax =
323+sliceSepByMax =
306 forAll (chooseInt (min_value, max_value)) $ \n ->
324 forAll (chooseInt (min_value, max_value)) $ \n ->
307 forAll (listOf (chooseInt (0, 1))) $ \ls ->
325 forAll (listOf (chooseInt (0, 1))) $ \ls ->
308− case S.parseD (D.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
326+ case S.parseD (P.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
309 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
327 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
310 Left _ -> property False
328 Left _ -> property False
@@ -314,7 +332,7 @@ sliceSepByMax =
314splitWith :: Property
332splitWith :: Property
315splitWith =
333splitWith =
316 forAll (listOf (chooseInt (0, 1))) $ \ls ->
334 forAll (listOf (chooseInt (0, 1))) $ \ls ->
317− case S.parseD (D.splitWith (,) (D.satisfy (== 0)) (D.satisfy (== 1))) (S.fromList ls) of
335+ case S.parseD (P.splitWith (,) (P.satisfy (== 0)) (P.satisfy (== 1))) (S.fromList ls) of
318 Right (result_first, result_second) -> case ls of
336 Right (result_first, result_second) -> case ls of
319 0 : 1 : _ -> (result_first == 0) && (result_second == 1)
337 0 : 1 : _ -> (result_first == 0) && (result_second == 1)
320 _ -> False
338 _ -> False
@@ -324,48 +342,48 @@ splitWith =
325splitWithFailLeft :: Property
343splitWithFailLeft :: Property
326splitWithFailLeft =
344splitWithFailLeft =
327− property (case S.parseD (D.splitWith (,) (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
345+ property (case S.parseD (P.splitWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
328 Right _ -> False
346 Right _ -> False
329 Left _ -> True)
347 Left _ -> True)
331splitWithFailRight :: Property
349splitWithFailRight :: Property
332splitWithFailRight =
350splitWithFailRight =
333− property (case S.parseD (D.splitWith (,) (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
351+ property (case S.parseD (P.splitWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
334 Right _ -> False
352 Right _ -> False
335 Left _ -> True)
353 Left _ -> True)
337splitWithFailBoth :: Property
355splitWithFailBoth :: Property
338splitWithFailBoth =
356splitWithFailBoth =
339− property (case S.parseD (D.splitWith (,) (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
357+ property (case S.parseD (P.splitWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
340 Right _ -> False
358 Right _ -> False
341 Left _ -> True)
359 Left _ -> True)
343teeWithPass :: Property
361teeWithPass :: Property
344−teeWithPass =
362+teeWithPass =
345 forAll (chooseInt (min_value, max_value)) $ \n ->
363 forAll (chooseInt (min_value, max_value)) $ \n ->
346 forAll (listOf (chooseInt (0, 1))) $ \ls ->
364 forAll (listOf (chooseInt (0, 1))) $ \ls ->
348− prsr = D.take n FL.toList
366+ prsr = P.take n FL.toList
350− case S.parseD (D.teeWith (,) prsr prsr) (S.fromList ls) of
368+ case S.parseD (P.teeWith (,) prsr prsr) (S.fromList ls) of
351 Right (ls_1, ls_2) -> checkListEqual (Prelude.take n ls) ls_1 .&&. checkListEqual ls_1 ls_2
369 Right (ls_1, ls_2) -> checkListEqual (Prelude.take n ls) ls_1 .&&. checkListEqual ls_1 ls_2
352 Left _ -> property False
370 Left _ -> property False
354teeWithFailLeft :: Property
372teeWithFailLeft :: Property
355−teeWithFailLeft =
373+teeWithFailLeft =
356− property (case S.parseD (D.teeWith (,) (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
374+ property (case S.parseD (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
357 Right _ -> False
375 Right _ -> False
358 Left _ -> True)
376 Left _ -> True)
360teeWithFailRight :: Property
378teeWithFailRight :: Property
361−teeWithFailRight =
379+teeWithFailRight =
362− property (case S.parseD (D.teeWith (,) (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
380+ property (case S.parseD (P.teeWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
363 Right _ -> False
381 Right _ -> False
364 Left _ -> True)
382 Left _ -> True)
366teeWithFailBoth :: Property
384teeWithFailBoth :: Property
367−teeWithFailBoth =
385+teeWithFailBoth =
368− property (case S.parseD (D.teeWith (,) (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
386+ property (case S.parseD (P.teeWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
369 Right _ -> False
387 Right _ -> False
370 Left _ -> True)
388 Left _ -> True)
@@ -374,9 +392,9 @@ shortestPass =
374 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
392 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
376 half_mid_value = mid_value `Prelude.div` 2
394 half_mid_value = mid_value `Prelude.div` 2
377− prsr_1 = D.takeWhile (<= half_mid_value) FL.toList
395+ prsr_1 = P.takeWhile (<= half_mid_value) FL.toList
378− prsr_2 = D.takeWhile (<= mid_value) FL.toList
396+ prsr_2 = P.takeWhile (<= mid_value) FL.toList
379− prsr_shortest = D.shortest prsr_1 prsr_2
397+ prsr_shortest = P.shortest prsr_1 prsr_2
381 case S.parseD prsr_shortest (S.fromList ls) of
399 case S.parseD prsr_shortest (S.fromList ls) of
382 Right short_list -> checkListEqual short_list (Prelude.takeWhile (<= half_mid_value) ls)
400 Right short_list -> checkListEqual short_list (Prelude.takeWhile (<= half_mid_value) ls)
@@ -384,19 +402,19 @@ shortestPass =
385shortestPassLeft :: Property
403shortestPassLeft :: Property
386shortestPassLeft =
404shortestPassLeft =
387− property (case S.parseD (D.shortest (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
405+ property (case S.parseD (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
388 Right r -> r == 1
406 Right r -> r == 1
389 Left _ -> False)
407 Left _ -> False)
391shortestPassRight :: Property
409shortestPassRight :: Property
392shortestPassRight =
410shortestPassRight =
393− property (case S.parseD (D.shortest (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
411+ property (case S.parseD (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
394 Right r -> r == 1
412 Right r -> r == 1
395 Left _ -> False)
413 Left _ -> False)
397shortestFailBoth :: Property
415shortestFailBoth :: Property
398shortestFailBoth =
416shortestFailBoth =
399− property (case S.parseD (D.shortest (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
417+ property (case S.parseD (P.shortest (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
400 Right _ -> False
418 Right _ -> False
401 Left _ -> True)
419 Left _ -> True)
@@ -405,9 +423,9 @@ longestPass =
405 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
423 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
407 half_mid_value = mid_value `Prelude.div` 2
425 half_mid_value = mid_value `Prelude.div` 2
408− prsr_1 = D.takeWhile (<= half_mid_value) FL.toList
426+ prsr_1 = P.takeWhile (<= half_mid_value) FL.toList
409− prsr_2 = D.takeWhile (<= mid_value) FL.toList
427+ prsr_2 = P.takeWhile (<= mid_value) FL.toList
410− prsr_longest = D.longest prsr_1 prsr_2
428+ prsr_longest = P.longest prsr_1 prsr_2
412 case S.parseD prsr_longest (S.fromList ls) of
430 case S.parseD prsr_longest (S.fromList ls) of
413 Right long_list -> long_list == Prelude.takeWhile (<= mid_value) ls
431 Right long_list -> long_list == Prelude.takeWhile (<= mid_value) ls
@@ -415,67 +433,70 @@ longestPass =
416longestPassLeft :: Property
434longestPassLeft :: Property
417longestPassLeft =
435longestPassLeft =
418− property (case S.parseD (D.shortest (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
436+ property (case S.parseD (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
419 Right r -> r == 1
437 Right r -> r == 1
420 Left _ -> False)
438 Left _ -> False)
422longestPassRight :: Property
440longestPassRight :: Property
423longestPassRight =
441longestPassRight =
424− property (case S.parseD (D.shortest (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
442+ property (case S.parseD (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
425 Right r -> r == 1
443 Right r -> r == 1
426 Left _ -> False)
444 Left _ -> False)
428longestFailBoth :: Property
446longestFailBoth :: Property
429longestFailBoth =
447longestFailBoth =
430− property (case S.parseD (D.shortest (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
448+ property (case S.parseD (P.shortest (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
431 Right _ -> False
449 Right _ -> False
432 Left _ -> True)
450 Left _ -> True)
434many :: Property
452many :: Property
436 forAll (listOf (chooseInt (0, 1))) $ \ls ->
454 forAll (listOf (chooseInt (0, 1))) $ \ls ->
438 concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
456 concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
439− prsr = D.many concatFold $ D.sliceSepBy (== 1) FL.toList
457+ prsr = P.many concatFold $ P.sliceSepBy (== 1) FL.toList
441 case S.parseD prsr (S.fromList ls) of
459 case S.parseD prsr (S.fromList ls) of
442 Right res_list -> checkListEqual res_list (Prelude.filter (== 0) ls)
460 Right res_list -> checkListEqual res_list (Prelude.filter (== 0) ls)
443 Left _ -> property False
461 Left _ -> property False
445many_empty :: Property
463many_empty :: Property
446−many_empty =
464+many_empty =
447− property (case S.parseD (D.many FL.toList (D.die "die")) (S.fromList [1 :: Int]) of
465+ property (case S.parseD (P.many FL.toList (P.die "die")) (S.fromList [1 :: Int]) of
448 Right res_list -> checkListEqual res_list ([] :: [Int])
466 Right res_list -> checkListEqual res_list ([] :: [Int])
449 Left _ -> property False)
467 Left _ -> property False)
451-- some :: Property
469-- some :: Property
452−-- some =
470+-- some =
453-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
471-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
455-- concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
473-- concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
456−-- prsr = D.some concatFold $ D.sliceSepBy (== 1) FL.toList
474+-- prsr = P.some concatFold $ P.sliceSepBy (== 1) FL.toList
458-- case S.parseD prsr (S.fromList ls) of
476-- case S.parseD prsr (S.fromList ls) of
459-- Right res_list -> res_list == Prelude.filter (== 0) ls
477-- Right res_list -> res_list == Prelude.filter (== 0) ls
460-- Left _ -> False
478-- Left _ -> False
462-- someFail :: Property
480-- someFail :: Property
463−-- someFail =
481+-- someFail =
464−-- property (case S.parseD (D.some FL.toList (D.die "die")) (S.fromList [1 :: Int]) of
482+-- property (case S.parseD (P.some FL.toList (P.die "die")) (S.fromList [1 :: Int]) of
465-- Right _ -> False
483-- Right _ -> False
466-- Left _ -> True)
484-- Left _ -> True)
468main :: IO ()
486main :: IO ()
469−main = hspec $ do
488+ hspec $
490+ modifyMaxSuccess (const maxTestCount) $ do
470 describe "test for accumulator" $ do
491 describe "test for accumulator" $ do
471− prop "D.fromFold FL.sum = FL.sum" fromFold
492+ prop "P.fromFold FL.sum = FL.sum" fromFold
472− prop "D.any = Prelude.any" Main.any
493+ prop "P.any = Prelude.any" Main.any
473− prop "D.all = Prelude.all" Main.all
494+ prop "P.all = Prelude.all" Main.all
474 prop "yield value provided" yield
495 prop "yield value provided" yield
475 prop "yield monadic value provided" yieldM
496 prop "yield monadic value provided" yieldM
476 prop "always fail" die
497 prop "always fail" die
477 prop "always fail but monadic" dieM
498 prop "always fail but monadic" dieM
479 describe "test for element parser" $ do
500 describe "test for element parser" $ do
480 prop "peek = head with list length > 0" peekPass
501 prop "peek = head with list length > 0" peekPass
481 prop "peek fail on []" peekFail
502 prop "peek fail on []" peekFail
@@ -485,18 +506,17 @@ main = hspec $ do
485 prop "check first element exists and satisfies predicate" satisfy
506 prop "check first element exists and satisfies predicate" satisfy
487 describe "test for sequence parser" $ do
508 describe "test for sequence parser" $ do
488− prop "D.take = Prelude.take" Main.take
509+ prop "P.take = Prelude.take" Main.take
489− prop "D.takeEQ = Prelude.take when len >= n" takeEQPass
510+ prop "P.takeEQ = Prelude.take when len >= n" takeEQPass
490− prop "D.takeEQ = Prelude.take when len >= n and fail otherwise" Main.takeEQ
511+ prop "P.takeEQ = Prelude.take when len >= n and fail otherwise" Main.takeEQ
491− prop "D.takeGE n ls = ls when len >= n" takeGEPass
512+ prop "P.takeGE n ls = ls when len >= n" takeGEPass
492− prop "D.takeGE n ls = ls when len >= n and fail otherwise" Main.takeGE
513+ prop "P.takeGE n ls = ls when len >= n and fail otherwise" Main.takeGE
493 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n" lookAheadPass
514 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n" lookAheadPass
494− prop "Fail when stream length exceeded" lookAheadFail
495 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n, else fail" lookAhead
515 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n, else fail" lookAhead
496− prop "D.takeWhile = Prelude.takeWhile" Main.takeWhile
516+ prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
497− prop "D.takeWhile = Prelude.takeWhile if taken something, else check why failed" takeWhile1
517+ prop "P.takeWhile1 = Prelude.takeWhile if taken something, else check why failed" takeWhile1
498− prop "D.sliceSepBy = Prelude.takeWhile (not . predicate)" sliceSepBy
518+ prop "P.sliceSepBy = Prelude.takeWhile (not . predicate)" sliceSepBy
499− prop "D.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
519+ prop "P.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
500 prop "parse 0, then 1, else fail" splitWith
520 prop "parse 0, then 1, else fail" splitWith
501 prop "fail due to die as left parser" splitWithFailLeft
521 prop "fail due to die as left parser" splitWithFailLeft
502 prop "fail due to die as right parser" splitWithFailRight
522 prop "fail due to die as right parser" splitWithFailRight
@@ -505,15 +525,16 @@ main = hspec $ do
505 prop "fail due to die as left parser" teeWithFailLeft
525 prop "fail due to die as left parser" teeWithFailLeft
506 prop "fail due to die as right parser" teeWithFailRight
526 prop "fail due to die as right parser" teeWithFailRight
507 prop "fail due to die as both parsers" teeWithFailBoth
527 prop "fail due to die as both parsers" teeWithFailBoth
508− prop "D.takeWhile (<= half_mid_value) = Prelude.takeWhile half_mid_value" shortestPass
528+ prop "P.takeWhile (<= half_mid_value) = Prelude.takeWhile half_mid_value" shortestPass
509 prop "pass even if die is left parser" shortestPassLeft
529 prop "pass even if die is left parser" shortestPassLeft
510 prop "pass even if die is right parser" shortestPassRight
530 prop "pass even if die is right parser" shortestPassRight
511 prop "fail due to die as both parsers" shortestFailBoth
531 prop "fail due to die as both parsers" shortestFailBoth
512− prop "D.takeWhile (<= mid_value) = Prelude.takeWhile (<= mid_value)" longestPass
532+ prop "P.takeWhile (<= mid_value) = Prelude.takeWhile (<= mid_value)" longestPass
513 prop "pass even if die is left parser" longestPassLeft
533 prop "pass even if die is left parser" longestPassLeft
514 prop "pass even if die is right parser" longestPassRight
534 prop "pass even if die is right parser" longestPassRight
515 prop "fail due to die as both parsers" longestFailBoth
535 prop "fail due to die as both parsers" longestFailBoth
516− prop "D.many concatFold $ D.sliceSepBy (== 1) FL.toList = Prelude.filter (== 0)" many
536+ prop "P.many concatFold $ P.sliceSepBy (== 1) FL.toList = Prelude.filter (== 0)" many
517 prop "[] due to parser being die" many_empty
537 prop "[] due to parser being die" many_empty
518 -- prop "" some
538 -- prop "" some
519− -- prop "fail due to parser being die" someFail
539+ -- prop "fail due to parser being die" someFail