@@ -15,12 +15,24 @@ import qualified Data.ByteString as B
15import qualified Data.Text as T
15import qualified Data.Text as T
16import Data.Text (pack,unpack)
16import Data.Text (pack,unpack)
17import qualified Data.Text.Encoding as E
17import qualified Data.Text.Encoding as E
18+import Control.Exception
18import qualified Data.Text.Fusion as S
19import qualified Data.Text.Fusion as S
19import Data.Text.Fusion (stream, unstream)
20import Data.Text.Fusion (stream, unstream)
20import qualified Data.List as L
21import qualified Data.List as L
22+import System.IO.Unsafe
23+import Prelude hiding (catch)
22import QuickCheckUtils
25import QuickCheckUtils
27+-- If a pure property threatens to crash, wrap it with this to keep
28+-- QuickCheck from bombing out.
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
24prop_pack_unpack s = (unpack . pack) s == s
36prop_pack_unpack s = (unpack . pack) s == s
25prop_stream_unstream t = (unstream . stream) t == t
37prop_stream_unstream t = (unstream . stream) t == t
26prop_reverse_stream t = (S.reverse . S.reverseStream) t == t
38prop_reverse_stream t = (S.reverse . S.reverseStream) t == t
@@ -29,10 +41,11 @@ prop_singleton c = [c] == (unpack . T.singleton) c
29prop_ascii t = E.decodeASCII (E.encodeASCII a) == a
41prop_ascii t = E.decodeASCII (E.encodeASCII a) == a
30 where a = T.map (\c -> chr (ord c `mod` 128)) t
42 where a = T.map (\c -> chr (ord c `mod` 128)) t
31prop_utf8 = (E.decodeUtf8 . E.encodeUtf8) `eq` id
43prop_utf8 = (E.decodeUtf8 . E.encodeUtf8) `eq` id
44+prop_utf16LE = (E.decodeUtf16LE . E.encodeUtf16LE) `eq` id
33-- Do two functions give the same answer?
46-- Do two functions give the same answer?
34eq :: (Eq a) => (t -> a) -> (t -> a) -> t -> Bool
47eq :: (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
36-- What about with the RHS packed?
49-- What about with the RHS packed?
37eqP :: (Eq a, Show a) => (String -> a) -> (T.Text -> a) -> String -> Word8 -> Bool
50eqP :: (Eq a, Show a) => (String -> a) -> (T.Text -> a) -> String -> Word8 -> Bool
38eqP a b s w = eq "orig" (a s) (b t) &&
51eqP 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) &&
45 m | l == 0 = n
58 m | l == 0 = n
46 | otherwise = n `mod` l
59 | otherwise = n `mod` l
47 n = fromIntegral w
60 n = fromIntegral w
48− eq s a b | a == b = True
61+ eq s a b | crashy False $ a == b = True
49 | otherwise = trace (s ++ ": " ++ show a ++ " /= " ++ show b) False
62 | otherwise = trace (s ++ ": " ++ show a ++ " /= " ++ show b) False
50-- Or with the string non-empty, and the RHS packed?
63-- Or with the string non-empty, and the RHS packed?
51eqEP :: (Eq a) =>
64eqEP :: (Eq a) =>
@@ -219,6 +232,7 @@ tests = [
220 ("prop_ascii", mytest prop_ascii),
233 ("prop_ascii", mytest prop_ascii),
221 ("prop_utf8", mytest prop_utf8),
234 ("prop_utf8", mytest prop_utf8),
235+ ("prop_utf16LE", mytest prop_utf16LE),
223 ("prop_cons", mytest prop_cons),
237 ("prop_cons", mytest prop_cons),
224 ("prop_snoc", mytest prop_snoc),
238 ("prop_snoc", mytest prop_snoc),