mirror of
https://github.com/composewell/streamly.git
synced 2024-09-11 11:37:22 +03:00
Fix a ParserK to ParserD conversion bug
This commit is contained in:
parent
7fbc066e73
commit
b86d3be5a1
@ -725,10 +725,12 @@ adaptCG (ParserD.Parser step initial extract) =
|
||||
-- | A continuation to extract the result when a CPS parser is done.
|
||||
{-# INLINE parserDone #-}
|
||||
parserDone :: Monad m => ParseResult b -> Int -> Input a -> m (Step a m b)
|
||||
parserDone (Success n b) _ None = return $ Done (negate n) b
|
||||
parserDone (Success n b) _ (Chunk _) = return $ Done (1 - n) b
|
||||
parserDone (Failure n e) _ None = return $ Error (negate n) e
|
||||
parserDone (Failure n e) _ (Chunk _) = return $ Error (1 - n) e
|
||||
parserDone (Success n b) _ _ = do
|
||||
assertM(n <= 1)
|
||||
return $ Done n b
|
||||
parserDone (Failure n e) _ _ = do
|
||||
assertM(n <= 1)
|
||||
return $ Error n e
|
||||
|
||||
-- XXX Note that this works only for single element parsers and not for Array
|
||||
-- input parsers. The asserts will fail for array parsers.
|
||||
|
@ -797,19 +797,35 @@ toParser = do
|
||||
|
||||
-- NOTE: Without fusionBreaker this test would pass even if toParser has
|
||||
-- incorrect implementation because of fusion rules.
|
||||
let p2 =
|
||||
let p2 = Parser.takeWhile (<= 3) FL.toList
|
||||
runP2 xs = Stream.parseBreak p2 (Stream.fromList xs)
|
||||
|
||||
p3 = ParserK.adapt (Parser.takeWhile (<= 3) FL.toList)
|
||||
runP3 xs = StreamK.parseBreak p3 (StreamK.fromList xs)
|
||||
|
||||
p4 =
|
||||
ParserK.toParser
|
||||
$ fusionBreaker
|
||||
$ ParserK.adapt (Parser.takeWhile (<= 3) FL.toList)
|
||||
runP2 xs = Stream.parseBreak p2 (Stream.fromList xs)
|
||||
runP4 xs = Stream.parseBreak p4 (Stream.fromList xs)
|
||||
describe "toParser . adapt" $ do
|
||||
it "(<= 3) for [1, 2, 3, 4, 5]" $ do
|
||||
(a, b) <- runP2 ([1, 2, 3, 4, 5] :: [Int])
|
||||
fromRight undefined a `shouldBe` [1, 2, 3]
|
||||
rest <- Stream.toList b
|
||||
rest `shouldBe` [4, 5]
|
||||
it "(<= 3) for [1, 2, 3, 4, 5]" $ do
|
||||
(a, b) <- runP3 ([1, 2, 3, 4, 5] :: [Int])
|
||||
fromRight undefined a `shouldBe` [1, 2, 3]
|
||||
rest <- StreamK.toList b
|
||||
rest `shouldBe` [4, 5]
|
||||
it "(<= 3) for [1, 2, 3, 4, 5]" $ do
|
||||
(a, b) <- runP4 ([1, 2, 3, 4, 5] :: [Int])
|
||||
fromRight undefined a `shouldBe` [1,2,3]
|
||||
rest <- Stream.toList b
|
||||
rest `shouldBe` [4, 5]
|
||||
it "(<= 3) for [1, 2, 3]" $ do
|
||||
(a, b) <- runP2 ([1, 2, 3] :: [Int])
|
||||
(a, b) <- runP4 ([1, 2, 3] :: [Int])
|
||||
fromRight undefined a `shouldBe` [1, 2, 3]
|
||||
rest <- Stream.toList b
|
||||
rest `shouldBe` []
|
||||
|
Loading…
Reference in New Issue
Block a user