@@ -1,3 +1,4 @@
1+{-# LANGUAGE FlexibleInstances #-}
1{-# OPTIONS_GHC -fno-enable-rewrite-rules #-}
2{-# OPTIONS_GHC -fno-enable-rewrite-rules #-}
3import Test.QuickCheck
4import Test.QuickCheck
@@ -49,32 +50,51 @@ prop_T_utf16BE = (E.decodeUtf16BE . E.encodeUtf16BE) `eq` id
49prop_T_utf32LE = (E.decodeUtf32LE . E.encodeUtf32LE) `eq` id
50prop_T_utf32LE = (E.decodeUtf32LE . E.encodeUtf32LE) `eq` id
50prop_T_utf32BE = (E.decodeUtf32BE . E.encodeUtf32BE) `eq` id
51prop_T_utf32BE = (E.decodeUtf32BE . E.encodeUtf32BE) `eq` id
55+ splitAtT :: Int -> t -> (t,t)
57+instance Target (S.Stream Char) where
59+ splitAtT n s = (S.take n s, S.drop n s)
61+instance Target T.Text where
65+instance Target TL.Text where
67+ splitAtT = TL.splitAt
52-- Do two functions give the same answer?
69-- Do two functions give the same answer?
53eq :: (Eq a) => (t -> a) -> (t -> a) -> t -> Bool
70eq :: (Eq a) => (t -> a) -> (t -> a) -> t -> Bool
54eq a b s = crashy False $ a s == b s
71eq a b s = crashy False $ a s == b s
55-- What about with the RHS packed?
73-- What about with the RHS packed?
74+eqP :: (Eq a, Show a, Target t) =>
56−eqP :: (Eq a, Show a) => (String -> a) -> (T.Text -> a) -> String -> Word8 -> Bool
75+ (String -> a) -> (t -> a) -> String -> Word8 -> Bool
57eqP a b s w = eq "orig" (a s) (b t) &&
76eqP a b s w = eq "orig" (a s) (b t) &&
58 eq "head" (a sa) (b ta) &&
77 eq "head" (a sa) (b ta) &&
59 eq "tail" (a sb) (b tb)
78 eq "tail" (a sb) (b tb)
60− where t = T.pack s
79+ where t = packT s
61 (sa,sb) = splitAt m s
80 (sa,sb) = splitAt m s
62− (ta,tb) = T.splitAt m t
81+ (ta,tb) = splitAtT m t
63 l = length s
82 l = length s
64 m | l == 0 = n
83 m | l == 0 = n
65 | otherwise = n `mod` l
84 | otherwise = n `mod` l
66 n = fromIntegral w
85 n = fromIntegral w
67 eq s a b | crashy False $ a == b = True
86 eq s a b | crashy False $ a == b = True
68 | otherwise = trace (s ++ ": " ++ show a ++ " /= " ++ show b) False
87 | otherwise = trace (s ++ ": " ++ show a ++ " /= " ++ show b) False
69-- Or with the string non-empty, and the RHS packed?
89-- Or with the string non-empty, and the RHS packed?
70−eqEP :: (Eq a) =>
90+eqEP :: (Eq a, Target t) =>
71− (String -> a) -> (T.Text -> a) -> NotEmpty String -> Word8 -> Bool
91+ (String -> a) -> (t -> a) -> NotEmpty String -> Word8 -> Bool
72eqEP a b e w = a s == b t &&
92eqEP a b e w = a s == b t &&
73 (null sa || a sa == b ta) &&
93 (null sa || a sa == b ta) &&
74 (null sb || a sb == b tb)
94 (null sb || a sb == b tb)
75 where (sa,sb) = splitAt m s
95 where (sa,sb) = splitAt m s
76− (ta,tb) = T.splitAt m t
96+ (ta,tb) = splitAtT m t
77− t = T.pack s
97+ t = packT s
78 l = length s
98 l = length s
79 m | l == 0 = n
99 m | l == 0 = n
80 | otherwise = n `mod` l
100 | otherwise = n `mod` l