X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=test%2FTest.hs;h=7832f760e963c35a665ca43f7bedc0ee707f5e23;hb=4989a35706a2193bd5e0e2e98135d6aecd76cea1;hp=53dca6a098fdddd850098bc96c4523c7e0dd7d0d;hpb=1b4f53266cadfbd54f8198908424b4890fb1755f;p=github%2Ffretlink%2Ftext-pipes.git diff --git a/test/Test.hs b/test/Test.hs index 53dca6a..7832f76 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -23,16 +23,16 @@ import qualified Pipes.Text.Internal as PE import qualified Pipes.Text as TP import qualified Pipes.ByteString as BP import qualified Pipes as P -import Debug.Trace main :: IO () main = defaultMain [tests] -- >>> :main -a 10000 - tests = testGroup "stream_decode" [ -- testProperty "t_utf8_incr_valid" t_utf8_incr_valid, --- testProperty "t_utf8_incr_mixed" t_utf8_incr_mixed ] -- , - testProperty "t_utf8_incr_pipe" t_utf8_incr_pipe] + testProperty "t_utf8_incr_mixed" t_utf8_incr_mixed , + testProperty "t_utf8_incr_pipe" t_utf8_incr_pipe, + testProperty "t_utf8_incr_decoding" t_utf8_incr_decoding, + testProperty "t_utf8_dec_some" t_utf8_dec_some] t_utf8_incr_valid = do Positive n <- arbitrary @@ -72,7 +72,7 @@ t_utf8_incr_pipe = do Positive n <- arbitrary txt <- genUnicode let chunkSize = mod n 7 + 1 - bytesLength = mod 3 m + bytesLength = mod 10 m forAll (vector bytesLength) $ (BL.toStrict . BP.toLazy . roundtrip . P.each . chunk chunkSize . appendBytes txt) `eq` @@ -83,6 +83,35 @@ t_utf8_incr_pipe = do chunk n bs = let (a,b) = B.splitAt n bs in if B.null a then [] else a : chunk n b appendBytes txt bts = E.encodeUtf8 txt <> B.pack bts ; (<>) = B.append +-- +t_utf8_incr_decoding = do + Positive m <- arbitrary + Positive n <- arbitrary + txt <- genUnicode + let chunkSize = mod n 7 + 1 + bytesLength = mod 10 m + forAll (vector bytesLength) $ + (BL.toStrict . BP.toLazy . roundtrip . P.each . chunk chunkSize . appendBytes txt) + `eq` + appendBytes txt + where + roundtrip :: Monad m => P.Producer B.ByteString m r -> P.Producer B.ByteString m r + roundtrip p = join (TP.decode utf8_start p P.>-> TP.encodeUtf8) + chunk n bs = let (a,b) = B.splitAt n bs in if B.null a then [] else a : chunk n b + appendBytes txt bts = E.encodeUtf8 txt <> B.pack bts ; (<>) = B.append + utf8_start = PE.Some T.empty B.empty (PE.codecDecode PE.utf8) +t_utf8_dec_some = do + Positive m <- arbitrary + txt <- genUnicode + let bytesLength = mod 10 m :: Int + forAll (vector bytesLength) $ + (roundtrip . appendBytes txt) + `eq` + appendBytes txt + where + roundtrip bs = case PE.decodeSomeUtf8 bs of + (txt,bys) -> E.encodeUtf8 txt <> bys + appendBytes txt bts = E.encodeUtf8 txt <> B.pack bts ; (<>) = B.append