@@ -15,12 +15,24 @@ import qualified Data.ByteString as B
1515import qualified Data.Text as T
1616import Data.Text (pack,unpack)
1717import qualified Data.Text.Encoding as E
18+import Control.Exception
1819import qualified Data.Text.Fusion as S
1920import Data.Text.Fusion (stream, unstream)
2021import qualified Data.List as L
22+import System.IO.Unsafe
23+import Prelude hiding (catch)
2124
2225import QuickCheckUtils
2326
27+-- If a pure property threatens to crash, wrap it with this to keep
28+-- QuickCheck from bombing out.
29+crashy :: a -> a -> a
30+{-# NOINLINE crashy #-}
31+crashy onException p = unsafePerformIO $
32+ (return $! p) `catch` \e ->
33+ let types = e :: SomeException
34+ in trace ("*** Exception: " ++ show e) return onException
35+
2436prop_pack_unpack s = (unpack . pack) s == s
2537prop_stream_unstream t = (unstream . stream) t == t
2638prop_reverse_stream t = (S.reverse . S.reverseStream) t == t
@@ -29,10 +41,11 @@ prop_singleton c = [c] == (unpack . T.singleton) c
2941prop_ascii t = E.decodeASCII (E.encodeASCII a) == a
3042 where a = T.map (\c -> chr (ord c `mod` 128)) t
3143prop_utf8 = (E.decodeUtf8 . E.encodeUtf8) `eq` id
44+prop_utf16LE = (E.decodeUtf16LE . E.encodeUtf16LE) `eq` id
3245
3346-- Do two functions give the same answer?
3447eq :: (Eq a) => (t -> a) -> (t -> a) -> t -> Bool
35−eq a b s = a s == b s
48+eq a b s = crashy False $ a s == b s
3649-- What about with the RHS packed?
3750eqP :: (Eq a, Show a) => (String -> a) -> (T.Text -> a) -> String -> Word8 -> Bool
3851eqP a b s w = eq "orig" (a s) (b t) &&
@@ -45,7 +58,7 @@ eqP a b s w = eq "orig" (a s) (b t) &&
4558 m | l == 0 = n
4659 | otherwise = n `mod` l
4760 n = fromIntegral w
48− eq s a b | a == b = True
61+ eq s a b | crashy False $ a == b = True
4962 | otherwise = trace (s ++ ": " ++ show a ++ " /= " ++ show b) False
5063-- Or with the string non-empty, and the RHS packed?
5164eqEP :: (Eq a) =>
@@ -219,6 +232,7 @@ tests = [
219232
220233 ("prop_ascii", mytest prop_ascii),
221234 ("prop_utf8", mytest prop_utf8),
235+ ("prop_utf16LE", mytest prop_utf16LE),
222236
223237 ("prop_cons", mytest prop_cons),
224238 ("prop_snoc", mytest prop_snoc),