on 00a2f7b help sign in
698 lines 26 kB history raw
1module Main (main) where
3import Control.Exception (SomeException(..))
4import Data.Word (Word8, Word32, Word64)
5import Streamly.Test.Common (listEquals, checkListEqual, chooseInt)
6import Test.Hspec (Spec, hspec, describe)
7import Test.Hspec.QuickCheck
8import Test.QuickCheck
9 (arbitrary, forAll, elements, Property,
10 property, listOf, vectorOf, (.&&.), Gen, suchThat)
11import Test.QuickCheck.Monadic (monadicIO, assert, run)
13import qualified Data.List as List
14import qualified Prelude
15import qualified Streamly.Internal.Data.Array.Storable.Foreign as A
16import qualified Streamly.Internal.Data.Fold as FL
17import qualified Streamly.Internal.Data.Parser.ParserD as P
18import qualified Streamly.Internal.Data.Stream.IsStream as S
19import qualified Test.Hspec as H
21import Prelude hiding (sequence)
23#if MIN_VERSION_QuickCheck(2,14,0)
25import Test.QuickCheck (chooseAny)
27#else
29import System.Random (Random(random))
30import Test.QuickCheck.Gen (Gen(MkGen))
32-- | Generates a random element over the natural range of `a`.
33chooseAny :: Random a => Gen a
34chooseAny = MkGen (\r _ -> let (x,_) = random r in x)
36#endif
38maxTestCount :: Int
39maxTestCount = 100
41min_value :: Int
42min_value = 0
44mid_value :: Int
45mid_value = 5000
47max_value :: Int
48max_value = 10000
50max_length :: Int
51max_length = 1000
53-- Accumulator Tests
55fromFold :: Property
56fromFold =
57 forAll (listOf $ chooseInt (min_value, max_value))
58 $ \ls ->
59 case (==) <$> (S.parseD (P.fromFold FL.sum) (S.fromList ls))
60 <*> (S.fold FL.sum (S.fromList ls)) of
61 Right is_equal -> is_equal
62 Left _ -> False
64yield :: Property
65yield =
66 forAll (chooseInt (min_value, max_value)) $ \x ->
67 case S.parseD (P.yield x) (S.fromList [1 :: Int]) of
68 Right r -> r == x
69 Left _ -> False
71yieldM :: Property
72yieldM =
73 forAll (chooseInt (min_value, max_value)) $ \x ->
74 case S.parseD (P.yieldM $ return x) (S.fromList [1 :: Int]) of
75 Right r -> r == x
76 Left _ -> False
78die :: Property
79die =
80 property $
81 case S.parseD (P.die "die test") (S.fromList [0 :: Int]) of
82 Right _ -> False
83 Left _ -> True
85dieM :: Property
86dieM =
87 property $
88 case S.parseD (P.dieM (Right "die test")) (S.fromList [0 :: Int]) of
89 Right _ -> False
90 Left _ -> True
92-- Element Parser Tests
94peekPass :: Property
95peekPass =
96 forAll (chooseInt (1, max_length)) $ \list_length ->
97 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
98 case S.parseD P.peek (S.fromList ls) of
99 Right head_value -> case ls of
100 head_ls : _ -> head_value == head_ls
101 _ -> False
102 Left _ -> False
104peekFail :: Property
105peekFail =
106 property (case S.parseD P.peek (S.fromList []) of
107 Right _ -> False
108 Left _ -> True)
110eofPass :: Property
111eofPass =
112 property (case S.parseD P.eof (S.fromList []) of
113 Right _ -> True
114 Left _ -> False)
116eofFail :: Property
117eofFail =
118 forAll (chooseInt (1, max_length)) $ \list_length ->
119 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
120 case S.parseD P.eof (S.fromList ls) of
121 Right _ -> False
122 Left _ -> True
124satisfyPass :: Property
125satisfyPass =
126 forAll (chooseInt (mid_value, max_value)) $ \first_element ->
127 forAll (listOf (chooseInt (min_value, max_value))) $ \ls_tail ->
128 let
129 ls = first_element : ls_tail
130 predicate = (>= mid_value)
131 in
132 case S.parseD (P.satisfy predicate) (S.fromList ls) of
133 Right r -> r == first_element
134 Left _ -> False
136satisfy :: Property
137satisfy =
138 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
139 case S.parseD (P.satisfy predicate) (S.fromList ls) of
140 Right r -> case ls of
141 [] -> False
142 (x : _) -> predicate x && (r == x)
143 Left _ -> case ls of
144 [] -> True
145 (x : _) -> not $ predicate x
146 where
147 predicate = (>= mid_value)
149-- Sequence Parsers Tests
151take :: Property
152take =
153 forAll (chooseInt (min_value, max_value)) $ \n ->
154 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
155 case S.parseD (P.fromFold $ FL.ltake n FL.toList) (S.fromList ls) of
156 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
157 Left _ -> property False
159takeEQPass :: Property
160takeEQPass =
161 forAll (chooseInt (min_value, max_value)) $ \n ->
162 forAll (chooseInt (n, max_value)) $ \list_length ->
163 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
164 case S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
165 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
166 Left _ -> property False
168takeEQ :: Property
169takeEQ =
170 forAll (chooseInt (min_value, max_value)) $ \n ->
171 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
172 let
173 list_length = Prelude.length ls
174 in
175 case S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
176 Right parsed_list ->
177 if (n <= list_length) then
178 checkListEqual parsed_list (Prelude.take n ls)
179 else
180 property False
181 Left _ -> property (n > list_length)
183takeGEPass :: Property
184takeGEPass =
185 forAll (chooseInt (min_value, max_value)) $ \n ->
186 forAll (chooseInt (n, max_value)) $ \list_length ->
187 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
188 case S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
189 Right parsed_list -> checkListEqual parsed_list ls
190 Left _ -> property False
192takeGE :: Property
193takeGE =
194 forAll (chooseInt (min_value, max_value)) $ \n ->
195 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
196 let
197 list_length = Prelude.length ls
198 in
199 case S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
200 Right parsed_list ->
201 if (n <= list_length) then
202 checkListEqual parsed_list ls
203 else
204 property False
205 Left _ -> property (n > list_length)
207nLessThanEqual0 ::
208 ( Int
209 -> FL.Fold (Either SomeException) Int [Int]
210 -> P.Parser (Either SomeException) Int [Int]
211 )
212 -> (Int -> [Int] -> [Int])
213 -> Property
214nLessThanEqual0 tk ltk =
215 forAll (elements [0, (-1)]) $ \n ->
216 forAll (listOf arbitrary) $ \ls ->
217 case S.parseD (tk n FL.toList) (S.fromList ls) of
218 Right parsed_list -> checkListEqual parsed_list (ltk n ls)
219 Left _ -> property False
221takeProperties :: Spec
222takeProperties =
223 describe "take combinators when n <= 0/" $ do
224 prop "takeEQ n FL.toList = []" $
225 nLessThanEqual0 P.takeEQ (\_ -> const [])
226 prop "takeGE n FL.toList xs = xs" $
227 nLessThanEqual0 P.takeGE (\_ -> id)
230-- XXX lookAhead can't deal with EOF which in this case means when
231-- n==list_length, this test will fail. So excluding that case for now.
232lookAheadPass :: Property
233lookAheadPass =
234 forAll (chooseInt (min_value, max_value)) $ \n ->
235 let
236 takeWithoutConsume = P.lookAhead $ P.fromFold $ FL.ltake n FL.toList
237 parseTwice = do
238 parsed_list_1 <- takeWithoutConsume
239 parsed_list_2 <- takeWithoutConsume
240 return (parsed_list_1, parsed_list_2)
241 in
242 forAll (chooseInt (n+1, max_value)) $ \list_length ->
243 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
244 case S.parseD parseTwice (S.fromList ls) of
245 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
246 Left _ -> property $ False
248lookAhead :: Property
249lookAhead =
250 forAll (chooseInt (min_value, max_value)) $ \n ->
251 let
252 takeWithoutConsume = P.lookAhead $ P.fromFold $ FL.ltake n FL.toList
253 parseTwice = do
254 parsed_list_1 <- takeWithoutConsume
255 parsed_list_2 <- takeWithoutConsume
256 return (parsed_list_1, parsed_list_2)
257 in
258 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
259 case S.parseD parseTwice (S.fromList ls) of
260 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
261 Left _ -> property ((list_length < n) || (list_length == n && n == 0))
262 where
263 list_length = Prelude.length ls
265takeWhile :: Property
266takeWhile =
267 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
268 case S.parseD (P.takeWhile predicate FL.toList) (S.fromList ls) of
269 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile predicate ls)
270 Left _ -> property False
271 where
272 predicate = (== 0)
274takeWhile1 :: Property
275takeWhile1 =
276 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
277 case S.parseD (P.takeWhile1 predicate FL.toList) (S.fromList ls) of
278 Right parsed_list -> case ls of
279 [] -> property False
280 (x : _) ->
281 if predicate x then
282 checkListEqual parsed_list (Prelude.takeWhile predicate ls)
283 else
284 property False
285 Left _ -> case ls of
286 [] -> property True
287 (x : _) -> property (not $ predicate x)
288 where
289 predicate = (== 0)
291groupBy :: Property
292groupBy =
293 forAll (listOf (chooseInt (0, 1)))
294 $ \ls ->
295 case S.parseD parser (S.fromList ls) of
296 Right parsed -> checkListEqual parsed (groupByLF ls)
297 Left _ -> property False
299 where
301 cmp = (==)
302 parser = P.groupBy cmp FL.toList
303 groupByLF lst
304 | null lst = []
305 | otherwise = head $ List.groupBy cmp lst
307sliceSepBy :: Property
308sliceSepBy =
309 forAll (listOf (chooseInt (0, 1))) $ \ls ->
310 case S.parseD (P.fromFold $ FL.sliceSepBy predicate FL.toList) (S.fromList ls) of
311 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile (not . predicate) ls)
312 Left _ -> property False
313 where
314 predicate = (== 1)
316sliceSepByMax :: Property
317sliceSepByMax =
318 forAll (chooseInt (min_value, max_value)) $ \n ->
319 forAll (listOf (chooseInt (0, 1))) $ \ls ->
320 case S.parseD (P.fromFold $ FL.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
321 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
322 Left _ -> property False
323 where
324 predicate = (== 1)
326wordBy :: Property
327wordBy =
328 forAll (listOf (elements [' ', 's']))
329 $ \ls ->
330 case S.parseD parser (S.fromList ls) of
331 Right parsed -> checkListEqual parsed (words' ls)
332 Left _ -> property False
334 where
336 predicate = (== ' ')
337 parser = P.many FL.toList (P.wordBy predicate FL.toList)
338 words' lst =
339 let wrds = words lst
340 in if wrds == [] then [""] else wrds
343splitWith :: Property
344splitWith =
345 forAll (listOf (chooseInt (0, 1))) $ \ls ->
346 case S.parseD (P.splitWith (,) (P.satisfy (== 0)) (P.satisfy (== 1))) (S.fromList ls) of
347 Right (result_first, result_second) -> case ls of
348 0 : 1 : _ -> (result_first == 0) && (result_second == 1)
349 _ -> False
350 Left _ -> case ls of
351 0 : 1 : _ -> False
352 _ -> True
354splitWithFailLeft :: Property
355splitWithFailLeft =
356 property (case S.parseD (P.splitWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
357 Right _ -> False
358 Left _ -> True)
360splitWithFailRight :: Property
361splitWithFailRight =
362 property (case S.parseD (P.splitWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
363 Right _ -> False
364 Left _ -> True)
366splitWithFailBoth :: Property
367splitWithFailBoth =
368 property (case S.parseD (P.splitWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
369 Right _ -> False
370 Left _ -> True)
372teeWithPass :: Property
373teeWithPass =
374 forAll (chooseInt (min_value, max_value)) $ \n ->
375 forAll (listOf (chooseInt (0, 1))) $ \ls ->
376 let
377 prsr = P.fromFold $ FL.ltake n FL.toList
378 in
379 case S.parseD (P.teeWith (,) prsr prsr) (S.fromList ls) of
380 Right (ls_1, ls_2) -> checkListEqual (Prelude.take n ls) ls_1 .&&. checkListEqual ls_1 ls_2
381 Left _ -> property False
383teeWithFailLeft :: Property
384teeWithFailLeft =
385 property (case S.parseD (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
386 Right _ -> False
387 Left _ -> True)
389teeWithFailRight :: Property
390teeWithFailRight =
391 property (case S.parseD (P.teeWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
392 Right _ -> False
393 Left _ -> True)
395teeWithFailBoth :: Property
396teeWithFailBoth =
397 property (case S.parseD (P.teeWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
398 Right _ -> False
399 Left _ -> True)
401shortestPass :: Property
402shortestPass =
403 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
404 let
405 half_mid_value = mid_value `Prelude.div` 2
406 prsr_1 = P.takeWhile (<= half_mid_value) FL.toList
407 prsr_2 = P.takeWhile (<= mid_value) FL.toList
408 prsr_shortest = P.shortest prsr_1 prsr_2
409 in
410 case S.parseD prsr_shortest (S.fromList ls) of
411 Right short_list -> checkListEqual short_list (Prelude.takeWhile (<= half_mid_value) ls)
412 Left _ -> property False
414shortestPassLeft :: Property
415shortestPassLeft =
416 property (case S.parseD (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
417 Right r -> r == 1
418 Left _ -> False)
420shortestPassRight :: Property
421shortestPassRight =
422 property (case S.parseD (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
423 Right r -> r == 1
424 Left _ -> False)
426shortestFailBoth :: Property
427shortestFailBoth =
428 property
429 (case S.parseD
430 (P.shortest (P.die "die") (P.die "die"))
431 (S.fromList [1 :: Int]) of
432 Right _ -> False
433 Left _ -> True)
435longestPass :: Property
436longestPass =
437 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
438 let
439 half_mid_value = mid_value `Prelude.div` 2
440 prsr_1 = P.takeWhile (<= half_mid_value) FL.toList
441 prsr_2 = P.takeWhile (<= mid_value) FL.toList
442 prsr_longest = P.longest prsr_1 prsr_2
443 in
444 case S.parseD prsr_longest (S.fromList ls) of
445 Right long_list -> long_list == Prelude.takeWhile (<= mid_value) ls
446 Left _ -> False
448longestPassLeft :: Property
449longestPassLeft =
450 property (case S.parseD (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
451 Right r -> r == 1
452 Left _ -> False)
454longestPassRight :: Property
455longestPassRight =
456 property (case S.parseD (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
457 Right r -> r == 1
458 Left _ -> False)
460longestFailBoth :: Property
461longestFailBoth =
462 property
463 (case S.parseD (P.shortest (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
464 Right _ -> False
465 Left _ -> True)
467many :: Property
468many =
469 forAll (listOf (chooseInt (0, 1)))
470 $ \ls ->
471 let fldstp conL currL = return $ FL.Partial (conL ++ currL)
472 concatFold =
473 FL.Fold fldstp (return []) return
474 prsr = P.many concatFold $ P.fromFold $ FL.sliceSepBy (== 1) FL.toList
475 in case S.parseD prsr (S.fromList ls) of
476 Right res_list ->
477 checkListEqual res_list (Prelude.filter (== 0) ls)
478 Left _ -> property False
480many_empty :: Property
481many_empty =
482 property (case S.parseD (P.many FL.toList (P.die "die")) (S.fromList [1 :: Int]) of
483 Right res_list -> checkListEqual res_list ([] :: [Int])
484 Left _ -> property False)
486some :: Property
487some =
488 forAll (listOf (chooseInt (0, 1)))
489 $ \ls ->
490 let fldstp conL currL = return $ FL.Partial $ conL ++ currL
491 concatFold = FL.Fold fldstp (return []) return
492 prsr = P.some concatFold $ P.fromFold $ FL.sliceSepBy (== 1) FL.toList
493 in case S.parseD prsr (S.fromList ls) of
494 Right res_list -> res_list == Prelude.filter (== 0) ls
495 Left _ -> False
497someFail :: Property
498someFail =
499 property (case S.parseD (P.some FL.toList (P.die "die")) (S.fromList [1 :: Int]) of
500 Right _ -> False
501 Left _ -> True)
503-------------------------------------------------------------------------------
504-- Instances
505-------------------------------------------------------------------------------
507-- XXX Remove "`suchThat` (\x -> length x > 0)) $ \ list1 ->" once FL.ltake is
508-- fixed.
509applicative :: Property
510applicative =
511 forAll (listOf (chooseAny :: Gen Int) `suchThat` (\x -> length x > 0)) $ \ list1 ->
512 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
513 let parser =
514 (,)
515 <$> P.fromFold (FL.ltake (length list1) FL.toList)
516 <*> P.fromFold (FL.ltake (length list2) FL.toList)
517 in monadicIO $ do
518 (olist1, olist2) <-
519 run $ S.parseD parser (S.fromList $ list1 ++ list2)
520 listEquals (==) olist1 list1
521 listEquals (==) olist2 list2
523-- XXX Remove "`suchThat` (\x -> length x > 0)) $ \ list1 ->" once FL.ltake is
524-- fixed.
525sequence :: Property
526sequence =
527 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int) `suchThat` (\x -> length x > 0))) $ \ ins ->
528 let parsers = fmap (\xs -> P.fromFold $ FL.ltake (length xs) FL.toList) ins
529 in monadicIO $ do
530 outs <- run $
531 S.parseD
532 (Prelude.sequence parsers)
533 (S.fromList $ concat ins)
534 listEquals (==) outs ins
536-- XXX Remove "`suchThat` (\x -> length x > 0)) $ \ list1 ->" once FL.ltake is
537-- fixed.
538monad :: Property
539monad =
540 forAll (listOf (chooseAny :: Gen Int) `suchThat` (\x -> length x > 0)) $ \ list1 ->
541 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
542 let parser = do
543 olist1 <- P.fromFold (FL.ltake (length list1) FL.toList)
544 olist2 <- P.fromFold (FL.ltake (length list2) FL.toList)
545 return (olist1, olist2)
546 in monadicIO $ do
547 (olist1, olist2) <-
548 run $ S.parseD parser (S.fromList $ list1 ++ list2)
549 listEquals (==) olist1 list1
550 listEquals (==) olist2 list2
552-------------------------------------------------------------------------------
553-- Stream parsing
554-------------------------------------------------------------------------------
556parseMany :: Property
557parseMany =
558 forAll (chooseInt (1,100)) $ \len ->
559 forAll (listOf (vectorOf len (chooseAny :: Gen Int))) $ \ ins ->
560 monadicIO $ do
561 outs <-
562 ( run
563 $ S.toList
564 $ S.parseManyD
565 (P.fromFold $ FL.ltake len FL.toList) (S.fromList $ concat ins)
566 )
567 listEquals (==) outs ins
569-------------------------------------------------------------------------------
570-- Test for a particular case hit during fs events testing
571-------------------------------------------------------------------------------
573evId :: [Word8]
574evId = [96,238,17,9,0,0,0,0]
576evFlags :: [Word8]
577evFlags = [0,4,1,0,0,0,0,0]
579evPathLen :: [Word8]
580evPathLen = [71,0,0,0,0,0,0,0]
582evPath :: [Word8]
583evPath =
584 [47,85,115,101,114,115,47,118,111,108,47,118,101,109,98,97,47,99,111,109
585 ,112,111,115,101,119,101 ,108,108,45,116,101,99,104,47,69,110,103,47,112
586 ,114,111,106,101,99,116,115,47,115,116,114,101,97,109,108,121,47,115,116
587 ,114,101,97,109,108,121,47,116,109,112,47,122,122
588 ]
590event :: [Word8]
591event = evId ++ evFlags ++ evPathLen ++ evPath
593data Event = Event
594 { eventId :: Word64
595 , eventFlags :: Word32
596 , eventAbsPath :: A.Array Word8
597 } deriving (Show, Ord, Eq)
599readOneEvent :: P.Parser IO Word8 Event
600readOneEvent = do
601 arr <- P.takeEQ 24 (A.writeN 24)
602 let arr1 = A.unsafeCast arr :: A.Array Word64
603 eid = A.unsafeIndex arr1 0
604 eflags = A.unsafeIndex arr1 1
605 pathLen = fromIntegral $ A.unsafeIndex arr1 2
606 path <- P.takeEQ pathLen (A.writeN pathLen)
607 return $ Event
608 { eventId = eid
609 , eventFlags = fromIntegral eflags
610 , eventAbsPath = path
611 }
613parseMany2Events :: Property
614parseMany2Events =
615 monadicIO $ do
616 xs <-
617 ( run
618 $ S.toList
619 $ S.parseManyD readOneEvent
620 $ S.fromList (concat (replicate 2 event))
621 )
622 assert (length xs == 2)
623 -- XXX assuming little endian machine
624 let ev = Event
625 { eventId = 152170080
626 , eventFlags = 66560
627 , eventAbsPath = A.fromList evPath
628 }
629 in listEquals (==) xs (replicate 2 ev)
631-------------------------------------------------------------------------------
632-- Main
633-------------------------------------------------------------------------------
635main :: IO ()
636main =
637 hspec $
638 H.parallel $
639 modifyMaxSuccess (const maxTestCount) $ do
640 describe "Instances" $ do
641 prop "applicative" applicative
642 prop "monad" monad
643 prop "sequence" sequence
645 describe "Stream parsing" $ do
646 prop "parseMany" parseMany
647 prop "parseMany2Events" parseMany2Events
649 describe "test for accumulator" $ do
650 prop "P.fromFold FL.sum = FL.sum" fromFold
651 prop "yield value provided" yield
652 prop "yield monadic value provided" yieldM
653 prop "always fail" die
654 prop "always fail but monadic" dieM
656 describe "test for element parser" $ do
657 prop "peek = head with list length > 0" peekPass
658 prop "peek fail on []" peekFail
659 prop "eof pass on []" eofPass
660 prop "eof fail on non-empty list" eofFail
661 prop "first element exists and >= mid_value" satisfyPass
662 prop "check first element exists and satisfies predicate" satisfy
664 describe "test for sequence parser" $ do
665 prop "P.take = Prelude.take" Main.take
666 prop "P.takeEQ = Prelude.take when len >= n" takeEQPass
667 prop "P.takeEQ = Prelude.take when len >= n and fail otherwise" Main.takeEQ
668 prop "P.takeGE n ls = ls when len >= n" takeGEPass
669 prop "P.takeGE n ls = ls when len >= n and fail otherwise" Main.takeGE
670 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n" lookAheadPass
671 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n, else fail" lookAhead
672 prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
673 prop "P.takeWhile1 = Prelude.takeWhile if taken something, else check why failed" takeWhile1
674 prop "P.groupBy = Prelude.head . Prelude.groupBy" groupBy
675 prop "P.sliceSepBy = Prelude.takeWhile (not . predicate)" sliceSepBy
676 prop "P.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
677 prop "many (P.wordBy ' ') = words'" wordBy
678 prop "parse 0, then 1, else fail" splitWith
679 prop "fail due to die as left parser" splitWithFailLeft
680 prop "fail due to die as right parser" splitWithFailRight
681 prop "fail due to die as both parsers" splitWithFailBoth
682 prop "parsed two lists should be equal" teeWithPass
683 prop "fail due to die as left parser" teeWithFailLeft
684 prop "fail due to die as right parser" teeWithFailRight
685 prop "fail due to die as both parsers" teeWithFailBoth
686 prop "P.takeWhile (<= half_mid_value) = Prelude.takeWhile half_mid_value" shortestPass
687 prop "pass even if die is left parser" shortestPassLeft
688 prop "pass even if die is right parser" shortestPassRight
689 prop "fail due to die as both parsers" shortestFailBoth
690 prop "P.takeWhile (<= mid_value) = Prelude.takeWhile (<= mid_value)" longestPass
691 prop "pass even if die is left parser" longestPassLeft
692 prop "pass even if die is right parser" longestPassRight
693 prop "fail due to die as both parsers" longestFailBoth
694 prop "P.many concatFold $ P.sliceSepBy (== 1) FL.toList = Prelude.filter (== 0)" many
695 prop "[] due to parser being die" many_empty
696 prop "P.some concatFold $ P.sliceSepBy (== 1) FL.toList = Prelude.filter (== 0)" some
697 prop "fail due to parser being die" someFail
698 takeProperties