1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module QC.Simple (
tests
) where
import Control.Applicative ((<|>))
import Data.ByteString (ByteString)
import Data.List (foldl')
import Data.Maybe (fromMaybe)
import QC.Rechunked (rechunkBS)
import Test.Tasty (TestTree)
import Test.Tasty.QuickCheck (testProperty)
import Test.QuickCheck (Property, counterexample, forAll)
import qualified Data.Attoparsec.ByteString.Char8 as A
t_issue75 = expect issue75 "ab" (A.Done "" "b")
issue75 :: A.Parser ByteString
issue75 = "a" >> ("b" <|> "")
expect :: (Show r, Eq r) => A.Parser r -> ByteString -> A.Result r -> Property
expect p input wanted =
forAll (rechunkBS input) $ \in' ->
let result = parse p in'
in counterexample (show result ++ " /= " ++ show wanted) $
fromMaybe False (A.compareResults result wanted)
parse :: A.Parser r -> [ByteString] -> A.Result r
parse p (x:xs) = foldl' A.feed (A.parse p x) xs
parse p [] = A.parse p ""
tests :: [TestTree]
tests = [
testProperty "issue75" t_issue75
]
|