@@ -4,43 +4,86 @@ import qualified Streamly.Internal.Data.Parser.ParserD as D
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)
7import Test.Hspec(hspec, describe)
9import Test.Hspec(hspec, describe)
8import Test.Hspec.QuickCheck
10import Test.Hspec.QuickCheck
9−import Test.QuickCheck (forAll, chooseInt, Property, property, listOf, vectorOf, (.&&.))
11+import Test.QuickCheck (forAll, choose, Property, property, listOf, vectorOf, counterexample, (.&&.), Gen)
13+import Test.QuickCheck.Monadic (monadicIO, PropertyM, assert, monitor)
14+import Control.Monad.IO.Class (MonadIO(..))
15+import Control.Monad (when)
16+import Data.List ((\\))
30+listEquals :: (Show a, Eq a, MonadIO m)
31+ => ([a] -> [a] -> Bool) -> [a] -> [a] -> PropertyM m ()
32+listEquals eq parsed_list list = do
33+ when (not $ parsed_list `eq` list) $ liftIO $ putStrLn $
34+ "parsed list " ++ show parsed_list
35+ ++ "\nlist " ++ show list
36+ ++ "\nparsed list \\\\ list " ++ show (parsed_list \\ list)
37+ ++ "\nlist \\\\ parsed list " ++ show (list \\ parsed_list)
38+ when (not $ parsed_list `eq` list) $
41+ "parsed list " ++ show parsed_list
42+ ++ "\nlist " ++ show list
43+ ++ "\nparsed list \\\\ list " ++ show (parsed_list \\ list)
44+ ++ "\nlist \\\\ parsed list " ++ show (list \\ parsed_list)
46+ assert (parsed_list `eq` list)
48+checkListEqual :: (Show a, Eq a) => [a] -> [a] -> Property
49+checkListEqual ls_1 ls_2 = monadicIO (listEquals (==) ls_1 ls_2)
51+chooseInt :: (Int, Int) -> Gen Int
11-- Accumulator Tests
54-- Accumulator Tests
13fromFold :: Property
56fromFold :: Property
15− forAll (listOf $ chooseInt (0, 10000)) $ \ls ->
58+ forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
16 case (==) <$> (S.parseD (D.fromFold FL.sum) (S.fromList ls)) <*> (S.fold FL.sum (S.fromList ls)) of
59 case (==) <$> (S.parseD (D.fromFold FL.sum) (S.fromList ls)) <*> (S.fold FL.sum (S.fromList ls)) of
17 Right is_equal -> is_equal
60 Right is_equal -> is_equal
18 Left _ -> False
61 Left _ -> False
20any :: Property
63any :: Property
22− forAll (listOf $ chooseInt (0, 10000)) $ \ls ->
65+ forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
23− case S.parseD (D.any (> 5000)) (S.fromList ls) of
66+ case S.parseD (D.any (> mid_value)) (S.fromList ls) of
24− Right r -> r == (Prelude.any (> 5000) ls)
67+ Right r -> r == (Prelude.any (> mid_value) ls)
25 Left _ -> False
68 Left _ -> False
27all :: Property
70all :: Property
29− forAll (listOf $ chooseInt (0, 10000)) $ \ls ->
72+ forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
30− case S.parseD (D.all (> 5000)) (S.fromList ls) of
73+ case S.parseD (D.all (> mid_value)) (S.fromList ls) of
31− Right r -> r == (Prelude.all (> 5000) ls)
74+ Right r -> r == (Prelude.all (> mid_value) ls)
32 Left _ -> False
75 Left _ -> False
34yield :: Property
77yield :: Property
36− forAll (chooseInt (0, 10000)) $ \x ->
79+ forAll (chooseInt (min_value, max_value)) $ \x ->
37 case S.parseD (D.yield x) (S.fromList [1 :: Int]) of
80 case S.parseD (D.yield x) (S.fromList [1 :: Int]) of
38 Right r -> r == x
81 Right r -> r == x
39 Left _ -> False
82 Left _ -> False
41yieldM :: Property
84yieldM :: Property
43− forAll (chooseInt (0, 10000)) $ \x ->
86+ forAll (chooseInt (min_value, max_value)) $ \x ->
44 case S.parseD (D.yieldM $ return x) (S.fromList [1 :: Int]) of
87 case S.parseD (D.yieldM $ return x) (S.fromList [1 :: Int]) of
45 Right r -> r == x
88 Right r -> r == x
46 Left _ -> False
89 Left _ -> False
@@ -61,35 +104,51 @@ dieM =
62-- Element Parser Tests
105-- Element Parser Tests
64−peek :: Property
107+peekPass :: Property
66− forAll (chooseInt (1, 100)) $ \list_length ->
109+ forAll (chooseInt (1, max_length)) $ \list_length ->
67− forAll (vectorOf list_length (chooseInt (0, 10000))) $ \ls ->
110+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
68 case S.parseD D.peek (S.fromList ls) of
111 case S.parseD D.peek (S.fromList ls) of
69 Right head_value -> case ls of
112 Right head_value -> case ls of
70 head_ls : _ -> head_value == head_ls
113 head_ls : _ -> head_value == head_ls
71 _ -> False
114 _ -> False
72 Left _ -> False
115 Left _ -> False
74 property (case S.parseD D.peek (S.fromList []) of
119 property (case S.parseD D.peek (S.fromList []) of
75 Right _ -> False
120 Right _ -> False
76 Left _ -> True)
121 Left _ -> True)
78−eof :: Property
123+eofPass :: Property
80− forAll (chooseInt (1, 100)) $ \list_length ->
81− forAll (vectorOf list_length (chooseInt (0, 10000))) $ \ls ->
82− case S.parseD D.eof (S.fromList ls) of
86 property (case S.parseD D.eof (S.fromList []) of
125 property (case S.parseD D.eof (S.fromList []) of
87 Right _ -> True
126 Right _ -> True
88 Left _ -> False)
127 Left _ -> False)
131+ forAll (chooseInt (1, max_length)) $ \list_length ->
132+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
133+ case S.parseD D.eof (S.fromList ls) of
137+satisfyPass :: Property
139+ forAll (chooseInt (mid_value, max_value)) $ \first_element ->
140+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls_tail ->
142+ ls = first_element : ls_tail
143+ predicate = (>= mid_value)
145+ case S.parseD (D.satisfy predicate) (S.fromList ls) of
146+ Right r -> r == first_element
90satisfy :: Property
149satisfy :: Property
92− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
151+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
93 case S.parseD (D.satisfy predicate) (S.fromList ls) of
152 case S.parseD (D.satisfy predicate) (S.fromList ls) of
94 Right r -> case ls of
153 Right r -> case ls of
95 [] -> False
154 [] -> False
@@ -98,43 +157,101 @@ satisfy =
98 [] -> True
157 [] -> True
99 (x : _) -> not $ predicate x
158 (x : _) -> not $ predicate x
101− predicate = (>= 5000)
160+ predicate = (>= mid_value)
103-- Sequence Parsers Tests
162-- Sequence Parsers Tests
105take :: Property
164take :: Property
107− forAll (chooseInt (0, 10000)) $ \n ->
166+ forAll (chooseInt (min_value, max_value)) $ \n ->
108− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
167+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
109 case S.parseD (D.take n FL.toList) (S.fromList ls) of
168 case S.parseD (D.take n FL.toList) (S.fromList ls) of
169+ Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
170+ Left _ -> property False
172+takeEQPass :: Property
174+ forAll (chooseInt (min_value, max_value)) $ \n ->
175+ forAll (chooseInt (n, max_value)) $ \list_length ->
176+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
177+ case S.parseD (D.takeEQ n FL.toList) (S.fromList ls) of
110− Right parsed_list -> parsed_list == Prelude.take n ls
178+ Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
111− Left _ -> False
179+ Left _ -> property False
113takeEQ :: Property
181takeEQ :: Property
115− forAll (chooseInt (0, 10000)) $ \n ->
183+ forAll (chooseInt (min_value, max_value)) $ \n ->
116− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
184+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
118 list_length = Prelude.length ls
186 list_length = Prelude.length ls
120 case S.parseD (D.takeEQ n FL.toList) (S.fromList ls) of
188 case S.parseD (D.takeEQ n FL.toList) (S.fromList ls) of
189+ Right parsed_list ->
190+ if (n <= list_length) then
121− Right parsed_list -> (n <= list_length) && (parsed_list == Prelude.take n ls)
191+ checkListEqual parsed_list (Prelude.take n ls)
122− Left _ -> n > list_length
194+ Left _ -> property (n > list_length)
196+takeGEPass :: Property
198+ forAll (chooseInt (min_value, max_value)) $ \n ->
199+ forAll (chooseInt (n, max_value)) $ \list_length ->
200+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
201+ case S.parseD (D.takeGE n FL.toList) (S.fromList ls) of
202+ Right parsed_list -> checkListEqual parsed_list ls
203+ Left _ -> property False
124takeGE :: Property
205takeGE :: Property
126− forAll (chooseInt (0, 10000)) $ \n ->
207+ forAll (chooseInt (min_value, max_value)) $ \n ->
127− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
208+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
129 list_length = Prelude.length ls
210 list_length = Prelude.length ls
131 case S.parseD (D.takeGE n FL.toList) (S.fromList ls) of
212 case S.parseD (D.takeGE n FL.toList) (S.fromList ls) of
132− Right parsed_list -> (n <= list_length) && (parsed_list == ls)
213+ Right parsed_list ->
214+ if (n <= list_length) then
215+ checkListEqual parsed_list ls
218+ Left _ -> property (n > list_length)
220+lookAheadPass :: Property
222+ forAll (chooseInt (min_value + 1, max_value)) $ \n ->
224+ takeWithoutConsume = D.lookAhead $ D.take n FL.toList
226+ parsed_list_1 <- takeWithoutConsume
227+ parsed_list_2 <- takeWithoutConsume
228+ return (parsed_list_1, parsed_list_2)
230+ forAll (chooseInt (n, max_value)) $ \list_length ->
231+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
232+ 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)
234+ 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)
133− Left _ -> n > list_length
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
135lookAhead :: Property
252lookAhead :: Property
136lookAhead =
253lookAhead =
137− forAll (chooseInt (0, 10000)) $ \n ->
254+ forAll (chooseInt (min_value, max_value)) $ \n ->
139 takeWithoutConsume = D.lookAhead $ D.take n FL.toList
256 takeWithoutConsume = D.lookAhead $ D.take n FL.toList
140 parseTwice = do
257 parseTwice = do
@@ -142,19 +259,19 @@ lookAhead =
142 parsed_list_2 <- takeWithoutConsume
259 parsed_list_2 <- takeWithoutConsume
143 return (parsed_list_1, parsed_list_2)
260 return (parsed_list_1, parsed_list_2)
145− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
262+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
146 case S.parseD parseTwice (S.fromList ls) of
263 case S.parseD parseTwice (S.fromList ls) of
147− Right (ls_1, ls_2) -> (ls_1 == ls_2) && (ls_1 == Prelude.take n ls)
264+ Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
148− Left _ -> (list_length < n) || (list_length == n && n == 0)
265+ Left _ -> property ((list_length < n) || (list_length == n && n == 0))
150 list_length = Prelude.length ls
267 list_length = Prelude.length ls
152takeWhile :: Property
269takeWhile :: Property
153takeWhile =
270takeWhile =
154 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
271 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
155− case S.parseD (D.takeWhile predicate FL.toList) (S.fromList ls) of
272+ case S.parseD (D.takeWhile predicate FL.toList) (S.fromList ls) of
156− Right parsed_list -> parsed_list == Prelude.takeWhile predicate ls
273+ Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile predicate ls)
157− Left _ -> False
274+ Left _ -> property False
159 predicate = (== 0)
276 predicate = (== 0)
@@ -163,11 +280,15 @@ takeWhile1 =
163 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
280 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
164 case S.parseD (D.takeWhile1 predicate FL.toList) (S.fromList ls) of
281 case S.parseD (D.takeWhile1 predicate FL.toList) (S.fromList ls) of
165 Right parsed_list -> case ls of
282 Right parsed_list -> case ls of
166− [] -> False
283+ [] -> property False
167− (x : _) -> predicate x && (parsed_list == Prelude.takeWhile predicate ls)
286+ checkListEqual parsed_list (Prelude.takeWhile predicate ls)
168 Left _ -> case ls of
289 Left _ -> case ls of
169− [] -> True
290+ [] -> property True
170− (x : _) -> not $ predicate x
291+ (x : _) -> property (not $ predicate x)
172 predicate = (== 0)
293 predicate = (== 0)
@@ -175,20 +296,20 @@ sliceSepBy :: Property
175sliceSepBy =
296sliceSepBy =
176 forAll (listOf (chooseInt (0, 1))) $ \ls ->
297 forAll (listOf (chooseInt (0, 1))) $ \ls ->
177 case S.parseD (D.sliceSepBy predicate FL.toList) (S.fromList ls) of
298 case S.parseD (D.sliceSepBy predicate FL.toList) (S.fromList ls) of
178− Right parsed_list -> parsed_list == Prelude.takeWhile (not . predicate) ls
299+ Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile (not . predicate) ls)
179− Left _ -> False
300+ Left _ -> property False
181 predicate = (== 1)
302 predicate = (== 1)
183−-- sliceSepByMax :: Property
304+sliceSepByMax :: Property
184−-- sliceSepByMax =
305+sliceSepByMax =
185−-- forAll (chooseInt (0, 10000)) $ \n ->
306+ forAll (chooseInt (min_value, max_value)) $ \n ->
186−-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
307+ forAll (listOf (chooseInt (0, 1))) $ \ls ->
187−-- case S.parseD (D.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
308+ case S.parseD (D.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
188−-- Right parsed_list -> parsed_list == Prelude.take n (Prelude.takeWhile (not . predicate) ls)
309+ Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
189−-- Left _ -> False
310+ Left _ -> property False
191−-- predicate = (== 1)
312+ predicate = (== 1)
193splitWith :: Property
314splitWith :: Property
194splitWith =
315splitWith =
@@ -200,86 +321,112 @@ splitWith =
200 Left _ -> case ls of
321 Left _ -> case ls of
201 0 : 1 : _ -> False
322 0 : 1 : _ -> False
202 _ -> True
323 _ -> True
325+splitWithFailLeft :: Property
204 property (case S.parseD (D.splitWith (,) (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
327 property (case S.parseD (D.splitWith (,) (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
205 Right _ -> False
328 Right _ -> False
206 Left _ -> True)
329 Left _ -> True)
331+splitWithFailRight :: Property
208 property (case S.parseD (D.splitWith (,) (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
333 property (case S.parseD (D.splitWith (,) (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
209 Right _ -> False
334 Right _ -> False
210 Left _ -> True)
335 Left _ -> True)
337+splitWithFailBoth :: Property
212 property (case S.parseD (D.splitWith (,) (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
339 property (case S.parseD (D.splitWith (,) (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
213 Right _ -> False
340 Right _ -> False
214 Left _ -> True)
341 Left _ -> True)
216−teeWith :: Property
343+teeWithPass :: Property
217−teeWith =
344+teeWithPass =
218− forAll (chooseInt (0, 10000)) $ \n ->
345+ forAll (chooseInt (min_value, max_value)) $ \n ->
219 forAll (listOf (chooseInt (0, 1))) $ \ls ->
346 forAll (listOf (chooseInt (0, 1))) $ \ls ->
221 prsr = D.take n FL.toList
348 prsr = D.take n FL.toList
223 case S.parseD (D.teeWith (,) prsr prsr) (S.fromList ls) of
350 case S.parseD (D.teeWith (,) prsr prsr) (S.fromList ls) of
224− Right (ls_1, ls_2) -> (Prelude.take n ls == ls_1) && (ls_1 == ls_2)
351+ Right (ls_1, ls_2) -> checkListEqual (Prelude.take n ls) ls_1 .&&. checkListEqual ls_1 ls_2
225− Left _ -> False
352+ Left _ -> property False
354+teeWithFailLeft :: Property
227 property (case S.parseD (D.teeWith (,) (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
356 property (case S.parseD (D.teeWith (,) (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
228 Right _ -> False
357 Right _ -> False
229 Left _ -> True)
358 Left _ -> True)
360+teeWithFailRight :: Property
231 property (case S.parseD (D.teeWith (,) (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
362 property (case S.parseD (D.teeWith (,) (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
232 Right _ -> False
363 Right _ -> False
233 Left _ -> True)
364 Left _ -> True)
366+teeWithFailBoth :: Property
235 property (case S.parseD (D.teeWith (,) (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
368 property (case S.parseD (D.teeWith (,) (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
236 Right _ -> False
369 Right _ -> False
237 Left _ -> True)
370 Left _ -> True)
239−shortest :: Property
372+shortestPass :: Property
240−shortest =
373+shortestPass =
241− forAll (listOf (chooseInt(0, 10000))) $ \ls ->
374+ forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
376+ half_mid_value = mid_value `Prelude.div` 2
243− prsr_1 = D.takeWhile (<= 2500) FL.toList
377+ prsr_1 = D.takeWhile (<= half_mid_value) FL.toList
244− prsr_2 = D.takeWhile (<= 5000) FL.toList
378+ prsr_2 = D.takeWhile (<= mid_value) FL.toList
245 prsr_shortest = D.shortest prsr_1 prsr_2
379 prsr_shortest = D.shortest prsr_1 prsr_2
247 case S.parseD prsr_shortest (S.fromList ls) of
381 case S.parseD prsr_shortest (S.fromList ls) of
248− Right short_list -> short_list == Prelude.takeWhile (<= 2500) ls
382+ Right short_list -> checkListEqual short_list (Prelude.takeWhile (<= half_mid_value) ls)
249− Left _ -> False
383+ Left _ -> property False
385+shortestPassLeft :: Property
251 property (case S.parseD (D.shortest (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
387 property (case S.parseD (D.shortest (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
252 Right r -> r == 1
388 Right r -> r == 1
253 Left _ -> False)
389 Left _ -> False)
391+shortestPassRight :: Property
255 property (case S.parseD (D.shortest (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
393 property (case S.parseD (D.shortest (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
256 Right r -> r == 1
394 Right r -> r == 1
257 Left _ -> False)
395 Left _ -> False)
397+shortestFailBoth :: Property
259 property (case S.parseD (D.shortest (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
399 property (case S.parseD (D.shortest (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
260 Right _ -> False
400 Right _ -> False
261 Left _ -> True)
401 Left _ -> True)
263−longest :: Property
403+longestPass :: Property
264−longest =
404+longestPass =
265− forAll (listOf (chooseInt(0, 10000))) $ \ls ->
405+ forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
407+ half_mid_value = mid_value `Prelude.div` 2
267− prsr_1 = D.takeWhile (<= 2500) FL.toList
408+ prsr_1 = D.takeWhile (<= half_mid_value) FL.toList
268− prsr_2 = D.takeWhile (<= 5000) FL.toList
409+ prsr_2 = D.takeWhile (<= mid_value) FL.toList
269 prsr_longest = D.longest prsr_1 prsr_2
410 prsr_longest = D.longest prsr_1 prsr_2
271 case S.parseD prsr_longest (S.fromList ls) of
412 case S.parseD prsr_longest (S.fromList ls) of
272− Right long_list -> long_list == Prelude.takeWhile (<= 5000) ls
413+ Right long_list -> long_list == Prelude.takeWhile (<= mid_value) ls
273 Left _ -> False
414 Left _ -> False
416+longestPassLeft :: Property
275 property (case S.parseD (D.shortest (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
418 property (case S.parseD (D.shortest (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
276 Right r -> r == 1
419 Right r -> r == 1
277 Left _ -> False)
420 Left _ -> False)
422+longestPassRight :: Property
279 property (case S.parseD (D.shortest (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
424 property (case S.parseD (D.shortest (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
280 Right r -> r == 1
425 Right r -> r == 1
281 Left _ -> False)
426 Left _ -> False)
428+longestFailBoth :: Property
283 property (case S.parseD (D.shortest (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
430 property (case S.parseD (D.shortest (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
284 Right _ -> False
431 Right _ -> False
285 Left _ -> True)
432 Left _ -> True)
@@ -292,12 +439,14 @@ many =
292 prsr = D.many concatFold $ D.sliceSepBy (== 1) FL.toList
439 prsr = D.many concatFold $ D.sliceSepBy (== 1) FL.toList
294 case S.parseD prsr (S.fromList ls) of
441 case S.parseD prsr (S.fromList ls) of
295− Right res_list -> res_list == Prelude.filter (== 0) ls
442+ Right res_list -> checkListEqual res_list (Prelude.filter (== 0) ls)
296− Left _ -> False
443+ Left _ -> property False
445+many_empty :: Property
298 property (case S.parseD (D.many FL.toList (D.die "die")) (S.fromList [1 :: Int]) of
447 property (case S.parseD (D.many FL.toList (D.die "die")) (S.fromList [1 :: Int]) of
299− Right res_list -> res_list == ([] :: [Int])
448+ Right res_list -> checkListEqual res_list ([] :: [Int])
300− Left _ -> False)
449+ Left _ -> property False)
302-- some :: Property
451-- some :: Property
303-- some =
452-- some =
@@ -309,7 +458,9 @@ many =
309-- case S.parseD prsr (S.fromList ls) of
458-- case S.parseD prsr (S.fromList ls) of
310-- Right res_list -> res_list == Prelude.filter (== 0) ls
459-- Right res_list -> res_list == Prelude.filter (== 0) ls
311-- Left _ -> False
460-- Left _ -> False
462+-- someFail :: Property
313-- property (case S.parseD (D.some FL.toList (D.die "die")) (S.fromList [1 :: Int]) of
464-- property (case S.parseD (D.some FL.toList (D.die "die")) (S.fromList [1 :: Int]) of
314-- Right _ -> False
465-- Right _ -> False
315-- Left _ -> True)
466-- Left _ -> True)
@@ -317,31 +468,52 @@ many =
317main :: IO ()
468main :: IO ()
318main = hspec $ do
469main = hspec $ do
319 describe "test for accumulator" $ do
470 describe "test for accumulator" $ do
320− prop "test fromFold function" fromFold
471+ prop "D.fromFold FL.sum = FL.sum" fromFold
321− prop "test any function" Main.any
472+ prop "D.any = Prelude.any" Main.any
322− prop "test all function" Main.all
473+ prop "D.all = Prelude.all" Main.all
323− prop "test yield function" yield
474+ prop "yield value provided" yield
324− prop "test yieldM function" yieldM
475+ prop "yield monadic value provided" yieldM
325− prop "test die function" die
476+ prop "always fail" die
326− prop "test dieM function" dieM
477+ prop "always fail but monadic" dieM
328 describe "test for element parser" $ do
479 describe "test for element parser" $ do
329− prop "test for peek function" peek
480+ prop "peek = head with list length > 0" peekPass
330− prop "test for eof function" eof
481+ prop "peek fail on []" peekFail
331− prop "test for satisfy function" satisfy
482+ prop "eof pass on []" eofPass
483+ prop "eof fail on non-empty list" eofFail
484+ prop "first element exists and >= mid_value" satisfyPass
485+ prop "check first element exists and satisfies predicate" satisfy
333 describe "test for sequence parser" $ do
487 describe "test for sequence parser" $ do
334− prop "test for take function" Main.take
488+ prop "D.take = Prelude.take" Main.take
335− prop "test for takeEq function" Main.takeEQ
489+ prop "D.takeEQ = Prelude.take when len >= n" takeEQPass
336− prop "test for takeGE function" Main.takeGE
490+ prop "D.takeEQ = Prelude.take when len >= n and fail otherwise" Main.takeEQ
337− prop "test for LookAhead function" lookAhead
491+ prop "D.takeGE n ls = ls when len >= n" takeGEPass
338− prop "test for takeWhile function" Main.takeWhile
492+ prop "D.takeGE n ls = ls when len >= n and fail otherwise" Main.takeGE
339− prop "test for takeWhile1 function" takeWhile1
493+ prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n" lookAheadPass
340− prop "test for sliceSepBy function" sliceSepBy
494+ prop "Fail when stream length exceeded" lookAheadFail
341− -- prop "test for sliceSepByMax function" sliceSepByMax
495+ prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n, else fail" lookAhead
342− prop "test for splitWith function" splitWith
496+ prop "D.takeWhile = Prelude.takeWhile" Main.takeWhile
343− prop "test for teeWith function" teeWith
497+ prop "D.takeWhile = Prelude.takeWhile if taken something, else check why failed" takeWhile1
344− prop "test for shortest function" shortest
498+ prop "D.sliceSepBy = Prelude.takeWhile (not . predicate)" sliceSepBy
345− prop "test for longest function" longest
499+ prop "D.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
346− prop "test for many function" many
500+ prop "parse 0, then 1, else fail" splitWith
347− -- prop "test for some function" some
501+ prop "fail due to die as left parser" splitWithFailLeft
502+ prop "fail due to die as right parser" splitWithFailRight
503+ prop "fail due to die as both parsers" splitWithFailBoth
504+ prop "parsed two lists should be equal" teeWithPass
505+ prop "fail due to die as left parser" teeWithFailLeft
506+ prop "fail due to die as right parser" teeWithFailRight
507+ prop "fail due to die as both parsers" teeWithFailBoth
508+ prop "D.takeWhile (<= half_mid_value) = Prelude.takeWhile half_mid_value" shortestPass
509+ prop "pass even if die is left parser" shortestPassLeft
510+ prop "pass even if die is right parser" shortestPassRight
511+ prop "fail due to die as both parsers" shortestFailBoth
512+ prop "D.takeWhile (<= mid_value) = Prelude.takeWhile (<= mid_value)" longestPass
513+ prop "pass even if die is left parser" longestPassLeft
514+ prop "pass even if die is right parser" longestPassRight
515+ prop "fail due to die as both parsers" longestFailBoth
516+ prop "D.many concatFold $ D.sliceSepBy (== 1) FL.toList = Prelude.filter (== 0)" many
517+ prop "[] due to parser being die" many_empty
519+ -- prop "fail due to parser being die" someFail