Add a test case for ParserK.toParser

This commit is contained in:
Adithya Kumar 2024-07-30 12:02:21 +05:30 committed by Harendra Kumar
parent f64ff6d5b9
commit 7fbc066e73

View File

@ -795,6 +795,29 @@ toParser = do
r3 <- runP1 [0,1::Int]
fromRight undefined r3 `shouldBe` 0
-- NOTE: Without fusionBreaker this test would pass even if toParser has
-- incorrect implementation because of fusion rules.
let p2 =
ParserK.toParser
$ fusionBreaker
$ ParserK.adapt (Parser.takeWhile (<= 3) FL.toList)
runP2 xs = Stream.parseBreak p2 (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]" $ do
(a, b) <- runP2 ([1, 2, 3] :: [Int])
fromRight undefined a `shouldBe` [1, 2, 3]
rest <- Stream.toList b
rest `shouldBe` []
{-# NOINLINE fusionBreaker #-}
fusionBreaker :: a -> a
fusionBreaker = id
-------------------------------------------------------------------------------
-- Main
-------------------------------------------------------------------------------