@@ -3,8 +3,8 @@ module Main (main) where
3import Control.Applicative ((<|>))
3import Control.Applicative ((<|>))
4import Control.Exception (SomeException(..), try)
4import Control.Exception (SomeException(..), try)
5import Data.Word (Word8, Word32, Word64)
5import Data.Word (Word8, Word32, Word64)
6−import Streamly.Test.Common (listEquals, checkListEqual, chooseInt, equals)
6+import Streamly.Test.Common (listEquals, checkListEqual, chooseInt)
7−import Test.Hspec (Spec, hspec, describe, Expectation, it, shouldReturn)
7+import Test.Hspec (Spec, hspec, describe)
8import Test.Hspec.QuickCheck
8import Test.Hspec.QuickCheck
9import Test.QuickCheck
9import Test.QuickCheck
10 (arbitrary, forAll, elements, Property,
10 (arbitrary, forAll, elements, Property,
@@ -28,7 +28,7 @@ import Prelude hiding (sequence)
28#if MIN_VERSION_QuickCheck(2,14,0)
28#if MIN_VERSION_QuickCheck(2,14,0)
30import Test.QuickCheck (chooseAny)
30import Test.QuickCheck (chooseAny)
31−
31+import Control.Monad.Identity (runIdentity, Identity (Identity))
@@ -65,7 +65,7 @@ fromFold :: Property
66 forAll (listOf $ chooseInt (min_value, max_value))
66 forAll (listOf $ chooseInt (min_value, max_value))
68− case (==) <$> (S.parseD (P.fromFold FL.sum) (S.fromList ls))
68+ case (==) <$> runIdentity (S.parseD (P.fromFold FL.sum) (S.fromList ls))
69 <*> (S.fold FL.sum (S.fromList ls)) of
69 <*> (S.fold FL.sum (S.fromList ls)) of
70 Right is_equal -> is_equal
70 Right is_equal -> is_equal
71 Left _ -> False
71 Left _ -> False
@@ -73,28 +73,28 @@ fromFold =
73fromPure :: Property
73fromPure :: Property
75 forAll (chooseInt (min_value, max_value)) $ \x ->
75 forAll (chooseInt (min_value, max_value)) $ \x ->
76− case S.parseD (P.fromPure x) (S.fromList [1 :: Int]) of
76+ case runIdentity $ S.parseD (P.fromPure x) (S.fromList [1 :: Int]) of
77 Right r -> r == x
77 Right r -> r == x
78 Left _ -> False
78 Left _ -> False
80fromEffect :: Property
80fromEffect :: Property
81fromEffect =
81fromEffect =
82 forAll (chooseInt (min_value, max_value)) $ \x ->
82 forAll (chooseInt (min_value, max_value)) $ \x ->
83− case S.parseD (P.fromEffect $ return x) (S.fromList [1 :: Int]) of
83+ case runIdentity $ S.parseD (P.fromEffect $ return x) (S.fromList [1 :: Int]) of
84 Right r -> r == x
84 Right r -> r == x
85 Left _ -> False
85 Left _ -> False
87die :: Property
87die :: Property
89 property $
89 property $
90− case S.parseD (P.die "die test") (S.fromList [0 :: Int]) of
90+ case runIdentity (S.parseD (P.die "die test") (S.fromList [0 :: Int])) of
91 Right _ -> False
91 Right _ -> False
92 Left _ -> True
92 Left _ -> True
94dieM :: Property
94dieM :: Property
96 property $
96 property $
97− case S.parseD (P.dieM (Right "die test")) (S.fromList [0 :: Int]) of
97+ case runIdentity (S.parseD (P.dieM (Identity "die test")) (S.fromList [0 :: Int])) of
98 Right _ -> False
98 Right _ -> False
99 Left _ -> True
99 Left _ -> True
@@ -104,7 +104,7 @@ peekPass :: Property
104peekPass =
104peekPass =
105 forAll (chooseInt (1, max_length)) $ \list_length ->
105 forAll (chooseInt (1, max_length)) $ \list_length ->
106 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
106 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
107− case S.parseD P.peek (S.fromList ls) of
107+ case runIdentity $ S.parseD P.peek (S.fromList ls) of
108 Right head_value -> case ls of
108 Right head_value -> case ls of
109 head_ls : _ -> head_value == head_ls
109 head_ls : _ -> head_value == head_ls
110 _ -> False
110 _ -> False
@@ -112,7 +112,7 @@ peekPass =
113peekFail :: Property
113peekFail :: Property
114peekFail =
114peekFail =
115− property (case S.parseD P.peek (S.fromList []) of
115+ property (case runIdentity $ S.parseD P.peek (S.fromList []) of
116 Right _ -> False
116 Right _ -> False
117 Left _ -> True)
117 Left _ -> True)
@@ -126,7 +126,7 @@ eofFail :: Property
127 forAll (chooseInt (1, max_length)) $ \list_length ->
127 forAll (chooseInt (1, max_length)) $ \list_length ->
128 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
128 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
129− case S.parseD P.eof (S.fromList ls) of
129+ case runIdentity $S.parseD P.eof (S.fromList ls) of
130 Right _ -> False
130 Right _ -> False
131 Left _ -> True
131 Left _ -> True
@@ -138,14 +138,14 @@ satisfyPass =
138 ls = first_element : ls_tail
138 ls = first_element : ls_tail
139 predicate = (>= mid_value)
139 predicate = (>= mid_value)
141− case S.parseD (P.satisfy predicate) (S.fromList ls) of
141+ case runIdentity $ S.parseD (P.satisfy predicate) (S.fromList ls) of
142 Right r -> r == first_element
142 Right r -> r == first_element
143 Left _ -> False
143 Left _ -> False
145satisfy :: Property
145satisfy :: Property
147 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
147 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
148− case S.parseD (P.satisfy predicate) (S.fromList ls) of
148+ case runIdentity $ S.parseD (P.satisfy predicate) (S.fromList ls) of
149 Right r -> case ls of
149 Right r -> case ls of
150 [] -> False
150 [] -> False
151 (x : _) -> predicate x && (r == x)
151 (x : _) -> predicate x && (r == x)
@@ -162,7 +162,7 @@ takeBetweenPass =
162 forAll (chooseInt (m, max_value)) $ \n ->
162 forAll (chooseInt (m, max_value)) $ \n ->
163 forAll (chooseInt (m, max_value)) $ \list_length ->
163 forAll (chooseInt (m, max_value)) $ \list_length ->
164 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
164 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
165− case S.parseD (P.takeBetween m n FL.toList) (S.fromList ls) of
165+ case runIdentity $ S.parseD (P.takeBetween m n FL.toList) (S.fromList ls) of
166 Right parsed_list ->
166 Right parsed_list ->
167 let lpl = Prelude.length parsed_list
167 let lpl = Prelude.length parsed_list
168 in checkListEqual parsed_list (Prelude.take lpl ls)
168 in checkListEqual parsed_list (Prelude.take lpl ls)
@@ -180,13 +180,16 @@ takeBetween =
180 let p = P.takeBetween m n FL.toList
180 let p = P.takeBetween m n FL.toList
181 r <- run $ try $ S.parseD p (S.fromList ls)
181 r <- run $ try $ S.parseD p (S.fromList ls)
182 return $ case r of
182 return $ case r of
183− Right parsed_list ->
183+ Right x -> case x of
184+ Right parsed_list ->
184− if m <= list_length && n >= m
185+ if m <= list_length && n >= m
186− let len = Prelude.length parsed_list
187+ let len = Prelude.length parsed_list
187− in checkListEqual
188+ in checkListEqual
188− parsed_list (Prelude.take len ls)
189+ parsed_list (Prelude.take len ls)
189− else property False
190+ else property False
192+ property (m > n || list_length < m)
190 Left (_ :: SomeException) ->
193 Left (_ :: SomeException) ->
191 property (m > n || list_length < m)
194 property (m > n || list_length < m)
@@ -194,7 +197,7 @@ take :: Property
195 forAll (chooseInt (min_value, max_value)) $ \n ->
198 forAll (chooseInt (min_value, max_value)) $ \n ->
196 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
199 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
197− case S.parseD (P.fromFold $ FL.take n FL.toList) (S.fromList ls) of
200+ case runIdentity $ S.parseD (P.fromFold $ FL.take n FL.toList) (S.fromList ls) of
198 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
201 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
199 Left _ -> property False
202 Left _ -> property False
@@ -203,7 +206,7 @@ takeEQPass =
203 forAll (chooseInt (min_value, max_value)) $ \n ->
206 forAll (chooseInt (min_value, max_value)) $ \n ->
204 forAll (chooseInt (n, max_value)) $ \list_length ->
207 forAll (chooseInt (n, max_value)) $ \list_length ->
205 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
208 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
206− case S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
209+ case runIdentity $ S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
207 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
210 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
208 Left _ -> property False
211 Left _ -> property False
@@ -214,7 +217,7 @@ takeEQ =
215 list_length = Prelude.length ls
218 list_length = Prelude.length ls
217− case S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
220+ case runIdentity $ S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
218 Right parsed_list ->
221 Right parsed_list ->
219 if (n <= list_length) then
222 if (n <= list_length) then
220 checkListEqual parsed_list (Prelude.take n ls)
223 checkListEqual parsed_list (Prelude.take n ls)
@@ -227,7 +230,7 @@ takeGEPass =
227 forAll (chooseInt (min_value, max_value)) $ \n ->
230 forAll (chooseInt (min_value, max_value)) $ \n ->
228 forAll (chooseInt (n, max_value)) $ \list_length ->
231 forAll (chooseInt (n, max_value)) $ \list_length ->
229 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
232 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
230− case S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
233+ case runIdentity $ S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
231 Right parsed_list -> checkListEqual parsed_list ls
234 Right parsed_list -> checkListEqual parsed_list ls
232 Left _ -> property False
235 Left _ -> property False
@@ -238,7 +241,7 @@ takeGE =
239 list_length = Prelude.length ls
242 list_length = Prelude.length ls
241− case S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
244+ case runIdentity $ S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
242 Right parsed_list ->
245 Right parsed_list ->
243 if (n <= list_length) then
246 if (n <= list_length) then
244 checkListEqual parsed_list ls
247 checkListEqual parsed_list ls
@@ -248,15 +251,15 @@ takeGE =
249nLessThanEqual0 ::
252nLessThanEqual0 ::
251− -> FL.Fold (Either SomeException) Int [Int]
254+ -> FL.Fold Identity Int [Int]
252− -> P.Parser Int (Either SomeException) [Int]
255+ -> P.Parser Int Identity [Int]
254 -> (Int -> [Int] -> [Int])
257 -> (Int -> [Int] -> [Int])
255 -> Property
258 -> Property
256nLessThanEqual0 tk ltk =
259nLessThanEqual0 tk ltk =
257 forAll (elements [0, (-1)]) $ \n ->
260 forAll (elements [0, (-1)]) $ \n ->
258 forAll (listOf arbitrary) $ \ls ->
261 forAll (listOf arbitrary) $ \ls ->
259− case S.parseD (tk n FL.toList) (S.fromList ls) of
262+ case runIdentity $ S.parseD (tk n FL.toList) (S.fromList ls) of
260 Right parsed_list -> checkListEqual parsed_list (ltk n ls)
263 Right parsed_list -> checkListEqual parsed_list (ltk n ls)
261 Left _ -> property False
264 Left _ -> property False
@@ -283,7 +286,7 @@ lookAheadPass =
284 forAll (chooseInt (n+1, max_value)) $ \list_length ->
287 forAll (chooseInt (n+1, max_value)) $ \list_length ->
285 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
288 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
286− case S.parseD parseTwice (S.fromList ls) of
289+ case runIdentity $ S.parseD parseTwice (S.fromList ls) of
287 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
290 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
288 Left _ -> property $ False
291 Left _ -> property $ False
@@ -298,7 +301,7 @@ lookAhead =
298 return (parsed_list_1, parsed_list_2)
301 return (parsed_list_1, parsed_list_2)
300 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
303 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
301− case S.parseD parseTwice (S.fromList ls) of
304+ case runIdentity $ S.parseD parseTwice (S.fromList ls) of
302 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
305 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
303 Left _ -> property ((list_length < n) || (list_length == n && n == 0))
306 Left _ -> property ((list_length < n) || (list_length == n && n == 0))
@@ -307,7 +310,7 @@ lookAhead =
307takeWhile :: Property
310takeWhile :: Property
308takeWhile =
311takeWhile =
309 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
312 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
310− case S.parseD (P.takeWhile predicate FL.toList) (S.fromList ls) of
313+ case runIdentity $ S.parseD (P.takeWhile predicate FL.toList) (S.fromList ls) of
311 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile predicate ls)
314 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile predicate ls)
312 Left _ -> property False
315 Left _ -> property False
@@ -316,7 +319,7 @@ takeWhile =
316takeWhile1 :: Property
319takeWhile1 :: Property
317takeWhile1 =
320takeWhile1 =
318 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
321 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
319− case S.parseD (P.takeWhile1 predicate FL.toList) (S.fromList ls) of
322+ case runIdentity $ S.parseD (P.takeWhile1 predicate FL.toList) (S.fromList ls) of
320 Right parsed_list -> case ls of
323 Right parsed_list -> case ls of
321 [] -> property False
324 [] -> property False
322 (x : _) ->
325 (x : _) ->
@@ -334,7 +337,7 @@ groupBy :: Property
335 forAll (listOf (chooseInt (0, 1)))
338 forAll (listOf (chooseInt (0, 1)))
337− case S.parseD parser (S.fromList ls) of
340+ case runIdentity $ S.parseD parser (S.fromList ls) of
338 Right parsed -> checkListEqual parsed (groupByLF ls)
341 Right parsed -> checkListEqual parsed (groupByLF ls)
339 Left _ -> property False
342 Left _ -> property False
@@ -350,7 +353,7 @@ groupByRolling :: Property
350groupByRolling =
353groupByRolling =
351 forAll (listOf (chooseInt (0, 1)))
354 forAll (listOf (chooseInt (0, 1)))
353− case S.parseD parser (S.fromList ls) of
356+ case runIdentity $ S.parseD parser (S.fromList ls) of
354 Right parsed -> checkListEqual parsed (groupByLF Nothing ls)
357 Right parsed -> checkListEqual parsed (groupByLF Nothing ls)
355 Left _ -> property False
358 Left _ -> property False
@@ -369,7 +372,7 @@ takeEndByOrMax :: Property
369takeEndByOrMax =
372takeEndByOrMax =
370 forAll (chooseInt (min_value, max_value)) $ \n ->
373 forAll (chooseInt (min_value, max_value)) $ \n ->
371 forAll (listOf (chooseInt (0, 1))) $ \ls ->
374 forAll (listOf (chooseInt (0, 1))) $ \ls ->
372− case S.parseD (P.fromFold $ FL.takeEndBy_ predicate (FL.take n FL.toList)) (S.fromList ls) of
375+ case runIdentity $ S.parseD (P.fromFold $ FL.takeEndBy_ predicate (FL.take n FL.toList)) (S.fromList ls) of
373 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
376 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
374 Left _ -> property False
377 Left _ -> property False
@@ -379,7 +382,7 @@ wordBy :: Property
380 forAll (listOf (elements [' ', 's']))
383 forAll (listOf (elements [' ', 's']))
382− case S.parseD parser (S.fromList ls) of
385+ case runIdentity $ S.parseD parser (S.fromList ls) of
383 Right parsed -> checkListEqual parsed (words' ls)
386 Right parsed -> checkListEqual parsed (words' ls)
384 Left _ -> property False
387 Left _ -> property False
@@ -395,7 +398,7 @@ wordBy =
395splitWith :: Property
398splitWith :: Property
396splitWith =
399splitWith =
397 forAll (listOf (chooseInt (0, 1))) $ \ls ->
400 forAll (listOf (chooseInt (0, 1))) $ \ls ->
398− case S.parseD (P.splitWith (,) (P.satisfy (== 0)) (P.satisfy (== 1))) (S.fromList ls) of
401+ case runIdentity $ S.parseD (P.splitWith (,) (P.satisfy (== 0)) (P.satisfy (== 1))) (S.fromList ls) of
399 Right (result_first, result_second) -> case ls of
402 Right (result_first, result_second) -> case ls of
400 0 : 1 : _ -> (result_first == 0) && (result_second == 1)
403 0 : 1 : _ -> (result_first == 0) && (result_second == 1)
401 _ -> False
404 _ -> False
@@ -405,19 +408,19 @@ splitWith =
406splitWithFailLeft :: Property
409splitWithFailLeft :: Property
407splitWithFailLeft =
410splitWithFailLeft =
408− property (case S.parseD (P.splitWith (,) (P.die "die") (P.fromPure (1 :: Int))) (S.fromList [1 :: Int]) of
411+ property (case runIdentity $ S.parseD (P.splitWith (,) (P.die "die") (P.fromPure (1 :: Int))) (S.fromList [1 :: Int]) of
409 Right _ -> False
412 Right _ -> False
410 Left _ -> True)
413 Left _ -> True)
412splitWithFailRight :: Property
415splitWithFailRight :: Property
413splitWithFailRight =
416splitWithFailRight =
414− property (case S.parseD (P.splitWith (,) (P.fromPure (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
417+ property (case runIdentity $ S.parseD (P.splitWith (,) (P.fromPure (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
415 Right _ -> False
418 Right _ -> False
416 Left _ -> True)
419 Left _ -> True)
418splitWithFailBoth :: Property
421splitWithFailBoth :: Property
419splitWithFailBoth =
422splitWithFailBoth =
420− property (case S.parseD (P.splitWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
423+ property (case runIdentity $ S.parseD (P.splitWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
421 Right _ -> False
424 Right _ -> False
422 Left _ -> True)
425 Left _ -> True)
@@ -528,14 +531,14 @@ many =
529 flip P.many concatFold
532 flip P.many concatFold
530 $ P.fromFold $ FL.takeEndBy_ (== 1) FL.toList
533 $ P.fromFold $ FL.takeEndBy_ (== 1) FL.toList
531− in case S.parseD prsr (S.fromList ls) of
534+ in case runIdentity $ S.parseD prsr (S.fromList ls) of
532 Right res_list ->
535 Right res_list ->
533 checkListEqual res_list (Prelude.filter (== 0) ls)
536 checkListEqual res_list (Prelude.filter (== 0) ls)
534 Left _ -> property False
537 Left _ -> property False
536many_empty :: Property
539many_empty :: Property
537many_empty =
540many_empty =
538− property (case S.parseD (flip P.many FL.toList (P.die "die")) (S.fromList [1 :: Int]) of
541+ property (case runIdentity $ S.parseD (flip P.many FL.toList (P.die "die")) (S.fromList [1 :: Int]) of
539 Right res_list -> checkListEqual res_list ([] :: [Int])
542 Right res_list -> checkListEqual res_list ([] :: [Int])
540 Left _ -> property False)
543 Left _ -> property False)
@@ -548,13 +551,13 @@ some =
549 flip P.some concatFold
552 flip P.some concatFold
550 $ P.fromFold $ FL.takeEndBy_ (== 1) FL.toList
553 $ P.fromFold $ FL.takeEndBy_ (== 1) FL.toList
551− in case S.parseD prsr (S.fromList ls) of
554+ in case runIdentity $ S.parseD prsr (S.fromList ls) of
552 Right res_list -> res_list == Prelude.filter (== 0) ls
555 Right res_list -> res_list == Prelude.filter (== 0) ls
553 Left _ -> False
556 Left _ -> False
555someFail :: Property
558someFail :: Property
556someFail =
559someFail =
557− property (case S.parseD (P.some (P.die "die") FL.toList) (S.fromList [1 :: Int]) of
560+ property (case runIdentity $ S.parseD (P.some (P.die "die") FL.toList) (S.fromList [1 :: Int]) of
558 Right _ -> False
561 Right _ -> False
559 Left _ -> True)
562 Left _ -> True)
@@ -566,54 +569,66 @@ applicative :: Property
566applicative =
569applicative =
567 forAll (listOf (chooseAny :: Gen Int)) $ \ list1 ->
570 forAll (listOf (chooseAny :: Gen Int)) $ \ list1 ->
568 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
571 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
569 let parser =
573 let parser =
571 <$> P.fromFold (FL.take (length list1) FL.toList)
575 <$> P.fromFold (FL.take (length list1) FL.toList)
572 <*> P.fromFold (FL.take (length list2) FL.toList)
576 <*> P.fromFold (FL.take (length list2) FL.toList)
573− in monadicIO $ do
577+
574− (olist1, olist2) <-
578+ return $
575− run $ S.parseD parser (S.fromList $ list1 ++ list2)
579+ case runIdentity $ S.parseD parser (S.fromList $ list1 ++ list2) of
576− listEquals (==) olist1 list1
580+ Right (olist1, olist2) -> olist1 == list1 && olist2 == list2
577− listEquals (==) olist2 list2
581+ Left _ -> False
579sequence :: Property
583sequence :: Property
580sequence =
584sequence =
581 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int))) $ \ ins ->
585 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int))) $ \ ins ->
582 let parsers = fmap (\xs -> P.fromFold $ FL.take (length xs) FL.toList) ins
587 let parsers = fmap (\xs -> P.fromFold $ FL.take (length xs) FL.toList) ins
585− S.parseD
588+ outs <- S.parseD
586− (Prelude.sequence parsers)
589+ (Prelude.sequence parsers)
587− (S.fromList $ concat ins)
590+ (S.fromList $ concat ins)
588− listEquals (==) outs ins
591+ return $
590−altEOF1 :: Expectation
596+altEOF1 :: Property
592− S.parseD
599+ s1 <- S.parseD
593 (P.satisfy (> 0) <|> return 66)
600 (P.satisfy (> 0) <|> return 66)
594 (S.fromList ([]::[Int]))
601 (S.fromList ([]::[Int]))
595− `shouldReturn` 66
602+ return $
597−altEOF2 :: Expectation
607+altEOF2 :: Property
599− S.parseD
610+ s1 <- S.parseD
600 ((P.takeEQ 2 FL.toList) <|> (P.takeEQ 1 FL.toList))
611 ((P.takeEQ 2 FL.toList) <|> (P.takeEQ 1 FL.toList))
601 (S.fromList ([51]::[Int]))
612 (S.fromList ([51]::[Int]))
602− `shouldReturn` [51]
613+ return $
615+ Right x -> x == [51]
604monad :: Property
618monad :: Property
606 forAll (listOf (chooseAny :: Gen Int)) $ \ list1 ->
620 forAll (listOf (chooseAny :: Gen Int)) $ \ list1 ->
607 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
621 forAll (listOf (chooseAny :: Gen Int)) $ \ list2 ->
608 let parser = do
623 let parser = do
609 olist1 <- P.fromFold (FL.take (length list1) FL.toList)
624 olist1 <- P.fromFold (FL.take (length list1) FL.toList)
610 olist2 <- P.fromFold (FL.take (length list2) FL.toList)
625 olist2 <- P.fromFold (FL.take (length list2) FL.toList)
611 return (olist1, olist2)
626 return (olist1, olist2)
614− run $ S.parseD parser (S.fromList $ list1 ++ list2)
627+ s1 <- S.parseD parser (S.fromList $ list1 ++ list2)
615− listEquals (==) olist1 list1
628+ return $
616− listEquals (==) olist2 list2
629+ case s1 of
630+ Right (olist1, olist2) -> olist1 == list1 && olist2 == list2
618-------------------------------------------------------------------------------
633-------------------------------------------------------------------------------
619-- Stream parsing
634-- Stream parsing
@@ -624,13 +639,11 @@ parseMany =
624 forAll (chooseInt (1,100)) $ \len ->
639 forAll (chooseInt (1,100)) $ \len ->
625 forAll (listOf (vectorOf len (chooseAny :: Gen Int))) $ \ ins ->
640 forAll (listOf (vectorOf len (chooseAny :: Gen Int))) $ \ ins ->
626 monadicIO $ do
641 monadicIO $ do
630− $ S.parseManyD
643+ (toList $ S.rights $ S.parseManyD
631− (P.fromFold $ FL.take len FL.toList) (S.fromList $ concat ins)
644+ (P.fromFold $ FL.take len FL.toList) (S.fromList $ concat ins)
633− listEquals (==) outs ins
646+ return $ outs == ins
635-- basic sanity test for parsing from arrays
648-- basic sanity test for parsing from arrays
636parseUnfold :: Property
649parseUnfold :: Property
@@ -664,13 +677,15 @@ parserSequence :: Property
664parserSequence =
677parserSequence =
665 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int))) $ \ins ->
678 forAll (vectorOf 11 (listOf (chooseAny :: Gen Int))) $ \ins ->
666 monadicIO $ do
679 monadicIO $ do
667− let parsers = D.fromList
680+ let parsers = D.fromList
668− $ fmap (\xs -> P.fromFold $ FL.take (length xs) FL.sum) ins
681+ $ fmap (\xs -> P.fromFold $ FL.take (length xs) FL.sum) ins
669− let sequencedParser = P.sequence parsers FL.sum
682+ let sequencedParser = P.sequence parsers FL.sum
672− S.parseD sequencedParser $ S.concatMap S.fromList (S.fromList ins)
684+ S.parseD sequencedParser $ S.concatMap S.fromList (S.fromList ins)
673− equals (==) outs (sum $ map sum ins)
687+ Right x -> x == sum (map sum ins)
675-------------------------------------------------------------------------------
690-------------------------------------------------------------------------------
676-- Test for a particular case hit during fs events testing
691-- Test for a particular case hit during fs events testing
@@ -722,6 +737,7 @@ parseMany2Events =
725 $ S.parseManyD readOneEvent
741 $ S.parseManyD readOneEvent
726 $ S.fromList (concat (replicate 2 event))
742 $ S.fromList (concat (replicate 2 event))
@@ -750,8 +766,8 @@ main =
751 describe "Instances" $ do
767 describe "Instances" $ do
752 prop "applicative" applicative
768 prop "applicative" applicative
753− it "Alternative: end of input 1" altEOF1
769+ prop "Alternative: end of input 1" altEOF1
754− it "Alternative: end of input 2" altEOF2
770+ prop "Alternative: end of input 2" altEOF2
755 prop "monad" monad
771 prop "monad" monad
756 prop "sequence" sequence
772 prop "sequence" sequence