on master help sign in
Add test case for mapAccumL bug
9faf446Bryan O'Sullivan
tests/Tests/Regressions.hs+15−1
@@ -8,7 +8,7 @@ module Tests.Regressions
8
8
9import Control.Exception (SomeException, handle)
9import Control.Exception (SomeException, handle)
10import System.IO
10import System.IO
11−import Test.HUnit (assertBool, assertFailure)
11+import Test.HUnit (assertBool, assertEqual, assertFailure)
12import qualified Data.ByteString as B
12import qualified Data.ByteString as B
13import Data.ByteString.Char8 ()
13import Data.ByteString.Char8 ()
14import qualified Data.ByteString.Lazy as LB
14import qualified Data.ByteString.Lazy as LB
@@ -17,6 +17,7 @@ import qualified Data.Text.Encoding as TE
17import qualified Data.Text.IO as T
17import qualified Data.Text.IO as T
18import qualified Data.Text.Lazy as LT
18import qualified Data.Text.Lazy as LT
19import qualified Data.Text.Lazy.Encoding as LE
19import qualified Data.Text.Lazy.Encoding as LE
20+import qualified Data.Text.Unsafe as T
20import qualified Test.Framework as F
21import qualified Test.Framework as F
21import qualified Test.Framework.Providers.HUnit as F
22import qualified Test.Framework.Providers.HUnit as F
22
23
@@ -59,10 +60,23 @@ utf8_decode_unsafe = do
59 let t = TE.decodeUtf8With (\_ _ -> Just '\xdc00') "\x80"
60 let t = TE.decodeUtf8With (\_ _ -> Just '\xdc00') "\x80"
60 assertBool "broken error recovery shouldn't break us" (t == "\xfffd")
61 assertBool "broken error recovery shouldn't break us" (t == "\xfffd")
61
62
63+-- Reported by Eric Seidel: we mishandled mapping Chars that fit in a
64+-- single Word16 to Chars that require two.
65+mapAccumL_resize :: IO ()
66+mapAccumL_resize = do
67+ let f a _ = (a, '\65536')
68+ count = 5
69+ val = T.mapAccumL f 0 (T.replicate count "a")
70+ assertEqual "mapAccumL should correctly fill buffers for two-word results"
71+ (0, T.replicate count "\65536") val
72+ assertEqual "mapAccumL should correctly size buffers for two-word results"
73+ (count * 2) (T.lengthWord16 (snd val))
74+
62tests :: F.Test
75tests :: F.Test
63tests = F.testGroup "Regressions"
76tests = F.testGroup "Regressions"
64 [ F.testCase "hGetContents_crash" hGetContents_crash
77 [ F.testCase "hGetContents_crash" hGetContents_crash
65 , F.testCase "lazy_encode_crash" lazy_encode_crash
78 , F.testCase "lazy_encode_crash" lazy_encode_crash
79+ , F.testCase "mapAccumL_resize" mapAccumL_resize
66 , F.testCase "replicate_crash" replicate_crash
80 , F.testCase "replicate_crash" replicate_crash
67 , F.testCase "utf8_decode_unsafe" utf8_decode_unsafe
81 , F.testCase "utf8_decode_unsafe" utf8_decode_unsafe
68 ]
82 ]