aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Test.hs15
1 files changed, 5 insertions, 10 deletions
diff --git a/test/Test.hs b/test/Test.hs
index 66351d1..53dca6a 100644
--- a/test/Test.hs
+++ b/test/Test.hs
@@ -23,17 +23,16 @@ import qualified Pipes.Text.Internal as PE
23import qualified Pipes.Text as TP 23import qualified Pipes.Text as TP
24import qualified Pipes.ByteString as BP 24import qualified Pipes.ByteString as BP
25import qualified Pipes as P 25import qualified Pipes as P
26
27
28import Debug.Trace 26import Debug.Trace
27
29main :: IO () 28main :: IO ()
30main = defaultMain [tests] 29main = defaultMain [tests]
31-- >>> :main -a 10000 30-- >>> :main -a 10000
32 31
33tests = testGroup "stream_decode" [ 32tests = testGroup "stream_decode" [
34 -- testProperty "t_utf8_incr_valid" t_utf8_incr_valid, 33 -- testProperty "t_utf8_incr_valid" t_utf8_incr_valid,
35 testProperty "t_utf8_incr_mixed" t_utf8_incr_mixed, 34-- testProperty "t_utf8_incr_mixed" t_utf8_incr_mixed ] -- ,
36 testProperty "t_utf8_incr_pipe" t_utf8_incr_pipe] 35 testProperty "t_utf8_incr_pipe" t_utf8_incr_pipe]
37 36
38t_utf8_incr_valid = do 37t_utf8_incr_valid = do
39 Positive n <- arbitrary 38 Positive n <- arbitrary
@@ -68,23 +67,19 @@ t_utf8_incr_mixed = do
68 chunk n bs = let (a,b) = B.splitAt n bs in if B.null a then [] else a : chunk n b 67 chunk n bs = let (a,b) = B.splitAt n bs in if B.null a then [] else a : chunk n b
69 appendBytes txt bts = E.encodeUtf8 txt <> B.pack bts ; (<>) = B.append 68 appendBytes txt bts = E.encodeUtf8 txt <> B.pack bts ; (<>) = B.append
70 69
71
72
73
74t_utf8_incr_pipe = do 70t_utf8_incr_pipe = do
75 Positive m <- arbitrary 71 Positive m <- arbitrary
76 Positive n <- arbitrary 72 Positive n <- arbitrary
77 txt <- genUnicode 73 txt <- genUnicode
78 let chunkSize = mod n 7 + 1 74 let chunkSize = mod n 7 + 1
79 bytesLength = mod 20 m 75 bytesLength = mod 3 m
80 forAll (vector bytesLength) $ 76 forAll (vector bytesLength) $
81 (BL.toStrict . BP.toLazy . roundtrip . P.each . chunk chunkSize . appendBytes txt) 77 (BL.toStrict . BP.toLazy . roundtrip . P.each . chunk chunkSize . appendBytes txt)
82 `eq` 78 `eq`
83 appendBytes txt 79 appendBytes txt
84 where 80 where
85 roundtrip :: Monad m => P.Producer B.ByteString m r -> P.Producer B.ByteString m r 81 roundtrip :: Monad m => P.Producer B.ByteString m r -> P.Producer B.ByteString m r
86 roundtrip p = do pbs <- TP.decodeUtf8 p P.>-> TP.encodeUtf8 82 roundtrip p = join (TP.decodeUtf8 p P.>-> TP.encodeUtf8)
87 pbs
88 chunk n bs = let (a,b) = B.splitAt n bs in if B.null a then [] else a : chunk n b 83 chunk n bs = let (a,b) = B.splitAt n bs in if B.null a then [] else a : chunk n b
89 appendBytes txt bts = E.encodeUtf8 txt <> B.pack bts ; (<>) = B.append 84 appendBytes txt bts = E.encodeUtf8 txt <> B.pack bts ; (<>) = B.append
90 85