@@ -1,20 +1,27 @@
11module Main (main) where
22
3−import qualified Streamly.Internal.Data.Parser.ParserD as D
3+import qualified Streamly.Internal.Data.Parser.ParserD as P
44import qualified Streamly.Internal.Prelude as S
55import qualified Streamly.Internal.Data.Fold as FL
66
77-- import Data.List (partition)
88
9−import Test.Hspec(hspec, describe)
9+import Test.Hspec(Spec, hspec, describe)
10+import qualified Test.Hspec as H
1011import Test.Hspec.QuickCheck
11−import Test.QuickCheck (forAll, choose, Property, property, listOf, vectorOf, counterexample, (.&&.), Gen)
12+import Test.QuickCheck (arbitrary, forAll, choose, elements, Property,
13+ property, listOf, vectorOf, counterexample,
14+ (.&&.), Gen)
1215
1316import Test.QuickCheck.Monadic (monadicIO, PropertyM, assert, monitor)
17+import Control.Exception (SomeException(..))
1418import Control.Monad.IO.Class (MonadIO(..))
1519import Control.Monad (when)
1620import Data.List ((\\))
1721
22+maxTestCount :: Int
23+maxTestCount = 100
24+
1825min_value :: Int
1926min_value = 0
2027
@@ -56,59 +63,59 @@ chooseInt = choose
5663fromFold :: Property
5764fromFold =
5865 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
6067 Right is_equal -> is_equal
6168 Left _ -> False
6269
6370any :: Property
6471any =
6572 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
6774 Right r -> r == (Prelude.any (> mid_value) ls)
6875 Left _ -> False
6976
7077all :: Property
7178all =
7279 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
7481 Right r -> r == (Prelude.all (> mid_value) ls)
7582 Left _ -> False
7683
7784yield :: Property
78−yield =
85+yield =
7986 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
8188 Right r -> r == x
8289 Left _ -> False
8390
8491yieldM :: Property
8592yieldM =
8693 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
8895 Right r -> r == x
8996 Left _ -> False
9097
9198die :: Property
9299die =
93100 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
95102 Right _ -> False
96103 Left _ -> True
97104
98105dieM :: Property
99106dieM =
100107 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
102109 Right _ -> False
103110 Left _ -> True
104111
105112-- Element Parser Tests
106113
107114peekPass :: Property
108−peekPass =
115+peekPass =
109116 forAll (chooseInt (1, max_length)) $ \list_length ->
110117 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
112119 Right head_value -> case ls of
113120 head_ls : _ -> head_value == head_ls
114121 _ -> False
@@ -116,40 +123,40 @@ peekPass =
116123
117124peekFail :: Property
118125peekFail =
119− property (case S.parseD D.peek (S.fromList []) of
126+ property (case S.parseD P.peek (S.fromList []) of
120127 Right _ -> False
121128 Left _ -> True)
122129
123130eofPass :: Property
124−eofPass =
125− property (case S.parseD D.eof (S.fromList []) of
131+eofPass =
132+ property (case S.parseD P.eof (S.fromList []) of
126133 Right _ -> True
127134 Left _ -> False)
128135
129136eofFail :: Property
130−eofFail =
137+eofFail =
131138 forAll (chooseInt (1, max_length)) $ \list_length ->
132139 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
134141 Right _ -> False
135142 Left _ -> True
136143
137144satisfyPass :: Property
138−satisfyPass =
145+satisfyPass =
139146 forAll (chooseInt (mid_value, max_value)) $ \first_element ->
140147 forAll (listOf (chooseInt (min_value, max_value))) $ \ls_tail ->
141148 let
142149 ls = first_element : ls_tail
143150 predicate = (>= mid_value)
144151 in
145− case S.parseD (D.satisfy predicate) (S.fromList ls) of
152+ case S.parseD (P.satisfy predicate) (S.fromList ls) of
146153 Right r -> r == first_element
147154 Left _ -> False
148155
149156satisfy :: Property
150−satisfy =
157+satisfy =
151158 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
153160 Right r -> case ls of
154161 [] -> False
155162 (x : _) -> predicate x && (r == x)
@@ -162,19 +169,19 @@ satisfy =
162169-- Sequence Parsers Tests
163170
164171take :: Property
165−take =
172+take =
166173 forAll (chooseInt (min_value, max_value)) $ \n ->
167174 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
169176 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
170177 Left _ -> property False
171178
172179takeEQPass :: Property
173−takeEQPass =
180+takeEQPass =
174181 forAll (chooseInt (min_value, max_value)) $ \n ->
175182 forAll (chooseInt (n, max_value)) $ \list_length ->
176183 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
178185 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
179186 Left _ -> property False
180187
@@ -182,11 +189,11 @@ takeEQ :: Property
182189takeEQ =
183190 forAll (chooseInt (min_value, max_value)) $ \n ->
184191 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
185− let
192+ let
186193 list_length = Prelude.length ls
187194 in
188− case S.parseD (D.takeEQ n FL.toList) (S.fromList ls) of
189− Right parsed_list ->
195+ case S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
196+ Right parsed_list ->
190197 if (n <= list_length) then
191198 checkListEqual parsed_list (Prelude.take n ls)
192199 else
@@ -194,11 +201,11 @@ takeEQ =
194201 Left _ -> property (n > list_length)
195202
196203takeGEPass :: Property
197−takeGEPass =
204+takeGEPass =
198205 forAll (chooseInt (min_value, max_value)) $ \n ->
199206 forAll (chooseInt (n, max_value)) $ \list_length ->
200207 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
202209 Right parsed_list -> checkListEqual parsed_list ls
203210 Left _ -> property False
204211
@@ -206,54 +213,65 @@ takeGE :: Property
206213takeGE =
207214 forAll (chooseInt (min_value, max_value)) $ \n ->
208215 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
209− let
216+ let
210217 list_length = Prelude.length ls
211218 in
212− case S.parseD (D.takeGE n FL.toList) (S.fromList ls) of
213− Right parsed_list ->
219+ case S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
220+ Right parsed_list ->
214221 if (n <= list_length) then
215222 checkListEqual parsed_list ls
216223 else
217224 property False
218225 Left _ -> property (n > list_length)
219226
227+nLessThanEqual0 ::
228+ ( Int
229+ -> FL.Fold (Either SomeException) Int [Int]
230+ -> P.Parser (Either SomeException) Int [Int]
231+ )
232+ -> (Int -> [Int] -> [Int])
233+ -> Property
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
240+
241+takeProperties :: Spec
242+takeProperties =
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)
250+
251+
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.
220254lookAheadPass :: Property
221255lookAheadPass =
222− forAll (chooseInt (min_value + 1, max_value)) $ \n ->
256+ forAll (chooseInt (min_value, max_value)) $ \n ->
223257 let
224− takeWithoutConsume = D.lookAhead $ D.take n FL.toList
258+ takeWithoutConsume = P.lookAhead $ P.take n FL.toList
225259 parseTwice = do
226260 parsed_list_1 <- takeWithoutConsume
227261 parsed_list_2 <- takeWithoutConsume
228262 return (parsed_list_1, parsed_list_2)
229263 in
230− forAll (chooseInt (n, max_value)) $ \list_length ->
264+ forAll (chooseInt (n+1, max_value)) $ \list_length ->
231265 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
232266 case S.parseD parseTwice (S.fromList ls) of
233267 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
234268 Left _ -> property $ False
235269
236−lookAheadFail :: Property
237−lookAheadFail =
238− forAll (chooseInt (min_value + 1, max_value)) $ \n ->
239− let
240− takeWithoutConsume = D.lookAhead $ D.take n FL.toList
241− parseTwice = do
242− parsed_list_1 <- takeWithoutConsume
243− parsed_list_2 <- takeWithoutConsume
244− return (parsed_list_1, parsed_list_2)
245− in
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
249− Right _ -> False
250− Left _ -> True
251−
252270lookAhead :: Property
253271lookAhead =
254− forAll (chooseInt (min_value, max_value)) $ \n ->
272+ forAll (chooseInt (min_value, max_value)) $ \n ->
255273 let
256− takeWithoutConsume = D.lookAhead $ D.take n FL.toList
274+ takeWithoutConsume = P.lookAhead $ P.take n FL.toList
257275 parseTwice = do
258276 parsed_list_1 <- takeWithoutConsume
259277 parsed_list_2 <- takeWithoutConsume
@@ -269,7 +287,7 @@ lookAhead =
269287takeWhile :: Property
270288takeWhile =
271289 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
273291 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile predicate ls)
274292 Left _ -> property False
275293 where
@@ -278,10 +296,10 @@ takeWhile =
278296takeWhile1 :: Property
279297takeWhile1 =
280298 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
282300 Right parsed_list -> case ls of
283301 [] -> property False
284− (x : _) ->
302+ (x : _) ->
285303 if predicate x then
286304 checkListEqual parsed_list (Prelude.takeWhile predicate ls)
287305 else
@@ -291,21 +309,21 @@ takeWhile1 =
291309 (x : _) -> property (not $ predicate x)
292310 where
293311 predicate = (== 0)
294−
312+
295313sliceSepBy :: Property
296314sliceSepBy =
297315 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
299317 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile (not . predicate) ls)
300318 Left _ -> property False
301319 where
302320 predicate = (== 1)
303321
304322sliceSepByMax :: Property
305−sliceSepByMax =
323+sliceSepByMax =
306324 forAll (chooseInt (min_value, max_value)) $ \n ->
307325 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
309327 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
310328 Left _ -> property False
311329 where
@@ -314,7 +332,7 @@ sliceSepByMax =
314332splitWith :: Property
315333splitWith =
316334 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
318336 Right (result_first, result_second) -> case ls of
319337 0 : 1 : _ -> (result_first == 0) && (result_second == 1)
320338 _ -> False
@@ -324,48 +342,48 @@ splitWith =
324342
325343splitWithFailLeft :: Property
326344splitWithFailLeft =
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
328346 Right _ -> False
329347 Left _ -> True)
330348
331349splitWithFailRight :: Property
332350splitWithFailRight =
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
334352 Right _ -> False
335353 Left _ -> True)
336354
337355splitWithFailBoth :: Property
338356splitWithFailBoth =
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
340358 Right _ -> False
341359 Left _ -> True)
342360
343361teeWithPass :: Property
344−teeWithPass =
362+teeWithPass =
345363 forAll (chooseInt (min_value, max_value)) $ \n ->
346364 forAll (listOf (chooseInt (0, 1))) $ \ls ->
347365 let
348− prsr = D.take n FL.toList
366+ prsr = P.take n FL.toList
349367 in
350− case S.parseD (D.teeWith (,) prsr prsr) (S.fromList ls) of
368+ case S.parseD (P.teeWith (,) prsr prsr) (S.fromList ls) of
351369 Right (ls_1, ls_2) -> checkListEqual (Prelude.take n ls) ls_1 .&&. checkListEqual ls_1 ls_2
352370 Left _ -> property False
353371
354372teeWithFailLeft :: Property
355−teeWithFailLeft =
356− property (case S.parseD (D.teeWith (,) (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
373+teeWithFailLeft =
374+ property (case S.parseD (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
357375 Right _ -> False
358376 Left _ -> True)
359377
360378teeWithFailRight :: Property
361−teeWithFailRight =
362− property (case S.parseD (D.teeWith (,) (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
379+teeWithFailRight =
380+ property (case S.parseD (P.teeWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
363381 Right _ -> False
364382 Left _ -> True)
365383
366384teeWithFailBoth :: Property
367−teeWithFailBoth =
368− property (case S.parseD (D.teeWith (,) (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
385+teeWithFailBoth =
386+ property (case S.parseD (P.teeWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
369387 Right _ -> False
370388 Left _ -> True)
371389
@@ -374,9 +392,9 @@ shortestPass =
374392 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
375393 let
376394 half_mid_value = mid_value `Prelude.div` 2
377− prsr_1 = D.takeWhile (<= half_mid_value) FL.toList
378− prsr_2 = D.takeWhile (<= mid_value) FL.toList
379− prsr_shortest = D.shortest prsr_1 prsr_2
395+ prsr_1 = P.takeWhile (<= half_mid_value) FL.toList
396+ prsr_2 = P.takeWhile (<= mid_value) FL.toList
397+ prsr_shortest = P.shortest prsr_1 prsr_2
380398 in
381399 case S.parseD prsr_shortest (S.fromList ls) of
382400 Right short_list -> checkListEqual short_list (Prelude.takeWhile (<= half_mid_value) ls)
@@ -384,19 +402,19 @@ shortestPass =
384402
385403shortestPassLeft :: Property
386404shortestPassLeft =
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
388406 Right r -> r == 1
389407 Left _ -> False)
390408
391409shortestPassRight :: Property
392410shortestPassRight =
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
394412 Right r -> r == 1
395413 Left _ -> False)
396414
397415shortestFailBoth :: Property
398416shortestFailBoth =
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
400418 Right _ -> False
401419 Left _ -> True)
402420
@@ -405,9 +423,9 @@ longestPass =
405423 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
406424 let
407425 half_mid_value = mid_value `Prelude.div` 2
408− prsr_1 = D.takeWhile (<= half_mid_value) FL.toList
409− prsr_2 = D.takeWhile (<= mid_value) FL.toList
410− prsr_longest = D.longest prsr_1 prsr_2
426+ prsr_1 = P.takeWhile (<= half_mid_value) FL.toList
427+ prsr_2 = P.takeWhile (<= mid_value) FL.toList
428+ prsr_longest = P.longest prsr_1 prsr_2
411429 in
412430 case S.parseD prsr_longest (S.fromList ls) of
413431 Right long_list -> long_list == Prelude.takeWhile (<= mid_value) ls
@@ -415,67 +433,70 @@ longestPass =
415433
416434longestPassLeft :: Property
417435longestPassLeft =
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
419437 Right r -> r == 1
420438 Left _ -> False)
421439
422440longestPassRight :: Property
423441longestPassRight =
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
425443 Right r -> r == 1
426444 Left _ -> False)
427445
428446longestFailBoth :: Property
429447longestFailBoth =
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
431449 Right _ -> False
432450 Left _ -> True)
433451
434452many :: Property
435−many =
453+many =
436454 forAll (listOf (chooseInt (0, 1))) $ \ls ->
437455 let
438456 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
440458 in
441459 case S.parseD prsr (S.fromList ls) of
442460 Right res_list -> checkListEqual res_list (Prelude.filter (== 0) ls)
443461 Left _ -> property False
444462
445463many_empty :: Property
446−many_empty =
447− property (case S.parseD (D.many FL.toList (D.die "die")) (S.fromList [1 :: Int]) of
464+many_empty =
465+ property (case S.parseD (P.many FL.toList (P.die "die")) (S.fromList [1 :: Int]) of
448466 Right res_list -> checkListEqual res_list ([] :: [Int])
449467 Left _ -> property False)
450468
451469-- some :: Property
452−-- some =
470+-- some =
453471-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
454472-- let
455473-- 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
457475-- in
458476-- case S.parseD prsr (S.fromList ls) of
459477-- Right res_list -> res_list == Prelude.filter (== 0) ls
460478-- Left _ -> False
461479
462480-- someFail :: Property
463−-- someFail =
464−-- property (case S.parseD (D.some FL.toList (D.die "die")) (S.fromList [1 :: Int]) of
481+-- someFail =
482+-- property (case S.parseD (P.some FL.toList (P.die "die")) (S.fromList [1 :: Int]) of
465483-- Right _ -> False
466484-- Left _ -> True)
467485
468486main :: IO ()
469−main = hspec $ do
487+main =
488+ hspec $
489+ H.parallel $
490+ modifyMaxSuccess (const maxTestCount) $ do
470491 describe "test for accumulator" $ do
471− prop "D.fromFold FL.sum = FL.sum" fromFold
472− prop "D.any = Prelude.any" Main.any
473− prop "D.all = Prelude.all" Main.all
492+ prop "P.fromFold FL.sum = FL.sum" fromFold
493+ prop "P.any = Prelude.any" Main.any
494+ prop "P.all = Prelude.all" Main.all
474495 prop "yield value provided" yield
475496 prop "yield monadic value provided" yieldM
476497 prop "always fail" die
477498 prop "always fail but monadic" dieM
478−
499+
479500 describe "test for element parser" $ do
480501 prop "peek = head with list length > 0" peekPass
481502 prop "peek fail on []" peekFail
@@ -485,18 +506,17 @@ main = hspec $ do
485506 prop "check first element exists and satisfies predicate" satisfy
486507
487508 describe "test for sequence parser" $ do
488− prop "D.take = Prelude.take" Main.take
489− prop "D.takeEQ = Prelude.take when len >= n" takeEQPass
490− prop "D.takeEQ = Prelude.take when len >= n and fail otherwise" Main.takeEQ
491− prop "D.takeGE n ls = ls when len >= n" takeGEPass
492− prop "D.takeGE n ls = ls when len >= n and fail otherwise" Main.takeGE
509+ prop "P.take = Prelude.take" Main.take
510+ prop "P.takeEQ = Prelude.take when len >= n" takeEQPass
511+ prop "P.takeEQ = Prelude.take when len >= n and fail otherwise" Main.takeEQ
512+ prop "P.takeGE n ls = ls when len >= n" takeGEPass
513+ prop "P.takeGE n ls = ls when len >= n and fail otherwise" Main.takeGE
493514 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n" lookAheadPass
494− prop "Fail when stream length exceeded" lookAheadFail
495515 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n, else fail" lookAhead
496− prop "D.takeWhile = Prelude.takeWhile" Main.takeWhile
497− prop "D.takeWhile = Prelude.takeWhile if taken something, else check why failed" takeWhile1
498− prop "D.sliceSepBy = Prelude.takeWhile (not . predicate)" sliceSepBy
499− prop "D.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
516+ prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
517+ prop "P.takeWhile1 = Prelude.takeWhile if taken something, else check why failed" takeWhile1
518+ prop "P.sliceSepBy = Prelude.takeWhile (not . predicate)" sliceSepBy
519+ prop "P.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
500520 prop "parse 0, then 1, else fail" splitWith
501521 prop "fail due to die as left parser" splitWithFailLeft
502522 prop "fail due to die as right parser" splitWithFailRight
@@ -505,15 +525,16 @@ main = hspec $ do
505525 prop "fail due to die as left parser" teeWithFailLeft
506526 prop "fail due to die as right parser" teeWithFailRight
507527 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
509529 prop "pass even if die is left parser" shortestPassLeft
510530 prop "pass even if die is right parser" shortestPassRight
511531 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
513533 prop "pass even if die is left parser" longestPassLeft
514534 prop "pass even if die is right parser" longestPassRight
515535 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
517537 prop "[] due to parser being die" many_empty
518538 -- prop "" some
519− -- prop "fail due to parser being die" someFail
539+ -- prop "fail due to parser being die" someFail
540+ takeProperties