@@ -8,7 +8,7 @@ import qualified Streamly.Internal.Data.Fold as FL
88
99import Test.Hspec(hspec, describe)
1010import Test.Hspec.QuickCheck
11−import Test.QuickCheck (forAll, chooseInt, Property, property, listOf, vectorOf, (.&&.))
11+import Test.QuickCheck (forAll, chooseInt, Property, property, listOf, vectorOf)
1212
1313min_value :: Int
1414min_value = 0
@@ -91,17 +91,19 @@ peekFail =
9191 Right _ -> False
9292 Left _ -> True)
9393
94−eof :: Property
95−eof =
94+eofPass :: Property
95+eofPass =
96+ property (case S.parse P.eof (S.fromList []) of
97+ Right _ -> True
98+ Left _ -> False)
99+
100+eofFail :: Property
101+eofFail =
96102 forAll (chooseInt (1, max_length)) $ \list_length ->
97103 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
98104 case S.parse P.eof (S.fromList ls) of
99105 Right _ -> False
100106 Left _ -> True
101− .&&.
102− property (case S.parse P.eof (S.fromList []) of
103− Right _ -> True
104− Left _ -> False)
105107
106108satisfy :: Property
107109satisfy =
@@ -126,6 +128,15 @@ take =
126128 Right parsed_list -> parsed_list == Prelude.take n ls
127129 Left _ -> False
128130
131+takeEQPass :: Property
132+takeEQPass =
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
138+ Left _ -> False
139+
129140takeEQ :: Property
130141takeEQ =
131142 forAll (chooseInt (min_value, max_value)) $ \n ->
@@ -137,6 +148,15 @@ takeEQ =
137148 Right parsed_list -> (n <= list_length) && (parsed_list == Prelude.take n ls)
138149 Left _ -> n > list_length
139150
151+takeGEPass :: Property
152+takeGEPass =
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
158+ Left _ -> False
159+
140160takeGE :: Property
141161takeGE =
142162 forAll (chooseInt (min_value, max_value)) $ \n ->
@@ -148,6 +168,22 @@ takeGE =
148168 Right parsed_list -> (n <= list_length) && (parsed_list == ls)
149169 Left _ -> n > list_length
150170
171+lookAheadPass :: Property
172+lookAheadPass =
173+ forAll (chooseInt (min_value + 1, max_value)) $ \n ->
174+ let
175+ takeWithoutConsume = P.lookAhead $ P.take n FL.toList
176+ parseTwice = do
177+ parsed_list_1 <- takeWithoutConsume
178+ parsed_list_2 <- takeWithoutConsume
179+ return (parsed_list_1, parsed_list_2)
180+ in
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)
185+ Left _ -> False
186+
151187lookAhead :: Property
152188lookAhead =
153189 forAll (chooseInt (min_value, max_value)) $ \n ->
@@ -217,16 +253,20 @@ sliceSepBy =
217253-- 0 : 1 : _ -> False
218254-- _ -> True
219255
220−-- splitWithFail :: Property
221−-- splitWithFail =
256+-- splitWithFailLeft :: Property
257+-- splitWithFailLeft =
222258-- property (case S.parse (P.splitWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
223259-- Right _ -> False
224260-- Left _ -> True)
225−-- .&&.
261+
262+-- splitWithFailRight :: Property
263+-- splitWithFailRight =
226264-- property (case S.parse (P.splitWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
227265-- Right _ -> False
228266-- Left _ -> True)
229−-- .&&.
267+
268+-- splitWithFailBoth :: Property
269+-- splitWithFailBoth =
230270-- property (case S.parse (P.splitWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
231271-- Right _ -> False
232272-- Left _ -> True)
@@ -242,16 +282,20 @@ sliceSepBy =
242282-- Right (ls_1, ls_2) -> (Prelude.take n ls == ls_1) && (ls_1 == ls_2)
243283-- Left _ -> False
244284
245−-- teeWithFail :: Property
246−-- teeWithFail =
285+-- teeWithFailLeft :: Property
286+-- teeWithFailLeft =
247287-- property (case S.parse (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
248288-- Right _ -> False
249289-- Left _ -> True)
250−-- .&&.
290+
291+-- teeWithFailRight :: Property
292+-- teeWithFailRight =
251293-- property (case S.parse (P.teeWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
252294-- Right _ -> False
253295-- Left _ -> True)
254−-- .&&.
296+
297+-- teeWithFailBoth :: Property
298+-- teeWithFailBoth =
255299-- property (case S.parse (P.teeWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
256300-- Right _ -> False
257301-- Left _ -> True)
@@ -280,16 +324,20 @@ sliceSepBy =
280324-- Right short_list -> short_list == Prelude.takeWhile (<= 2500) ls
281325-- Left _ -> False
282326
283−-- shortestFail :: Property
284−-- shortestFail =
327+-- shortestFailLeft :: Property
328+-- shortestFailLeft =
285329-- property (case S.parse (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
286330-- Right r -> r == 1
287331-- Left _ -> False)
288−-- .&&.
332+
333+-- shortestFailRight :: Property
334+-- shortestFailRight =
289335-- property (case S.parse (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
290336-- Right r -> r == 1
291337-- Left _ -> False)
292−-- .&&.
338+
339+-- shortestFailBoth :: Property
340+-- shortestFailBoth =
293341-- property (case S.parse (P.shortest (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
294342-- Right _ -> False
295343-- Left _ -> True)
@@ -306,24 +354,34 @@ main = hspec $ do
306354 prop "test dieM function" dieM
307355
308356 describe "test for element parser" $ do
309− prop "test for peek function" peekPass
310− prop "test for peek function" peekFail
311− prop "test for eof function" eof
357+ prop "pass test for peek function" peekPass
358+ prop "fail test for peek function" peekFail
359+ prop "pass test for eof function" eofPass
360+ prop "fail test for eof function" eofFail
312361 prop "test for satisfy function" satisfy
313362
314363 describe "test for sequence parser" $ do
315364 prop "test for take function" Main.take
365+ prop "pass test for takeEq function" takeEQPass
316366 prop "test for takeEq function" Main.takeEQ
367+ prop "pass test for takeGE function" takeGEPass
317368 prop "test for takeGE function" Main.takeGE
369+ prop "pass test for LookAhead function" lookAheadPass
318370 prop "test for LookAhead function" lookAhead
319371 prop "test for takeWhile function" Main.takeWhile
320372 prop "test for takeWhile1 function" takeWhile1
321373 prop "test for sliceSepBy function" sliceSepBy
322374 -- prop "test for sliceSepByMax function" sliceSepByMax
323− -- prop "test for splitWithPass function" splitWithPass
324− -- prop "test for splitWithFail function" splitWithFail
325− -- prop "test for teeWithPass function" teeWithPass
326− -- prop "test for teeWithFail function" teeWithFail
375+ -- prop "pass test for splitWith function" splitWithPass
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
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
382+ -- prop "both fail test for teeWith function" teeWithFailBoth
327383 -- prop "test for deintercalate function" deintercalate
328− -- prop "test for shortestPass function" shortestPass
329− -- prop "test for shortestFail function" shortestFail
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
387+ -- prop "both fail test for shortest function" shortestFailBoth