on master help sign in
Improve test coverage up to 86%.

--HG-- extra : convert_revision : 625d2f5f8a5fa687b7c3984de438d326e9dd8369

commit3cebbddff75ab90783a1dfe5d9fbe8054d4ae4ca authorBryan O'Sullivan <bos@serpentine.com> dateFri 14 Aug 2009, 23:25 (17 years ago) parentd06b92b
5 files changed+19−43
Data/Text/Array.hs−35 Data/Text/Fusion/Internal.hs+2−4 Data/Text/UnsafeChar.hs+3−1 Data/Text/UnsafeShift.hs+4 tests/Properties.hs+10−3
Data/Text/Array.hs−35
@@ -166,9 +166,6 @@ unsafeFreeze :: MArray s e -> ST s (Array e)
166166
167167#if defined(__GLASGOW_HASKELL__)
168168
169−iNT_SCALE :: Int# -> Int#
170−iNT_SCALE n# = scale# *# n# where I# scale# = SIZEOF_INT
171−
172169wORD16_SCALE :: Int# -> Int#
173170wORD16_SCALE n# = scale# *# n# where I# scale# = SIZEOF_WORD16
174171
@@ -228,38 +225,6 @@ new len initVal = do
228225 sequence_ [unsafeWrite marr i initVal | i <- [0..len-1]]
229226 return marr
230227
231−instance Elt Int where
232−#if defined(__GLASGOW_HASKELL__)
233−
234− bytesInArray (I# i#) _ = I# (iNT_SCALE i#)
235− {-# INLINE bytesInArray #-}
236−
237− unsafeIndex (Array len ba#) i@(I# i#) =
238− CHECK_BOUNDS("unsafeIndex",len,i)
239− case indexIntArray# ba# i# of r# -> (I# r#)
240− {-# INLINE unsafeIndex #-}
241−
242− unsafeRead (MArray len mba#) i@(I# i#) = ST $ \s# ->
243− CHECK_BOUNDS("unsafeRead",len,i)
244− case readIntArray# mba# i# s# of
245− (# s2#, r# #) -> (# s2#, I# r# #)
246− {-# INLINE unsafeRead #-}
247−
248− unsafeWrite (MArray len marr#) i@(I# i#) (I# e#) = ST $ \s1# ->
249− CHECK_BOUNDS("unsafeWrite",len,i)
250− case writeIntArray# marr# i# e# s1# of
251− s2# -> (# s2#, () #)
252− {-# INLINE unsafeWrite #-}
253−
254−#elif defined(__HUGS__)
255−
256− bytesInArray n w = sizeOf w * n
257− unsafeIndex = unsafeIndexArray
258− unsafeRead = unsafeReadMArray
259− unsafeWrite = unsafeWriteMArray
260−
261−#endif
262−
263228instance Elt Word16 where
264229#if defined(__GLASGOW_HASKELL__)
265230
Data/Text/Fusion/Internal.hs+2−4
@@ -30,31 +30,29 @@ import Data.Word (Word8)
3030-- | Specialised, strict Maybe-like type.
3131data M a = N
3232 | J {-# UNPACK #-} !a
33− deriving (Eq, Ord, Show)
3433
3534type M8 = M Word8
3635
3736-- Restreaming state.
3837data S s = S {-# UNPACK #-} !s
3938 {-# UNPACK #-} !M8 {-# UNPACK #-} !M8 {-# UNPACK #-} !M8
40− deriving (Eq, Ord, Show)
4139
4240infixl 2 :!:
4341data PairS a b = !a :!: !b
44− deriving (Eq, Ord, Read, Show)
4542
4643-- | Allow a function over a stream to switch between two states.
4744data Switch = S1 | S2
48− deriving (Eq, Ord, Show)
4945
5046data Step s a = Done
5147 | Skip !s
5248 | Yield !a !s
5349
50+{-
5451instance Show a => Show (Step s a)
5552 where show Done = "Done"
5653 show (Skip _) = "Skip"
5754 show (Yield x _) = "Yield " ++ show x
55+-}
5856
5957instance (Eq a) => Eq (Stream a) where
6058 (==) = eq
Data/Text/UnsafeChar.hs+3−1
@@ -19,7 +19,7 @@ module Data.Text.UnsafeChar
1919 , unsafeChr8
2020 , unsafeChr32
2121 , unsafeWrite
22− , unsafeWriteRev
22+ -- , unsafeWriteRev
2323 ) where
2424
2525import Control.Exception (assert)
@@ -60,6 +60,7 @@ unsafeWrite marr i c
6060 hi = fromIntegral $ (m .&. 0x3FF) + 0xDC00
6161{-# INLINE unsafeWrite #-}
6262
63+{-
6364unsafeWriteRev :: A.MArray s Word16 -> Int -> Char -> ST s Int
6465unsafeWriteRev marr i c
6566 | n < 0x10000 = do
@@ -76,3 +77,4 @@ unsafeWriteRev marr i c
7677 lo = fromIntegral $ (m `shiftR` 10) + 0xD800
7778 hi = fromIntegral $ (m .&. 0x3FF) + 0xDC00
7879{-# INLINE unsafeWriteRev #-}
80+-}
Data/Text/UnsafeShift.hs+4
@@ -45,12 +45,14 @@ instance UnsafeShift Word32 where
4545 {-# INLINE shiftR #-}
4646 shiftR (W32# x#) (I# i#) = W32# (x# `uncheckedShiftRL#` i#)
4747
48+{-
4849instance UnsafeShift Word64 where
4950 {-# INLINE shiftL #-}
5051 shiftL (W64# x#) (I# i#) = W64# (x# `uncheckedShiftL64#` i#)
5152
5253 {-# INLINE shiftR #-}
5354 shiftR (W64# x#) (I# i#) = W64# (x# `uncheckedShiftRL64#` i#)
55+-}
5456
5557instance UnsafeShift Int where
5658 {-# INLINE shiftL #-}
@@ -59,9 +61,11 @@ instance UnsafeShift Int where
5961 {-# INLINE shiftR #-}
6062 shiftR (I# x#) (I# i#) = I# (x# `iShiftRA#` i#)
6163
64+{-
6265instance UnsafeShift Integer where
6366 {-# INLINE shiftL #-}
6467 shiftL = Bits.shiftL
6568
6669 {-# INLINE shiftR #-}
6770 shiftR = Bits.shiftR
71+-}
tests/Properties.hs+10−3
@@ -6,6 +6,7 @@ import Text.Show.Functions
66
77import Data.Char
88import Data.Monoid
9+import Data.String
910import Debug.Trace
1011import Text.Printf
1112import System.Environment
@@ -15,7 +16,7 @@ import Control.Monad
1516import Data.Word
1617import qualified Data.ByteString as B
1718import qualified Data.Text as T
18−import qualified Data.Text.Compat as T (breakSubstring)
19+import qualified Data.Text.Compat as C
1920import qualified Data.Text.Lazy as TL
2021import qualified Data.Text.Encoding as E
2122import Control.Exception
@@ -142,6 +143,8 @@ prop_T_mappend s = mappend s`eqP` (unpackS . mappend (T.pack s))
142143prop_TL_mappend s = mappend s`eqP` (unpackS . mappend (TL.pack s))
143144prop_T_mconcat = mconcat `eq` (unpackS . mconcat . L.map T.pack)
144145prop_TL_mconcat = mconcat `eq` (unpackS . mconcat . L.map TL.pack)
146+prop_T_IsString = fromString `eqP` (T.unpack . fromString)
147+prop_TL_IsString = fromString `eqP` (TL.unpack . fromString)
145148
146149prop_S_cons x = (x:) `eqP` (unpackS . S.cons x)
147150prop_T_cons x = (x:) `eqP` (unpackS . T.cons x)
@@ -332,6 +335,7 @@ prop_TL_split_i c = id `eq` (TL.intercalate (TL.singleton c) . TL.split c)
332335prop_T_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
333336prop_T_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.count c)
334337prop_T_splitWith_split c = T.splitWith (==c) `eq` T.split (T.singleton c)
338+prop_T_splitWith_Csplit c = T.splitWith (==c) `eq` C.split c
335339prop_TL_splitWith p = splitWith p `eqP` (map unpackS . TL.splitWith p)
336340
337341splitWith :: (a -> Bool) -> [a] -> [[a]]
@@ -350,10 +354,10 @@ prop_T_chunksOf_length k t = len == T.length t || (k <= 0 && len == 0)
350354
351355prop_T_breakSubstring_isInfixOf s l
352356 = T.isInfixOf s l ==
353− T.null s || (not . T.null . snd $ T.breakSubstring s l)
357+ T.null s || (not . T.null . snd $ C.breakSubstring s l)
354358prop_T_breakSubstringC c
355359 = L.break (==c) `eqP`
356− (unpack2 . T.breakSubstring (T.singleton c))
360+ (unpack2 . C.breakSubstring (T.singleton c))
357361
358362prop_T_lines = L.lines `eqP` (map unpackS . T.lines)
359363prop_TL_lines = L.lines `eqP` (map unpackS . TL.lines)
@@ -472,6 +476,8 @@ tests = [
472476 ("prop_TL_mappend", mytest prop_TL_mappend),
473477 ("prop_T_mconcat", mytest prop_T_mconcat),
474478 ("prop_TL_mconcat", mytest prop_TL_mconcat),
479+ ("prop_T_IsString", mytest prop_T_IsString),
480+ ("prop_TL_IsString", mytest prop_TL_IsString),
475481
476482 ("prop_S_cons", mytest prop_S_cons),
477483 ("prop_T_cons", mytest prop_T_cons),
@@ -613,6 +619,7 @@ tests = [
613619 ("prop_T_splitWith", mytest prop_T_splitWith),
614620 ("prop_T_splitWith_count", mytest prop_T_splitWith_count),
615621 ("prop_T_splitWith_split", mytest prop_T_splitWith_split),
622+ ("prop_T_splitWith_Csplit", mytest prop_T_splitWith_Csplit),
616623 ("prop_TL_splitWith", mytest prop_TL_splitWith),
617624 ("prop_T_chunksOf_same_lengths", mytest prop_T_chunksOf_same_lengths),
618625 ("prop_T_chunksOf_length", mytest prop_T_chunksOf_length),