on master help sign in
Properties: Add round-trip property for incremental decoding
59d2694Ben Gamari
tests/Tests/Properties.hs+12
@@ -93,6 +93,17 @@ tl_utf32LE = forAll genUnicode $ (EL.decodeUtf32LE . EL.encodeUtf32LE) `eq` id
93t_utf32BE = forAll genUnicode $ (E.decodeUtf32BE . E.encodeUtf32BE) `eq` id
93t_utf32BE = forAll genUnicode $ (E.decodeUtf32BE . E.encodeUtf32BE) `eq` id
94tl_utf32BE = forAll genUnicode $ (EL.decodeUtf32BE . EL.encodeUtf32BE) `eq` id
94tl_utf32BE = forAll genUnicode $ (EL.decodeUtf32BE . EL.encodeUtf32BE) `eq` id
95
95
96+t_utf8_incr = do
97+ Positive n <- arbitrary
98+ forAll genUnicode $ recode n `eq` id
99+ where recode n = T.concat . feedChunksOf n (E.decodeUtf8With' strictDecode) . E.encodeUtf8
100+ feedChunksOf :: Int -> (B.ByteString -> E.Decoder) -> B.ByteString -> [T.Text]
101+ feedChunksOf n f bs
102+ | B.null bs = []
103+ | otherwise = let (a,b) = B.splitAt n bs
104+ E.Some t f' = f a
105+ in t : feedChunksOf n f' b
106+
96-- This is a poor attempt to ensure that the error handling paths on
107-- This is a poor attempt to ensure that the error handling paths on
97-- decode are exercised in some way. Proper testing would be rather
108-- decode are exercised in some way. Proper testing would be rather
98-- more involved.
109-- more involved.
@@ -771,6 +782,7 @@ tests =
771 testProperty "tl_latin1" tl_latin1,
782 testProperty "tl_latin1" tl_latin1,
772 testProperty "t_utf8" t_utf8,
783 testProperty "t_utf8" t_utf8,
773 testProperty "t_utf8'" t_utf8',
784 testProperty "t_utf8'" t_utf8',
785+ testProperty "t_utf8_incr" t_utf8_incr,
774 testProperty "tl_utf8" tl_utf8,
786 testProperty "tl_utf8" tl_utf8,
775 testProperty "tl_utf8'" tl_utf8',
787 testProperty "tl_utf8'" tl_utf8',
776 testProperty "t_utf16LE" t_utf16LE,
788 testProperty "t_utf16LE" t_utf16LE,