@@ -21,7 +21,7 @@ import qualified Data.Text.Lazy.IO as TL
2121import qualified Data.Text.Lazy.Builder as TB
2222import qualified Data.Text.Encoding as E
2323import Data.Text.Encoding.Error
24−import Control.Exception (SomeException, bracket, evaluate, try)
24+import Control.Exception (SomeException, bracket, catch, evaluate, try)
2525import Data.Text.Foreign
2626import qualified Data.Text.Fusion as S
2727import qualified Data.Text.Fusion.Common as S
@@ -30,7 +30,7 @@ import qualified Data.Text.Lazy.Encoding as EL
3030import qualified Data.Text.Lazy.Fusion as SL
3131import qualified Data.Text.UnsafeShift as U
3232import qualified Data.List as L
33−import Prelude hiding (replicate)
33+import Prelude hiding (catch, replicate)
3434import System.IO
3535import System.IO.Unsafe (unsafePerformIO)
3636import Test.Framework (defaultMain, testGroup)
@@ -93,9 +93,19 @@ instance CoArbitrary Word8 where
9393instance Arbitrary DecodeErr where
9494 arbitrary = oneof [ return $ DE "lenient" lenientDecode
9595 , return $ DE "ignore" ignore
96+ , return $ DE "strict" strictDecode
9697 , DE "replace" `fmap` arbitrary ]
9798
98−t_utf8_err (DE _ de) bs = T.length (E.decodeUtf8With de bs) >= 0
99+-- This is a poor attempt to ensure that the error handling paths on
100+-- decode are exercised in some way. Proper testing would be rather
101+-- more involved.
102+t_utf8_err (DE _ de) bs = monadicIO $ do
103+ l <- run $ let len = T.length (E.decodeUtf8With de bs)
104+ in (len `seq` return (Right len)) `catch`
105+ (\(e::UnicodeException) -> return (Left e))
106+ case l of
107+ Left err -> assert $ length (show err) >= 0
108+ Right n -> assert $ n >= 0
99109
100110class Stringy s where
101111 packS :: String -> s