@@ -8,7 +8,7 @@ import qualified Streamly.Internal.Data.Fold as FL
9import Test.Hspec(hspec, describe)
9import Test.Hspec(hspec, describe)
10import Test.Hspec.QuickCheck
10import Test.Hspec.QuickCheck
11−import Test.QuickCheck (forAll, chooseInt, Property, property, listOf, vectorOf, (.&&.))
11+import Test.QuickCheck (forAll, chooseInt, Property, property, listOf, vectorOf)
13min_value :: Int
13min_value :: Int
14min_value = 0
14min_value = 0
@@ -91,17 +91,19 @@ peekFail =
91 Right _ -> False
91 Right _ -> False
92 Left _ -> True)
92 Left _ -> True)
96+ property (case S.parse P.eof (S.fromList []) of
94−eof :: Property
100+eofFail :: Property
96 forAll (chooseInt (1, max_length)) $ \list_length ->
102 forAll (chooseInt (1, max_length)) $ \list_length ->
97 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
103 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
98 case S.parse P.eof (S.fromList ls) of
104 case S.parse P.eof (S.fromList ls) of
99 Right _ -> False
105 Right _ -> False
100 Left _ -> True
106 Left _ -> True
102− property (case S.parse P.eof (S.fromList []) of
106satisfy :: Property
108satisfy :: Property
107satisfy =
109satisfy =
@@ -126,6 +128,15 @@ take =
126 Right parsed_list -> parsed_list == Prelude.take n ls
128 Right parsed_list -> parsed_list == Prelude.take n ls
127 Left _ -> False
129 Left _ -> False
131+takeEQPass :: Property
133+ forAll (chooseInt (min_value, max_value)) $ \n ->
134+ forAll (chooseInt (n, max_value)) $ \list_length ->
135+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
136+ case S.parse (P.takeEQ n FL.toList) (S.fromList ls) of
137+ Right parsed_list -> parsed_list == Prelude.take n ls
129takeEQ :: Property
140takeEQ :: Property
131 forAll (chooseInt (min_value, max_value)) $ \n ->
142 forAll (chooseInt (min_value, max_value)) $ \n ->
@@ -137,6 +148,15 @@ takeEQ =
137 Right parsed_list -> (n <= list_length) && (parsed_list == Prelude.take n ls)
148 Right parsed_list -> (n <= list_length) && (parsed_list == Prelude.take n ls)
138 Left _ -> n > list_length
149 Left _ -> n > list_length
151+takeGEPass :: Property
153+ forAll (chooseInt (min_value, max_value)) $ \n ->
154+ forAll (chooseInt (n, max_value)) $ \list_length ->
155+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
156+ case S.parse (P.takeGE n FL.toList) (S.fromList ls) of
157+ Right parsed_list -> parsed_list == ls
140takeGE :: Property
160takeGE :: Property
142 forAll (chooseInt (min_value, max_value)) $ \n ->
162 forAll (chooseInt (min_value, max_value)) $ \n ->
@@ -148,6 +168,22 @@ takeGE =
148 Right parsed_list -> (n <= list_length) && (parsed_list == ls)
168 Right parsed_list -> (n <= list_length) && (parsed_list == ls)
149 Left _ -> n > list_length
169 Left _ -> n > list_length
171+lookAheadPass :: Property
173+ forAll (chooseInt (min_value + 1, max_value)) $ \n ->
175+ takeWithoutConsume = P.lookAhead $ P.take n FL.toList
177+ parsed_list_1 <- takeWithoutConsume
178+ parsed_list_2 <- takeWithoutConsume
179+ return (parsed_list_1, parsed_list_2)
181+ forAll (chooseInt (n, max_value)) $ \list_length ->
182+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
183+ case S.parse parseTwice (S.fromList ls) of
184+ Right (ls_1, ls_2) -> (ls_1 == ls_2) && (ls_1 == Prelude.take n ls)
151lookAhead :: Property
187lookAhead :: Property
152lookAhead =
188lookAhead =
153 forAll (chooseInt (min_value, max_value)) $ \n ->
189 forAll (chooseInt (min_value, max_value)) $ \n ->
@@ -217,16 +253,20 @@ sliceSepBy =
217-- 0 : 1 : _ -> False
253-- 0 : 1 : _ -> False
218-- _ -> True
254-- _ -> True
220−-- splitWithFail :: Property
256+-- splitWithFailLeft :: Property
221−-- splitWithFail =
257+-- splitWithFailLeft =
222-- property (case S.parse (P.splitWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
258-- property (case S.parse (P.splitWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
223-- Right _ -> False
259-- Right _ -> False
224-- Left _ -> True)
260-- Left _ -> True)
262+-- splitWithFailRight :: Property
263+-- splitWithFailRight =
226-- property (case S.parse (P.splitWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
264-- property (case S.parse (P.splitWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
227-- Right _ -> False
265-- Right _ -> False
228-- Left _ -> True)
266-- Left _ -> True)
268+-- splitWithFailBoth :: Property
269+-- splitWithFailBoth =
230-- property (case S.parse (P.splitWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
270-- property (case S.parse (P.splitWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
231-- Right _ -> False
271-- Right _ -> False
232-- Left _ -> True)
272-- Left _ -> True)
@@ -242,16 +282,20 @@ sliceSepBy =
242-- Right (ls_1, ls_2) -> (Prelude.take n ls == ls_1) && (ls_1 == ls_2)
282-- Right (ls_1, ls_2) -> (Prelude.take n ls == ls_1) && (ls_1 == ls_2)
243-- Left _ -> False
283-- Left _ -> False
245−-- teeWithFail :: Property
285+-- teeWithFailLeft :: Property
246−-- teeWithFail =
286+-- teeWithFailLeft =
247-- property (case S.parse (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
287-- property (case S.parse (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
248-- Right _ -> False
288-- Right _ -> False
249-- Left _ -> True)
289-- Left _ -> True)
291+-- teeWithFailRight :: Property
292+-- teeWithFailRight =
251-- property (case S.parse (P.teeWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
293-- property (case S.parse (P.teeWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
252-- Right _ -> False
294-- Right _ -> False
253-- Left _ -> True)
295-- Left _ -> True)
297+-- teeWithFailBoth :: Property
255-- property (case S.parse (P.teeWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
299-- property (case S.parse (P.teeWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
256-- Right _ -> False
300-- Right _ -> False
257-- Left _ -> True)
301-- Left _ -> True)
@@ -280,16 +324,20 @@ sliceSepBy =
280-- Right short_list -> short_list == Prelude.takeWhile (<= 2500) ls
324-- Right short_list -> short_list == Prelude.takeWhile (<= 2500) ls
281-- Left _ -> False
325-- Left _ -> False
283−-- shortestFail :: Property
327+-- shortestFailLeft :: Property
284−-- shortestFail =
328+-- shortestFailLeft =
285-- property (case S.parse (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
329-- property (case S.parse (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
286-- Right r -> r == 1
330-- Right r -> r == 1
287-- Left _ -> False)
331-- Left _ -> False)
333+-- shortestFailRight :: Property
334+-- shortestFailRight =
289-- property (case S.parse (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
335-- property (case S.parse (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
290-- Right r -> r == 1
336-- Right r -> r == 1
291-- Left _ -> False)
337-- Left _ -> False)
339+-- shortestFailBoth :: Property
340+-- shortestFailBoth =
293-- property (case S.parse (P.shortest (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
341-- property (case S.parse (P.shortest (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
294-- Right _ -> False
342-- Right _ -> False
295-- Left _ -> True)
343-- Left _ -> True)
@@ -306,24 +354,34 @@ main = hspec $ do
306 prop "test dieM function" dieM
354 prop "test dieM function" dieM
308 describe "test for element parser" $ do
356 describe "test for element parser" $ do
309− prop "test for peek function" peekPass
357+ prop "pass test for peek function" peekPass
310− prop "test for peek function" peekFail
358+ prop "fail test for peek function" peekFail
311− prop "test for eof function" eof
359+ prop "pass test for eof function" eofPass
360+ prop "fail test for eof function" eofFail
312 prop "test for satisfy function" satisfy
361 prop "test for satisfy function" satisfy
314 describe "test for sequence parser" $ do
363 describe "test for sequence parser" $ do
315 prop "test for take function" Main.take
364 prop "test for take function" Main.take
365+ prop "pass test for takeEq function" takeEQPass
316 prop "test for takeEq function" Main.takeEQ
366 prop "test for takeEq function" Main.takeEQ
367+ prop "pass test for takeGE function" takeGEPass
317 prop "test for takeGE function" Main.takeGE
368 prop "test for takeGE function" Main.takeGE
369+ prop "pass test for LookAhead function" lookAheadPass
318 prop "test for LookAhead function" lookAhead
370 prop "test for LookAhead function" lookAhead
319 prop "test for takeWhile function" Main.takeWhile
371 prop "test for takeWhile function" Main.takeWhile
320 prop "test for takeWhile1 function" takeWhile1
372 prop "test for takeWhile1 function" takeWhile1
321 prop "test for sliceSepBy function" sliceSepBy
373 prop "test for sliceSepBy function" sliceSepBy
322 -- prop "test for sliceSepByMax function" sliceSepByMax
374 -- prop "test for sliceSepByMax function" sliceSepByMax
323− -- prop "test for splitWithPass function" splitWithPass
375+ -- prop "pass test for splitWith function" splitWithPass
324− -- prop "test for splitWithFail function" splitWithFail
376+ -- prop "left fail test for splitWith function" splitWithFailLeft
377+ -- prop "right fail test for splitWith function" splitWithFailRight
378+ -- prop "both fail test for splitWith function" splitWithFailBoth
325− -- prop "test for teeWithPass function" teeWithPass
379+ -- prop "pass test for teeWith function" teeWithPass
380+ -- prop "left fail test for teeWith function" teeWithFailLeft
381+ -- prop "right fail test for teeWith function" teeWithFailRight
326− -- prop "test for teeWithFail function" teeWithFail
382+ -- prop "both fail test for teeWith function" teeWithFailBoth
327 -- prop "test for deintercalate function" deintercalate
383 -- prop "test for deintercalate function" deintercalate
328− -- prop "test for shortestPass function" shortestPass
384+ -- prop "pass test for shortest function" shortestPass
385+ -- prop "left fail test for shortest function" shortestFailLeft
386+ -- prop "right fail test for shortest function" shortestFailRight
329− -- prop "test for shortestFail function" shortestFail
387+ -- prop "both fail test for shortest function" shortestFailBoth