Commits

Bryan O'Sullivan  committed bd9330b

Tests: generalise feedChunksOf and hoist to top level

  • Participants
  • Parent commits b06f2ac

Comments (0)

Files changed (1)

File tests/Tests/Properties.hs

 t_utf8_incr  = do
         Positive n <- arbitrary
         forAll genUnicode $ recode n `eq` id
-    where recode n = T.concat . feedChunksOf n E.streamDecodeUtf8 . E.encodeUtf8
-          feedChunksOf :: Int -> (B.ByteString -> E.Decoding) -> B.ByteString
-                       -> [T.Text]
-          feedChunksOf n f bs
-            | B.null bs  = []
-            | otherwise  = let (a,b) = B.splitAt n bs
-                               E.Some t _ f' = f a
-                           in t : feedChunksOf n f' b
+    where recode n = T.concat . map fst . feedChunksOf n E.streamDecodeUtf8 .
+                     E.encodeUtf8
+
+feedChunksOf :: Int -> (B.ByteString -> E.Decoding) -> B.ByteString
+             -> [(T.Text, B.ByteString)]
+feedChunksOf n f bs
+  | B.null bs  = []
+  | otherwise  = let (x,y) = B.splitAt n bs
+                     E.Some t b f' = f x
+                 in (t,b) : feedChunksOf n f' y
 
 data Badness = Solo | Leading | Trailing
              deriving (Eq, Show)