diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Test.hs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/Test.hs b/test/Test.hs index 373bafb..7832f76 100644 --- a/test/Test.hs +++ b/test/Test.hs | |||
@@ -31,6 +31,7 @@ tests = testGroup "stream_decode" [ | |||
31 | -- testProperty "t_utf8_incr_valid" t_utf8_incr_valid, | 31 | -- testProperty "t_utf8_incr_valid" t_utf8_incr_valid, |
32 | testProperty "t_utf8_incr_mixed" t_utf8_incr_mixed , | 32 | testProperty "t_utf8_incr_mixed" t_utf8_incr_mixed , |
33 | testProperty "t_utf8_incr_pipe" t_utf8_incr_pipe, | 33 | testProperty "t_utf8_incr_pipe" t_utf8_incr_pipe, |
34 | testProperty "t_utf8_incr_decoding" t_utf8_incr_decoding, | ||
34 | testProperty "t_utf8_dec_some" t_utf8_dec_some] | 35 | testProperty "t_utf8_dec_some" t_utf8_dec_some] |
35 | 36 | ||
36 | t_utf8_incr_valid = do | 37 | t_utf8_incr_valid = do |
@@ -83,6 +84,22 @@ t_utf8_incr_pipe = do | |||
83 | appendBytes txt bts = E.encodeUtf8 txt <> B.pack bts ; (<>) = B.append | 84 | appendBytes txt bts = E.encodeUtf8 txt <> B.pack bts ; (<>) = B.append |
84 | 85 | ||
85 | -- | 86 | -- |
87 | t_utf8_incr_decoding = do | ||
88 | Positive m <- arbitrary | ||
89 | Positive n <- arbitrary | ||
90 | txt <- genUnicode | ||
91 | let chunkSize = mod n 7 + 1 | ||
92 | bytesLength = mod 10 m | ||
93 | forAll (vector bytesLength) $ | ||
94 | (BL.toStrict . BP.toLazy . roundtrip . P.each . chunk chunkSize . appendBytes txt) | ||
95 | `eq` | ||
96 | appendBytes txt | ||
97 | where | ||
98 | roundtrip :: Monad m => P.Producer B.ByteString m r -> P.Producer B.ByteString m r | ||
99 | roundtrip p = join (TP.decode utf8_start p P.>-> TP.encodeUtf8) | ||
100 | chunk n bs = let (a,b) = B.splitAt n bs in if B.null a then [] else a : chunk n b | ||
101 | appendBytes txt bts = E.encodeUtf8 txt <> B.pack bts ; (<>) = B.append | ||
102 | utf8_start = PE.Some T.empty B.empty (PE.codecDecode PE.utf8) | ||
86 | t_utf8_dec_some = do | 103 | t_utf8_dec_some = do |
87 | Positive m <- arbitrary | 104 | Positive m <- arbitrary |
88 | txt <- genUnicode | 105 | txt <- genUnicode |