on master help sign in
add lookAheadFail function to test failure case of lookAhead
commitf819fdd313b366baf22ab6e9d475ca7f4085bf60 authorAhmed Zaheer Dadarkar <ahmed.dadarkar@gmail.com> dateMon 8 Jun 2020, 18:20 (6 years ago) parent3fa6710
1 file changed+17
test/Streamly/Test/Internal/Data/Parser.hs+17
test/Streamly/Test/Internal/Data/Parser.hs+17
@@ -196,6 +196,22 @@ lookAheadPass =
196196 Right (ls_1, ls_2) -> (ls_1 == ls_2) && (ls_1 == Prelude.take n ls)
197197 Left _ -> False
198198
199+lookAheadFail :: Property
200+lookAheadFail =
201+ forAll (chooseInt (min_value + 1, max_value)) $ \n ->
202+ let
203+ takeWithoutConsume = P.lookAhead $ P.take n FL.toList
204+ parseTwice = do
205+ parsed_list_1 <- takeWithoutConsume
206+ parsed_list_2 <- takeWithoutConsume
207+ return (parsed_list_1, parsed_list_2)
208+ in
209+ forAll (chooseInt (min_value, n - 1)) $ \list_length ->
210+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
211+ case S.parse parseTwice (S.fromList ls) of
212+ Right _ -> False
213+ Left _ -> True
214+
199215lookAhead :: Property
200216lookAhead =
201217 forAll (chooseInt (min_value, max_value)) $ \n ->
@@ -380,6 +396,7 @@ main = hspec $ do
380396 prop "takeGE on list of length >= n" takeGEPass
381397 prop "takeGE on arbitrary sized list and n" Main.takeGE
382398 prop "parse stream twice without exceeding length of list, then check eq of lists" lookAheadPass
399+ prop "parse stream and exceed the length of stream while parsing" lookAheadFail
383400 prop "parse stream twice, then check eq of lists if not failed, else check why failed" lookAhead
384401 prop "compare takeWhile of parser and prelude on list and predicate" Main.takeWhile
385402 prop "compare with prelude.takeWhile if taken something, else check why failed" takeWhile1