1 {-# LANGUAGE BangPatterns, FlexibleInstances, OverloadedStrings, 2 ScopedTypeVariables, TypeSynonymInstances #-} 3 {-# OPTIONS_GHC -fno-enable-rewrite-rules #-} 4 5 import Test.QuickCheck 6 import Test.QuickCheck.Monadic 7 import Text.Show.Functions () 8 9 import qualified Data.Bits as Bits (shiftL, shiftR) 10 import Data.Char (chr, isLower, isSpace, isUpper, ord) 11 import Data.Monoid (Monoid(..)) 12 import Data.String (fromString) 13 import Debug.Trace (trace) 14 import Control.Arrow ((***), second) 15 import Control.DeepSeq 16 import Data.Word (Word8, Word16, Word32) 17 import qualified Data.Text as T 18 import qualified Data.Text.IO as T 19 import qualified Data.Text.Lazy as TL 20 import qualified Data.Text.Lazy.IO as TL 21 import qualified Data.Text.Lazy.Internal as TL 22 import qualified Data.Text.Lazy.Builder as TB 23 import qualified Data.Text.Encoding as E 24 import Data.Text.Encoding.Error 25 import Control.Exception (SomeException, bracket, catch, evaluate, try) 26 import Data.Text.Foreign 27 import qualified Data.Text.Fusion as S 28 import qualified Data.Text.Fusion.Common as S 29 import Data.Text.Fusion.Size 30 import qualified Data.Text.Lazy.Encoding as EL 31 import qualified Data.Text.Lazy.Fusion as SL 32 import qualified Data.Text.UnsafeShift as U 33 import qualified Data.List as L 34 import Prelude hiding (catch, replicate) 35 import System.IO 36 import System.IO.Unsafe (unsafePerformIO) 37 import Test.Framework (defaultMain, testGroup) 38 import Test.Framework.Providers.QuickCheck2 (testProperty) 39 import Data.Text.Search (indices) 40 import qualified Data.Text.Lazy.Search as S (indices) 41 import qualified SlowFunctions as Slow 42 43 import QuickCheckUtils (NotEmpty(..), genUnicode, small, unsquare) 44 import TestUtils (withRedirect, withTempFile) 45 46 -- Ensure that two potentially bottom values (in the sense of crashing 47 -- for some inputs, not looping infinitely) either both crash, or both 48 -- give comparable results for some input. 49 (=^=) :: (Eq a, Show a) => a -> a -> Bool 50 {-# NOINLINE (=^=) #-} 51 -- entered 84,300 timesi =^= j = unsafePerformIO $ do 52 x <- try (evaluate i) 53 y <- try (evaluate j) 54 case (x,y) of 55 (Left (_ :: SomeException), Left (_ :: SomeException)) 56 -> return True 57 (Right a, Right b) -> return (a == b) 58 e -> trace ("*** Divergence: " ++ show e) return False 59 infix 4 =^= 60 61 -- entered oncet_pack_unpack = (T.unpack . T.pack) `eq` id 62 -- entered oncetl_pack_unpack = (TL.unpack . TL.pack) `eq` id 63 -- entered oncet_stream_unstream = (S.unstream . S.stream) `eq` id 64 -- entered oncetl_stream_unstream = (SL.unstream . SL.stream) `eq` id 65 -- entered 100 timest_reverse_stream t = (S.reverse . S.reverseStream) t == t 66 -- entered 100 timest_singleton c = [c] == (T.unpack . T.singleton) c 67 -- entered 100 timestl_singleton c = [c] == (TL.unpack . TL.singleton) c 68 -- entered 100 timestl_unstreamChunks x = f 11 x == f 1000 x 69 where f n = SL.unstreamChunks n . S.streamList 70 -- entered oncetl_chunk_unchunk = (TL.fromChunks . TL.toChunks) `eq` id 71 -- entered oncetl_from_to_strict = (TL.fromStrict . TL.toStrict) `eq` id 72 73 -- entered 100 timest_ascii t = E.decodeASCII (E.encodeUtf8 a) == a 74 where a = T.map (\c -> chr (ord c `mod` 128)) t 75 -- entered 100 timestl_ascii t = EL.decodeASCII (EL.encodeUtf8 a) == a 76 where a = TL.map (\c -> chr (ord c `mod` 128)) t 77 -- entered oncet_utf8 = forAll genUnicode $ (E.decodeUtf8 . E.encodeUtf8) `eq` id 78 -- entered oncetl_utf8 = forAll genUnicode $ (EL.decodeUtf8 . EL.encodeUtf8) `eq` id 79 -- entered oncet_utf16LE = forAll genUnicode $ (E.decodeUtf16LE . E.encodeUtf16LE) `eq` id 80 -- entered oncetl_utf16LE = forAll genUnicode $ (EL.decodeUtf16LE . EL.encodeUtf16LE) `eq` id 81 -- entered oncet_utf16BE = forAll genUnicode $ (E.decodeUtf16BE . E.encodeUtf16BE) `eq` id 82 -- entered oncetl_utf16BE = forAll genUnicode $ (EL.decodeUtf16BE . EL.encodeUtf16BE) `eq` id 83 -- entered oncet_utf32LE = forAll genUnicode $ (E.decodeUtf32LE . E.encodeUtf32LE) `eq` id 84 -- entered oncetl_utf32LE = forAll genUnicode $ (EL.decodeUtf32LE . EL.encodeUtf32LE) `eq` id 85 -- entered oncet_utf32BE = forAll genUnicode $ (E.decodeUtf32BE . E.encodeUtf32BE) `eq` id 86 -- entered oncetl_utf32BE = forAll genUnicode $ (EL.decodeUtf32BE . EL.encodeUtf32BE) `eq` id 87 88 data DecodeErr = DE String OnDecodeError 89 90 instance Show DecodeErr where 91 -- never enteredshow (DE d _) = "DE " ++ d 92 93 instance CoArbitrary Word8 where 94 -- entered 302 timescoarbitrary = coarbitraryIntegral 95 96 instance Arbitrary DecodeErr where 97 -- entered oncearbitrary = oneof [ return $ DE "lenient" lenientDecode 98 , return $ DE "ignore" ignore 99 , return $ DE "strict" strictDecode 100 , DE "replace" `fmap` arbitrary ] 101 102 -- This is a poor attempt to ensure that the error handling paths on 103 -- decode are exercised in some way. Proper testing would be rather 104 -- more involved. 105 -- entered 100 timest_utf8_err (DE _ de) bs = monadicIO $ do 106 l <- run $ let len = T.length (E.decodeUtf8With de bs) 107 in (len `seq` return (Right len)) `catch` 108 (\(e::UnicodeException) -> return (Left e)) 109 case l of 110 Left err -> assert $ length (show err) >= 0 111 Right n -> assert $ n >= 0 112 113 class Stringy s where 114 packS :: String -> s 115 unpackS :: s -> String 116 splitAtS :: Int -> s -> (s,s) 117 packSChunkSize :: Int -> String -> s 118 -- entered 13,289 timespackSChunkSize _ = packS 119 120 instance Stringy String where 121 -- entered oncepackS = id 122 -- never enteredunpackS = id 123 -- entered oncesplitAtS = splitAt 124 125 instance Stringy (S.Stream Char) where 126 -- entered 3058 timespackS = S.streamList 127 -- entered 12,407 timesunpackS = S.unstreamList 128 -- entered 6500 timessplitAtS n s = (S.take n s, S.drop n s) 129 130 instance Stringy T.Text where 131 -- entered 5078 timespackS = T.pack 132 -- entered 20,861 timesunpackS = T.unpack 133 -- entered oncesplitAtS = T.splitAt 134 135 instance Stringy TL.Text where 136 -- entered 5830 timespackSChunkSize k = SL.unstreamChunks k . S.streamList 137 -- entered 932 timespackS = TL.pack 138 -- entered 15,265 timesunpackS = TL.unpack 139 -- entered oncesplitAtS = ((TL.lazyInvariant *** TL.lazyInvariant) .) . 140 TL.splitAt . fromIntegral 141 142 -- Do two functions give the same answer? 143 eq :: (Eq a, Show a) => (t -> a) -> (t -> a) -> t -> Bool 144 -- entered 7500 timeseq a b s = a s =^= b s 145 146 -- What about with the RHS packed? 147 eqP :: (Eq a, Show a, Stringy s) => 148 (String -> a) -> (s -> a) -> String -> Word8 -> Bool 149 -- entered 19,200 timeseqP f g s w = eql "orig" (f s) (g t) && 150 eql "mini" (f s) (g mini) && 151 eql "head" (f sa) (g ta) && 152 eql "tail" (f sb) (g tb) 153 where t = packS s 154 mini = packSChunkSize 10 s 155 (sa,sb) = splitAt m s 156 (ta,tb) = splitAtS m t 157 l = length s 158 m | l == 0 = n 159 | otherwise = n `mod` l 160 n = fromIntegral w 161 eql d a b 162 | a =^= b = True 163 | otherwise = trace (d ++ ": " ++ show a ++ " /= " ++ show b) False 164 165 -- entered 100 timess_Eq s = (s==) `eq` ((S.streamList s==) . S.streamList) 166 where _types = s :: String 167 -- entered 100 timessf_Eq p s = 168 ((L.filter p s==) . L.filter p) `eq` 169 (((S.filter p $ S.streamList s)==) . S.filter p . S.streamList) 170 -- entered 100 timest_Eq s = (s==) `eq` ((T.pack s==) . T.pack) 171 -- entered 100 timestl_Eq s = (s==) `eq` ((TL.pack s==) . TL.pack) 172 -- entered 100 timess_Ord s = (compare s) `eq` (compare (S.streamList s) . S.streamList) 173 where _types = s :: String 174 -- entered 100 timessf_Ord p s = 175 ((compare $ L.filter p s) . L.filter p) `eq` 176 (compare (S.filter p $ S.streamList s) . S.filter p . S.streamList) 177 -- entered 100 timest_Ord s = (compare s) `eq` (compare (T.pack s) . T.pack) 178 -- entered 100 timestl_Ord s = (compare s) `eq` (compare (TL.pack s) . TL.pack) 179 -- entered oncet_Read = id `eq` (T.unpack . read . show) 180 -- entered oncetl_Read = id `eq` (TL.unpack . read . show) 181 -- entered oncet_Show = show `eq` (show . T.pack) 182 -- entered oncetl_Show = show `eq` (show . TL.pack) 183 -- entered 100 timest_mappend s = mappend s`eqP` (unpackS . mappend (T.pack s)) 184 -- entered 100 timestl_mappend s = mappend s`eqP` (unpackS . mappend (TL.pack s)) 185 -- entered oncet_mconcat = mconcat `eq` (unpackS . mconcat . L.map T.pack) 186 -- entered oncetl_mconcat = mconcat `eq` (unpackS . mconcat . L.map TL.pack) 187 -- entered oncet_IsString = fromString `eqP` (T.unpack . fromString) 188 -- entered oncetl_IsString = fromString `eqP` (TL.unpack . fromString) 189 190 -- entered 100 timess_cons x = (x:) `eqP` (unpackS . S.cons x) 191 -- entered 100 timess_cons_s x = (x:) `eqP` (unpackS . S.unstream . S.cons x) 192 -- entered 100 timessf_cons p x = ((x:) . L.filter p) `eqP` (unpackS . S.cons x . S.filter p) 193 -- entered 100 timest_cons x = (x:) `eqP` (unpackS . T.cons x) 194 -- entered 100 timestl_cons x = (x:) `eqP` (unpackS . TL.cons x) 195 -- entered 100 timess_snoc x = (++ [x]) `eqP` (unpackS . (flip S.snoc) x) 196 -- entered 100 timest_snoc x = (++ [x]) `eqP` (unpackS . (flip T.snoc) x) 197 -- entered 100 timestl_snoc x = (++ [x]) `eqP` (unpackS . (flip TL.snoc) x) 198 -- entered 100 timess_append s = (s++) `eqP` (unpackS . S.append (S.streamList s)) 199 -- entered 100 timess_append_s s = (s++) `eqP` 200 (unpackS . S.unstream . S.append (S.streamList s)) 201 -- entered 100 timessf_append p s = (L.filter p s++) `eqP` 202 (unpackS . S.append (S.filter p $ S.streamList s)) 203 -- entered 100 timest_append s = (s++) `eqP` (unpackS . T.append (packS s)) 204 205 -- entered 1600 timesuncons (x:xs) = Just (x,xs) 206 uncons _ = Nothing 207 208 -- entered onces_uncons = uncons `eqP` (fmap (second unpackS) . S.uncons) 209 -- entered 100 timessf_uncons p = (uncons . L.filter p) `eqP` 210 (fmap (second unpackS) . S.uncons . S.filter p) 211 -- entered oncet_uncons = uncons `eqP` (fmap (second unpackS) . T.uncons) 212 -- entered oncetl_uncons = uncons `eqP` (fmap (second unpackS) . TL.uncons) 213 -- entered onces_head = head `eqP` S.head 214 -- entered 100 timessf_head p = (head . L.filter p) `eqP` (S.head . S.filter p) 215 -- entered oncet_head = head `eqP` T.head 216 -- entered oncetl_head = head `eqP` TL.head 217 -- entered onces_last = last `eqP` S.last 218 -- entered 100 timessf_last p = (last . L.filter p) `eqP` (S.last . S.filter p) 219 -- entered oncet_last = last `eqP` T.last 220 -- entered oncetl_last = last `eqP` TL.last 221 -- entered onces_tail = tail `eqP` (unpackS . S.tail) 222 -- entered onces_tail_s = tail `eqP` (unpackS . S.unstream . S.tail) 223 -- entered 100 timessf_tail p = (tail . L.filter p) `eqP` (unpackS . S.tail . S.filter p) 224 -- entered oncet_tail = tail `eqP` (unpackS . T.tail) 225 -- entered oncetl_tail = tail `eqP` (unpackS . TL.tail) 226 -- entered onces_init = init `eqP` (unpackS . S.init) 227 -- entered onces_init_s = init `eqP` (unpackS . S.unstream . S.init) 228 -- entered 100 timessf_init p = (init . L.filter p) `eqP` (unpackS . S.init . S.filter p) 229 -- entered oncet_init = init `eqP` (unpackS . T.init) 230 -- entered oncetl_init = init `eqP` (unpackS . TL.init) 231 -- entered onces_null = null `eqP` S.null 232 -- entered 100 timessf_null p = (null . L.filter p) `eqP` (S.null . S.filter p) 233 -- entered oncet_null = null `eqP` T.null 234 -- entered oncetl_null = null `eqP` TL.null 235 -- entered onces_length = length `eqP` S.length 236 -- entered 100 timessf_length p = (length . L.filter p) `eqP` (S.length . S.filter p) 237 -- entered oncesl_length = (fromIntegral . length) `eqP` SL.length 238 -- entered oncet_length = length `eqP` T.length 239 -- entered oncetl_length = L.genericLength `eqP` TL.length 240 -- entered 100 timest_compareLength t = (compare (T.length t)) `eq` T.compareLength t 241 -- entered 100 timestl_compareLength t= (compare (TL.length t)) `eq` TL.compareLength t 242 243 -- entered 100 timess_map f = map f `eqP` (unpackS . S.map f) 244 -- entered 100 timess_map_s f = map f `eqP` (unpackS . S.unstream . S.map f) 245 -- entered 100 timessf_map p f = (map f . L.filter p) `eqP` (unpackS . S.map f . S.filter p) 246 -- entered 100 timest_map f = map f `eqP` (unpackS . T.map f) 247 -- entered 100 timestl_map f = map f `eqP` (unpackS . TL.map f) 248 -- entered 100 timest_intercalate c = L.intercalate c `eq` 249 (unpackS . T.intercalate (packS c) . map packS) 250 -- entered 100 timestl_intercalate c = L.intercalate c `eq` 251 (unpackS . TL.intercalate (TL.pack c) . map TL.pack) 252 -- entered 100 timess_intersperse c = L.intersperse c `eqP` 253 (unpackS . S.intersperse c) 254 -- entered 100 timess_intersperse_s c = L.intersperse c `eqP` 255 (unpackS . S.unstream . S.intersperse c) 256 -- entered 100 timessf_intersperse p c= (L.intersperse c . L.filter p) `eqP` 257 (unpackS . S.intersperse c . S.filter p) 258 -- entered 100 timest_intersperse c = L.intersperse c `eqP` (unpackS . T.intersperse c) 259 -- entered 100 timestl_intersperse c = L.intersperse c `eqP` (unpackS . TL.intersperse c) 260 -- entered oncet_transpose = L.transpose `eq` (map unpackS . T.transpose . map packS) 261 -- entered oncetl_transpose = L.transpose `eq` (map unpackS . TL.transpose . map TL.pack) 262 -- entered oncet_reverse = L.reverse `eqP` (unpackS . T.reverse) 263 -- entered oncetl_reverse = L.reverse `eqP` (unpackS . TL.reverse) 264 -- entered 100 timest_reverse_short n = L.reverse `eqP` (unpackS . S.reverse . shorten n . S.stream) 265 266 -- entered 100 timest_replace s d = (L.intercalate d . split s) `eqP` 267 (unpackS . T.replace (T.pack s) (T.pack d)) 268 -- entered 100 timestl_replace s d = (L.intercalate d . split s) `eqP` 269 (unpackS . TL.replace (TL.pack s) (TL.pack d)) 270 271 split :: (Eq a) => [a] -> [a] -> [[a]] 272 -- entered 800 timessplit pat src0 273 | l == 0 = error "empty" 274 | otherwise = go src0 275 where 276 l = length pat 277 go src = search 0 src 278 where 279 search _ [] = [src] 280 search !n s@(_:s') 281 | pat `L.isPrefixOf` s = take n src : go (drop l s) 282 | otherwise = search (n+1) s' 283 284 -- entered 100 timess_toCaseFold_length xs = S.length (S.toCaseFold s) >= length xs 285 where s = S.streamList xs 286 -- entered 100 timessf_toCaseFold_length p xs = 287 (S.length . S.toCaseFold . S.filter p $ s) >= (length . L.filter p $ xs) 288 where s = S.streamList xs 289 -- entered 100 timest_toCaseFold_length t = T.length (T.toCaseFold t) >= T.length t 290 -- entered 100 timestl_toCaseFold_length t = TL.length (TL.toCaseFold t) >= TL.length t 291 -- entered 100 timest_toLower_length t = T.length (T.toLower t) >= T.length t 292 -- entered 100 timest_toLower_lower t = p (T.toLower t) >= p t 293 where p = T.length . T.filter isLower 294 -- entered 100 timestl_toLower_lower t = p (TL.toLower t) >= p t 295 where p = TL.length . TL.filter isLower 296 -- entered 100 timest_toUpper_length t = T.length (T.toUpper t) >= T.length t 297 -- entered 100 timest_toUpper_upper t = p (T.toUpper t) >= p t 298 where p = T.length . T.filter isUpper 299 -- entered 100 timestl_toUpper_upper t = p (TL.toUpper t) >= p t 300 where p = TL.length . TL.filter isUpper 301 302 -- entered 2000 timesjustifyLeft k c xs = xs ++ L.replicate (k - length xs) c 303 -- entered 800 timesjustifyRight m n xs = L.replicate (m - length xs) n ++ xs 304 -- entered 800 timescenter k c xs 305 | len >= k = xs 306 | otherwise = L.replicate l c ++ xs ++ L.replicate r c 307 where len = length xs 308 d = k - len 309 r = d `div` 2 310 l = d - r 311 312 -- entered 100 timess_justifyLeft k c = justifyLeft j c `eqP` (unpackS . S.justifyLeftI j c) 313 where j = fromIntegral (k :: Word8) 314 -- entered 100 timess_justifyLeft_s k c = justifyLeft j c `eqP` 315 (unpackS . S.unstream . S.justifyLeftI j c) 316 where j = fromIntegral (k :: Word8) 317 -- entered 100 timessf_justifyLeft p k c = (justifyLeft j c . L.filter p) `eqP` 318 (unpackS . S.justifyLeftI j c . S.filter p) 319 where j = fromIntegral (k :: Word8) 320 -- entered 100 timest_justifyLeft k c = justifyLeft j c `eqP` (unpackS . T.justifyLeft j c) 321 where j = fromIntegral (k :: Word8) 322 -- entered 100 timestl_justifyLeft k c = justifyLeft j c `eqP` 323 (unpackS . TL.justifyLeft (fromIntegral j) c) 324 where j = fromIntegral (k :: Word8) 325 -- entered 100 timest_justifyRight k c = justifyRight j c `eqP` (unpackS . T.justifyRight j c) 326 where j = fromIntegral (k :: Word8) 327 -- entered 100 timestl_justifyRight k c = justifyRight j c `eqP` 328 (unpackS . TL.justifyRight (fromIntegral j) c) 329 where j = fromIntegral (k :: Word8) 330 -- entered 100 timest_center k c = center j c `eqP` (unpackS . T.center j c) 331 where j = fromIntegral (k :: Word8) 332 -- entered 100 timestl_center k c = center j c `eqP` (unpackS . TL.center (fromIntegral j) c) 333 where j = fromIntegral (k :: Word8) 334 335 -- entered 100 timessf_foldl p f z = (L.foldl f z . L.filter p) `eqP` (S.foldl f z . S.filter p) 336 where _types = f :: Char -> Char -> Char 337 -- entered 100 timest_foldl f z = L.foldl f z `eqP` (T.foldl f z) 338 where _types = f :: Char -> Char -> Char 339 -- entered 100 timestl_foldl f z = L.foldl f z `eqP` (TL.foldl f z) 340 where _types = f :: Char -> Char -> Char 341 -- entered 100 timessf_foldl' p f z = (L.foldl' f z . L.filter p) `eqP` 342 (S.foldl' f z . S.filter p) 343 where _types = f :: Char -> Char -> Char 344 -- entered 100 timest_foldl' f z = L.foldl' f z `eqP` T.foldl' f z 345 where _types = f :: Char -> Char -> Char 346 -- entered 100 timestl_foldl' f z = L.foldl' f z `eqP` TL.foldl' f z 347 where _types = f :: Char -> Char -> Char 348 -- entered 100 timessf_foldl1 p f = (L.foldl1 f . L.filter p) `eqP` (S.foldl1 f . S.filter p) 349 -- entered 100 timest_foldl1 f = L.foldl1 f `eqP` T.foldl1 f 350 -- entered 100 timestl_foldl1 f = L.foldl1 f `eqP` TL.foldl1 f 351 -- entered 100 timessf_foldl1' p f = (L.foldl1' f . L.filter p) `eqP` (S.foldl1' f . S.filter p) 352 -- entered 100 timest_foldl1' f = L.foldl1' f `eqP` T.foldl1' f 353 -- entered 100 timestl_foldl1' f = L.foldl1' f `eqP` TL.foldl1' f 354 -- entered 100 timessf_foldr p f z = (L.foldr f z . L.filter p) `eqP` (S.foldr f z . S.filter p) 355 where _types = f :: Char -> Char -> Char 356 -- entered 100 timest_foldr f z = L.foldr f z `eqP` T.foldr f z 357 where _types = f :: Char -> Char -> Char 358 -- entered 100 timestl_foldr f z = L.foldr f z `eqP` TL.foldr f z 359 where _types = f :: Char -> Char -> Char 360 -- entered 100 timessf_foldr1 p f = (L.foldr1 f . L.filter p) `eqP` (S.foldr1 f . S.filter p) 361 -- entered 100 timest_foldr1 f = L.foldr1 f `eqP` T.foldr1 f 362 -- entered 100 timestl_foldr1 f = L.foldr1 f `eqP` TL.foldr1 f 363 364 -- entered onces_concat_s = L.concat `eq` (unpackS . S.unstream . S.concat . map packS) 365 -- entered 100 timessf_concat p = (L.concat . map (L.filter p)) `eq` 366 (unpackS . S.concat . map (S.filter p . packS)) 367 -- entered oncet_concat = L.concat `eq` (unpackS . T.concat . map packS) 368 -- entered oncetl_concat = L.concat `eq` (unpackS . TL.concat . map TL.pack) 369 -- entered 100 timessf_concatMap p f = unsquare $ (L.concatMap f . L.filter p) `eqP` 370 (unpackS . S.concatMap (packS . f) . S.filter p) 371 -- entered 100 timest_concatMap f = unsquare $ 372 L.concatMap f `eqP` (unpackS . T.concatMap (packS . f)) 373 -- entered 100 timestl_concatMap f = unsquare $ 374 L.concatMap f `eqP` (unpackS . TL.concatMap (TL.pack . f)) 375 -- entered 100 timessf_any q p = (L.any p . L.filter q) `eqP` (S.any p . S.filter q) 376 -- entered 100 timest_any p = L.any p `eqP` T.any p 377 -- entered 100 timestl_any p = L.any p `eqP` TL.any p 378 -- entered 100 timessf_all q p = (L.all p . L.filter q) `eqP` (S.all p . S.filter q) 379 -- entered 100 timest_all p = L.all p `eqP` T.all p 380 -- entered 100 timestl_all p = L.all p `eqP` TL.all p 381 -- entered 100 timessf_maximum p = (L.maximum . L.filter p) `eqP` (S.maximum . S.filter p) 382 -- entered oncet_maximum = L.maximum `eqP` T.maximum 383 -- entered oncetl_maximum = L.maximum `eqP` TL.maximum 384 -- entered 100 timessf_minimum p = (L.minimum . L.filter p) `eqP` (S.minimum . S.filter p) 385 -- entered oncet_minimum = L.minimum `eqP` T.minimum 386 -- entered oncetl_minimum = L.minimum `eqP` TL.minimum 387 388 -- entered 100 timessf_scanl p f z = (L.scanl f z . L.filter p) `eqP` 389 (unpackS . S.scanl f z . S.filter p) 390 -- entered 100 timest_scanl f z = L.scanl f z `eqP` (unpackS . T.scanl f z) 391 -- entered 100 timestl_scanl f z = L.scanl f z `eqP` (unpackS . TL.scanl f z) 392 -- entered 100 timest_scanl1 f = L.scanl1 f `eqP` (unpackS . T.scanl1 f) 393 -- entered 100 timestl_scanl1 f = L.scanl1 f `eqP` (unpackS . TL.scanl1 f) 394 -- entered 100 timest_scanr f z = L.scanr f z `eqP` (unpackS . T.scanr f z) 395 -- entered 100 timestl_scanr f z = L.scanr f z `eqP` (unpackS . TL.scanr f z) 396 -- entered 100 timest_scanr1 f = L.scanr1 f `eqP` (unpackS . T.scanr1 f) 397 -- entered 100 timestl_scanr1 f = L.scanr1 f `eqP` (unpackS . TL.scanr1 f) 398 399 -- entered 100 timest_mapAccumL f z = L.mapAccumL f z `eqP` (second unpackS . T.mapAccumL f z) 400 where _types = f :: Int -> Char -> (Int,Char) 401 -- entered 100 timestl_mapAccumL f z = L.mapAccumL f z `eqP` (second unpackS . TL.mapAccumL f z) 402 where _types = f :: Int -> Char -> (Int,Char) 403 -- entered 100 timest_mapAccumR f z = L.mapAccumR f z `eqP` (second unpackS . T.mapAccumR f z) 404 where _types = f :: Int -> Char -> (Int,Char) 405 -- entered 100 timestl_mapAccumR f z = L.mapAccumR f z `eqP` (second unpackS . TL.mapAccumR f z) 406 where _types = f :: Int -> Char -> (Int,Char) 407 408 -- entered 200 timesreplicate n l = concat (L.replicate n l) 409 410 -- entered 100 timest_replicate n = replicate m `eq` (unpackS . T.replicate m . packS) 411 where m = fromIntegral (n :: Word8) 412 -- entered 100 timestl_replicate n = replicate m `eq` 413 (unpackS . TL.replicate (fromIntegral m) . packS) 414 where m = fromIntegral (n :: Word8) 415 416 unf :: Int -> Char -> Maybe (Char, Char) 417 -- entered 194,385 timesunf n c | fromEnum c * 100 > n = Nothing 418 | otherwise = Just (c, succ c) 419 420 -- entered 100 timest_unfoldr n = L.unfoldr (unf m) `eq` (unpackS . T.unfoldr (unf m)) 421 where m = fromIntegral (n :: Word16) 422 -- entered 100 timestl_unfoldr n = L.unfoldr (unf m) `eq` (unpackS . TL.unfoldr (unf m)) 423 where m = fromIntegral (n :: Word16) 424 -- entered 100 timest_unfoldrN n m = (L.take i . L.unfoldr (unf j)) `eq` 425 (unpackS . T.unfoldrN i (unf j)) 426 where i = fromIntegral (n :: Word16) 427 j = fromIntegral (m :: Word16) 428 -- entered 100 timestl_unfoldrN n m = (L.take i . L.unfoldr (unf j)) `eq` 429 (unpackS . TL.unfoldrN (fromIntegral i) (unf j)) 430 where i = fromIntegral (n :: Word16) 431 j = fromIntegral (m :: Word16) 432 433 unpack2 :: (Stringy s) => (s,s) -> (String,String) 434 -- entered 3200 timesunpack2 = unpackS *** unpackS 435 436 -- entered 100 timess_take n = L.take n `eqP` (unpackS . S.take n) 437 -- entered 100 timess_take_s m = L.take n `eqP` (unpackS . S.unstream . S.take n) 438 where n = small m 439 -- entered 100 timessf_take p n = (L.take n . L.filter p) `eqP` 440 (unpackS . S.take n . S.filter p) 441 -- entered 100 timest_take n = L.take n `eqP` (unpackS . T.take n) 442 -- entered 100 timestl_take n = L.take n `eqP` (unpackS . TL.take (fromIntegral n)) 443 -- entered 100 timess_drop n = L.drop n `eqP` (unpackS . S.drop n) 444 -- entered 100 timess_drop_s m = L.drop n `eqP` (unpackS . S.unstream . S.drop n) 445 where n = small m 446 -- entered 100 timessf_drop p n = (L.drop n . L.filter p) `eqP` 447 (unpackS . S.drop n . S.filter p) 448 -- entered 100 timest_drop n = L.drop n `eqP` (unpackS . T.drop n) 449 -- entered 100 timestl_drop n = L.drop n `eqP` (unpackS . TL.drop (fromIntegral n)) 450 -- entered 100 timess_take_drop m = (L.take n . L.drop n) `eqP` (unpackS . S.take n . S.drop n) 451 where n = small m 452 -- entered 100 timess_take_drop_s m = (L.take n . L.drop n) `eqP` 453 (unpackS . S.unstream . S.take n . S.drop n) 454 where n = small m 455 -- entered 100 timess_takeWhile p = L.takeWhile p `eqP` (unpackS . S.takeWhile p) 456 -- entered 100 timess_takeWhile_s p = L.takeWhile p `eqP` (unpackS . S.unstream . S.takeWhile p) 457 -- entered 100 timessf_takeWhile q p = (L.takeWhile p . L.filter q) `eqP` 458 (unpackS . S.takeWhile p . S.filter q) 459 -- entered 100 timest_takeWhile p = L.takeWhile p `eqP` (unpackS . T.takeWhile p) 460 -- entered 100 timestl_takeWhile p = L.takeWhile p `eqP` (unpackS . TL.takeWhile p) 461 -- entered 100 timess_dropWhile p = L.dropWhile p `eqP` (unpackS . S.dropWhile p) 462 -- entered 100 timess_dropWhile_s p = L.dropWhile p `eqP` (unpackS . S.unstream . S.dropWhile p) 463 -- entered 100 timessf_dropWhile q p = (L.dropWhile p . L.filter q) `eqP` 464 (unpackS . S.dropWhile p . S.filter q) 465 -- entered 100 timest_dropWhile p = L.dropWhile p `eqP` (unpackS . T.dropWhile p) 466 -- entered 100 timestl_dropWhile p = L.dropWhile p `eqP` (unpackS . S.dropWhile p) 467 -- entered 100 timest_dropWhileEnd p = (L.reverse . L.dropWhile p . L.reverse) `eqP` 468 (unpackS . T.dropWhileEnd p) 469 -- entered 100 timestl_dropWhileEnd p = (L.reverse . L.dropWhile p . L.reverse) `eqP` 470 (unpackS . TL.dropWhileEnd p) 471 -- entered 100 timest_dropAround p = (L.dropWhile p . L.reverse . L.dropWhile p . L.reverse) 472 `eqP` (unpackS . T.dropAround p) 473 -- entered 100 timestl_dropAround p = (L.dropWhile p . L.reverse . L.dropWhile p . L.reverse) 474 `eqP` (unpackS . TL.dropAround p) 475 -- entered oncet_stripStart = T.dropWhile isSpace `eq` T.stripStart 476 -- entered oncetl_stripStart = TL.dropWhile isSpace `eq` TL.stripStart 477 -- entered oncet_stripEnd = T.dropWhileEnd isSpace `eq` T.stripEnd 478 -- entered oncetl_stripEnd = TL.dropWhileEnd isSpace `eq` TL.stripEnd 479 -- entered oncet_strip = T.dropAround isSpace `eq` T.strip 480 -- entered oncetl_strip = TL.dropAround isSpace `eq` TL.strip 481 -- entered 100 timest_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n) 482 -- entered 100 timestl_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt (fromIntegral n)) 483 -- entered 100 timest_spanBy p = L.span p `eqP` (unpack2 . T.spanBy p) 484 -- entered 100 timestl_spanBy p = L.span p `eqP` (unpack2 . TL.spanBy p) 485 486 -- entered 100 timest_break_id s = squid `eq` (uncurry T.append . T.break s) 487 where squid t | T.null s = error "empty" 488 | otherwise = t 489 -- entered 100 timestl_break_id s = squid `eq` (uncurry TL.append . TL.break s) 490 where squid t | TL.null s = error "empty" 491 | otherwise = t 492 -- entered 100 timest_break_start (NotEmpty s) t = let (_,m) = T.break s t 493 in T.null m || s `T.isPrefixOf` m 494 -- entered 100 timestl_break_start (NotEmpty s) t = let (_,m) = TL.break s t 495 in TL.null m || s `TL.isPrefixOf` m 496 -- entered 100 timest_breakEnd_end (NotEmpty s) t = let (m,_) = T.breakEnd s t 497 in T.null m || s `T.isSuffixOf` m 498 -- entered 100 timestl_breakEnd_end (NotEmpty s) t = let (m,_) = TL.breakEnd s t 499 in TL.null m || s `TL.isSuffixOf` m 500 -- entered 100 timest_breakBy p = L.break p `eqP` (unpack2 . T.breakBy p) 501 -- entered 100 timestl_breakBy p = L.break p `eqP` (unpack2 . TL.breakBy p) 502 -- entered oncet_group = L.group `eqP` (map unpackS . T.group) 503 -- entered oncetl_group = L.group `eqP` (map unpackS . TL.group) 504 -- entered 100 timest_groupBy p = L.groupBy p `eqP` (map unpackS . T.groupBy p) 505 -- entered 100 timestl_groupBy p = L.groupBy p `eqP` (map unpackS . TL.groupBy p) 506 -- entered oncet_inits = L.inits `eqP` (map unpackS . T.inits) 507 -- entered oncetl_inits = L.inits `eqP` (map unpackS . TL.inits) 508 -- entered oncet_tails = L.tails `eqP` (map unpackS . T.tails) 509 -- entered oncetl_tails = L.tails `eqP` (map unpackS . TL.tails) 510 -- entered 100 timest_findAppendId (NotEmpty s) = unsquare $ \ts -> 511 let t = T.intercalate s ts 512 in all (==t) $ map (uncurry T.append) (T.find s t) 513 -- entered 100 timestl_findAppendId (NotEmpty s) = unsquare $ \ts -> 514 let t = TL.intercalate s ts 515 in all (==t) $ map (uncurry TL.append) (TL.find s t) 516 -- entered 100 timest_findContains (NotEmpty s) = all (T.isPrefixOf s . snd) . T.find s . 517 T.intercalate s 518 -- entered 100 timestl_findContains (NotEmpty s) = all (TL.isPrefixOf s . snd) . 519 TL.find s . TL.intercalate s 520 -- entered 100 timessl_filterCount c = (L.genericLength . L.filter (==c)) `eqP` SL.countChar c 521 -- entered 100 timest_findCount s = (L.length . T.find s) `eq` T.count s 522 -- entered 100 timestl_findCount s = (L.genericLength . TL.find s) `eq` TL.count s 523 524 -- entered 100 timest_split_split s = (T.split s `eq` Slow.split s) . T.intercalate s 525 -- entered 100 timestl_split_split s = ((TL.split (TL.fromStrict s) . TL.fromStrict) `eq` 526 (map TL.fromStrict . T.split s)) . T.intercalate s 527 -- entered 100 timest_split_i (NotEmpty t) = id `eq` (T.intercalate t . T.split t) 528 -- entered 100 timestl_split_i (NotEmpty t) = id `eq` (TL.intercalate t . TL.split t) 529 530 -- entered 100 timest_splitBy p = splitBy p `eqP` (map unpackS . T.splitBy p) 531 -- entered 100 timest_splitBy_count c = (L.length . T.splitBy (==c)) `eq` 532 ((1+) . T.count (T.singleton c)) 533 -- entered 100 timest_splitBy_split c = T.splitBy (==c) `eq` T.split (T.singleton c) 534 -- entered 100 timestl_splitBy p = splitBy p `eqP` (map unpackS . TL.splitBy p) 535 536 splitBy :: (a -> Bool) -> [a] -> [[a]] 537 -- entered 800 timessplitBy _ [] = [[]] 538 splitBy p xs = loop xs 539 where loop s | null s' = [l] 540 | otherwise = l : loop (tail s') 541 where (l, s') = break p s 542 543 -- entered 100 timest_chunksOf_same_lengths k = all ((==k) . T.length) . ini . T.chunksOf k 544 where ini [] = [] 545 ini xs = init xs 546 547 -- entered 100 timest_chunksOf_length k t = len == T.length t || (k <= 0 && len == 0) 548 where len = L.sum . L.map T.length $ T.chunksOf k t 549 550 -- entered 100 timestl_chunksOf k = T.chunksOf k `eq` (map (T.concat . TL.toChunks) . 551 TL.chunksOf (fromIntegral k) . TL.fromStrict) 552 553 -- entered oncet_lines = L.lines `eqP` (map unpackS . T.lines) 554 -- entered oncetl_lines = L.lines `eqP` (map unpackS . TL.lines) 555 {- 556 t_lines' = lines' `eqP` (map unpackS . T.lines') 557 where lines' "" = [] 558 lines' s = let (l, s') = break eol s 559 in l : case s' of 560 [] -> [] 561 ('\r':'\n':s'') -> lines' s'' 562 (_:s'') -> lines' s'' 563 eol c = c == '\r' || c == '\n' 564 -} 565 -- entered oncet_words = L.words `eqP` (map unpackS . T.words) 566 567 -- entered oncetl_words = L.words `eqP` (map unpackS . TL.words) 568 -- entered oncet_unlines = L.unlines `eq` (unpackS . T.unlines . map packS) 569 -- entered oncetl_unlines = L.unlines `eq` (unpackS . TL.unlines . map packS) 570 -- entered oncet_unwords = L.unwords `eq` (unpackS . T.unwords . map packS) 571 -- entered oncetl_unwords = L.unwords `eq` (unpackS . TL.unwords . map packS) 572 573 -- entered 100 timess_isPrefixOf s = L.isPrefixOf s `eqP` 574 (S.isPrefixOf (S.stream $ packS s) . S.stream) 575 -- entered 100 timessf_isPrefixOf p s = (L.isPrefixOf s . L.filter p) `eqP` 576 (S.isPrefixOf (S.stream $ packS s) . S.filter p . S.stream) 577 -- entered 100 timest_isPrefixOf s = L.isPrefixOf s`eqP` T.isPrefixOf (packS s) 578 -- entered 100 timestl_isPrefixOf s = L.isPrefixOf s`eqP` TL.isPrefixOf (packS s) 579 -- entered 100 timest_isSuffixOf s = L.isSuffixOf s`eqP` T.isSuffixOf (packS s) 580 -- entered 100 timestl_isSuffixOf s = L.isSuffixOf s`eqP` TL.isSuffixOf (packS s) 581 -- entered 100 timest_isInfixOf s = L.isInfixOf s `eqP` T.isInfixOf (packS s) 582 -- entered 100 timestl_isInfixOf s = L.isInfixOf s `eqP` TL.isInfixOf (packS s) 583 584 -- entered 1600 timesprefixed (p:ps) (t:ts) 585 | p == t = prefixed ps ts 586 prefixed [] ts = Just ts 587 prefixed _ _ = Nothing 588 589 -- entered 100 timest_prefixed s = (fmap packS . prefixed s) `eqP` T.prefixed (packS s) 590 -- entered 100 timestl_prefixed s = (fmap packS . prefixed s) `eqP` TL.prefixed (packS s) 591 592 -- entered 800 timessuffixed p t = reverse `fmap` prefixed (reverse p) (reverse t) 593 594 -- entered 100 timest_suffixed s = (fmap packS . suffixed s) `eqP` T.suffixed (packS s) 595 -- entered 100 timestl_suffixed s = (fmap packS . suffixed s) `eqP` TL.suffixed (packS s) 596 597 -- entered 100 timessf_elem p c = (L.elem c . L.filter p) `eqP` (S.elem c . S.filter p) 598 -- entered 100 timessf_filter q p = (L.filter p . L.filter q) `eqP` 599 (unpackS . S.filter p . S.filter q) 600 -- entered 100 timest_filter p = L.filter p `eqP` (unpackS . T.filter p) 601 -- entered 100 timestl_filter p = L.filter p `eqP` (unpackS . TL.filter p) 602 -- entered 100 timessf_findBy q p = (L.find p . L.filter q) `eqP` (S.findBy p . S.filter q) 603 -- entered 100 timest_findBy p = L.find p `eqP` T.findBy p 604 -- entered 100 timestl_findBy p = L.find p `eqP` TL.findBy p 605 -- entered 100 timest_partition p = L.partition p `eqP` (unpack2 . T.partitionBy p) 606 -- entered 100 timestl_partition p = L.partition p `eqP` (unpack2 . TL.partitionBy p) 607 608 -- entered 100 timessf_index p s = forAll (choose (-l,l*2)) 609 ((L.filter p s L.!!) `eq` S.index (S.filter p $ packS s)) 610 where l = L.length s 611 -- entered 100 timest_index s = forAll (choose (-l,l*2)) ((s L.!!) `eq` T.index (packS s)) 612 where l = L.length s 613 614 -- entered 100 timestl_index s = forAll (choose (-l,l*2)) 615 ((s L.!!) `eq` (TL.index (packS s) . fromIntegral)) 616 where l = L.length s 617 618 -- entered 100 timest_findIndex p = L.findIndex p `eqP` T.findIndex p 619 -- entered 100 timest_count (NotEmpty t) = (subtract 1 . L.length . T.split t) `eq` T.count t 620 -- entered 100 timestl_count (NotEmpty t) = (subtract 1 . L.genericLength . TL.split t) `eq` 621 TL.count t 622 -- entered 100 timest_zip s = L.zip s `eqP` T.zip (packS s) 623 -- entered 100 timestl_zip s = L.zip s `eqP` TL.zip (packS s) 624 -- entered 100 timessf_zipWith p c s = (L.zipWith c (L.filter p s) . L.filter p) `eqP` 625 (unpackS . S.zipWith c (S.filter p $ packS s) . S.filter p) 626 -- entered 100 timest_zipWith c s = L.zipWith c s `eqP` (unpackS . T.zipWith c (packS s)) 627 -- entered 100 timestl_zipWith c s = L.zipWith c s `eqP` (unpackS . TL.zipWith c (packS s)) 628 629 -- entered 100 timest_indices (NotEmpty s) = Slow.indices s `eq` indices s 630 -- entered 100 timestl_indices (NotEmpty s) = lazyIndices s `eq` S.indices s 631 where lazyIndices ss t = map fromIntegral $ Slow.indices (conc ss) (conc t) 632 conc = T.concat . TL.toChunks 633 -- entered 100 timest_indices_occurs (NotEmpty t) ts = let s = T.intercalate t ts 634 in Slow.indices t s == indices t s 635 636 -- Bit shifts. 637 -- entered 300 timesshiftL w = forAll (choose (0,width-1)) $ \k -> Bits.shiftL w k == U.shiftL w k 638 where width = round (log (fromIntegral m) / log 2 :: Double) 639 (m,_) = (maxBound, m == w) 640 -- entered 300 timesshiftR w = forAll (choose (0,width-1)) $ \k -> Bits.shiftR w k == U.shiftR w k 641 where width = round (log (fromIntegral m) / log 2 :: Double) 642 (m,_) = (maxBound, m == w) 643 644 -- entered onceshiftL_Int = shiftL :: Int -> Property 645 -- entered onceshiftL_Word16 = shiftL :: Word16 -> Property 646 -- entered onceshiftL_Word32 = shiftL :: Word32 -> Property 647 -- entered onceshiftR_Int = shiftR :: Int -> Property 648 -- entered onceshiftR_Word16 = shiftR :: Word16 -> Property 649 -- entered onceshiftR_Word32 = shiftR :: Word32 -> Property 650 651 -- Builder. 652 653 -- entered oncet_builderSingleton = id `eqP` 654 (unpackS . TB.toLazyText . mconcat . map TB.singleton) 655 -- entered oncet_builderFromText = L.concat `eq` (unpackS . TB.toLazyText . mconcat . 656 map (TB.fromText . packS)) 657 -- entered 100 timest_builderAssociative s1 s2 s3 = 658 TB.toLazyText (b1 `mappend` (b2 `mappend` b3)) == 659 TB.toLazyText ((b1 `mappend` b2) `mappend` b3) 660 where b1 = TB.fromText (packS s1) 661 b2 = TB.fromText (packS s2) 662 b3 = TB.fromText (packS s3) 663 664 -- Input and output. 665 666 -- Work around lack of Show instance for TextEncoding. 667 data Encoding = E String TextEncoding 668 669 instance Show Encoding where -- never enteredshow (E n _) = "utf" ++ n 670 671 instance Arbitrary Encoding where 672 -- entered oncearbitrary = oneof . map return $ 673 [ E "8" utf8, E "8_bom" utf8_bom, E "16" utf16, E "16le" utf16le, 674 E "16be" utf16be, E "32" utf32, E "32le" utf32le, E "32be" utf32be ] 675 676 -- entered oncewindowsNewlineMode = NewlineMode { inputNL = CRLF, outputNL = CRLF } 677 678 instance Show Newline where 679 -- never enteredshow CRLF = "CRLF" 680 show LF = "LF" 681 682 instance Show NewlineMode where 683 -- never enteredshow (NewlineMode i o) = "NewlineMode { inputNL = " ++ show i ++ 684 ", outputNL = " ++ show o ++ " }" 685 686 instance Arbitrary NewlineMode where 687 -- entered oncearbitrary = oneof . map return $ 688 [ noNewlineTranslation, universalNewlineMode, nativeNewlineMode, 689 windowsNewlineMode ] 690 691 instance Arbitrary BufferMode where 692 -- entered oncearbitrary = oneof [ return NoBuffering, 693 return LineBuffering, 694 return (BlockBuffering Nothing), 695 (BlockBuffering . Just . (+1) . fromIntegral) `fmap` 696 (arbitrary :: Gen Word16) ] 697 698 -- This test harness is complex! What property are we checking? 699 -- 700 -- Reading after writing a multi-line file should give the same 701 -- results as were written. 702 -- 703 -- What do we vary while checking this property? 704 -- * The lines themselves, scrubbed to contain neither CR nor LF. (By 705 -- working with a list of lines, we ensure that the data will 706 -- sometimes contain line endings.) 707 -- * Encoding. 708 -- * Newline translation mode. 709 -- * Buffering. 710 -- entered 400 timeswrite_read unline filt writer reader (E _ enc) nl buf ts = 711 monadicIO $ assert . (==t) =<< run act 712 where t = unline . map (filt (not . (`elem` "\r\n"))) $ ts 713 act = withTempFile $ \path h -> do 714 hSetEncoding h enc 715 hSetNewlineMode h nl 716 hSetBuffering h buf 717 () <- writer h t 718 hClose h 719 bracket (openFile path ReadMode) hClose $ \h' -> do 720 hSetEncoding h' enc 721 hSetNewlineMode h' nl 722 hSetBuffering h' buf 723 r <- reader h' 724 r `deepseq` return r 725 726 -- never enteredt_put_get = write_read T.unlines T.filter put get 727 where put h = withRedirect h stdout . T.putStr 728 get h = withRedirect h stdin T.getContents 729 -- never enteredtl_put_get = write_read TL.unlines TL.filter put get 730 where put h = withRedirect h stdout . TL.putStr 731 get h = withRedirect h stdin TL.getContents 732 -- entered oncet_write_read = write_read T.unlines T.filter T.hPutStr T.hGetContents 733 -- entered oncetl_write_read = write_read TL.unlines TL.filter TL.hPutStr TL.hGetContents 734 735 -- entered 100 timest_write_read_line e m b t = write_read head T.filter T.hPutStrLn 736 T.hGetLine e m b [t] 737 -- entered 100 timestl_write_read_line e m b t = write_read head TL.filter TL.hPutStrLn 738 TL.hGetLine e m b [t] 739 740 -- Low-level. 741 742 -- entered 100 timest_dropWord16 m t = dropWord16 m t `T.isSuffixOf` t 743 -- entered 100 timest_takeWord16 m t = takeWord16 m t `T.isPrefixOf` t 744 -- entered 100 timest_take_drop_16 m t = T.append (takeWord16 n t) (dropWord16 n t) == t 745 where n = small m 746 -- entered 100 timest_use_from t = monadicIO $ assert . (==t) =<< run (useAsPtr t fromPtr) 747 748 -- Regression tests. 749 -- entered 100 timess_filter_eq s = S.filter p t == S.streamList (filter p s) 750 where p = (/= S.last t) 751 t = S.streamList s 752 753 -- Make a stream appear shorter than it really is, to ensure that 754 -- functions that consume inaccurately sized streams behave 755 -- themselves. 756 shorten :: Int -> S.Stream a -> S.Stream a 757 -- entered 400 timesshorten n t@(S.Stream arr off len) 758 | n > 0 = S.Stream arr off (smaller (exactSize n) len) 759 | otherwise = t 760 761 -- entered oncemain = defaultMain tests 762 763 -- entered oncetests = [ 764 testGroup "creation/elimination" [ 765 testProperty "t_pack_unpack" t_pack_unpack, 766 testProperty "tl_pack_unpack" tl_pack_unpack, 767 testProperty "t_stream_unstream" t_stream_unstream, 768 testProperty "tl_stream_unstream" tl_stream_unstream, 769 testProperty "t_reverse_stream" t_reverse_stream, 770 testProperty "t_singleton" t_singleton, 771 testProperty "tl_singleton" tl_singleton, 772 testProperty "tl_unstreamChunks" tl_unstreamChunks, 773 testProperty "tl_chunk_unchunk" tl_chunk_unchunk, 774 testProperty "tl_from_to_strict" tl_from_to_strict 775 ], 776 777 testGroup "transcoding" [ 778 testProperty "t_ascii" t_ascii, 779 testProperty "tl_ascii" tl_ascii, 780 testProperty "t_utf8" t_utf8, 781 testProperty "tl_utf8" tl_utf8, 782 testProperty "t_utf16LE" t_utf16LE, 783 testProperty "tl_utf16LE" tl_utf16LE, 784 testProperty "t_utf16BE" t_utf16BE, 785 testProperty "tl_utf16BE" tl_utf16BE, 786 testProperty "t_utf32LE" t_utf32LE, 787 testProperty "tl_utf32LE" tl_utf32LE, 788 testProperty "t_utf32BE" t_utf32BE, 789 testProperty "tl_utf32BE" tl_utf32BE, 790 testGroup "errors" [ 791 testProperty "t_utf8_err" t_utf8_err 792 ] 793 ], 794 795 testGroup "instances" [ 796 testProperty "s_Eq" s_Eq, 797 testProperty "sf_Eq" sf_Eq, 798 testProperty "t_Eq" t_Eq, 799 testProperty "tl_Eq" tl_Eq, 800 testProperty "s_Ord" s_Ord, 801 testProperty "sf_Ord" sf_Ord, 802 testProperty "t_Ord" t_Ord, 803 testProperty "tl_Ord" tl_Ord, 804 testProperty "t_Read" t_Read, 805 testProperty "tl_Read" tl_Read, 806 testProperty "t_Show" t_Show, 807 testProperty "tl_Show" tl_Show, 808 testProperty "t_mappend" t_mappend, 809 testProperty "tl_mappend" tl_mappend, 810 testProperty "t_mconcat" t_mconcat, 811 testProperty "tl_mconcat" tl_mconcat, 812 testProperty "t_IsString" t_IsString, 813 testProperty "tl_IsString" tl_IsString 814 ], 815 816 testGroup "basics" [ 817 testProperty "s_cons" s_cons, 818 testProperty "s_cons_s" s_cons_s, 819 testProperty "sf_cons" sf_cons, 820 testProperty "t_cons" t_cons, 821 testProperty "tl_cons" tl_cons, 822 testProperty "s_snoc" s_snoc, 823 testProperty "t_snoc" t_snoc, 824 testProperty "tl_snoc" tl_snoc, 825 testProperty "s_append" s_append, 826 testProperty "s_append_s" s_append_s, 827 testProperty "sf_append" sf_append, 828 testProperty "t_append" t_append, 829 testProperty "s_uncons" s_uncons, 830 testProperty "sf_uncons" sf_uncons, 831 testProperty "t_uncons" t_uncons, 832 testProperty "tl_uncons" tl_uncons, 833 testProperty "s_head" s_head, 834 testProperty "sf_head" sf_head, 835 testProperty "t_head" t_head, 836 testProperty "tl_head" tl_head, 837 testProperty "s_last" s_last, 838 testProperty "sf_last" sf_last, 839 testProperty "t_last" t_last, 840 testProperty "tl_last" tl_last, 841 testProperty "s_tail" s_tail, 842 testProperty "s_tail_s" s_tail_s, 843 testProperty "sf_tail" sf_tail, 844 testProperty "t_tail" t_tail, 845 testProperty "tl_tail" tl_tail, 846 testProperty "s_init" s_init, 847 testProperty "s_init_s" s_init_s, 848 testProperty "sf_init" sf_init, 849 testProperty "t_init" t_init, 850 testProperty "tl_init" tl_init, 851 testProperty "s_null" s_null, 852 testProperty "sf_null" sf_null, 853 testProperty "t_null" t_null, 854 testProperty "tl_null" tl_null, 855 testProperty "s_length" s_length, 856 testProperty "sf_length" sf_length, 857 testProperty "sl_length" sl_length, 858 testProperty "t_length" t_length, 859 testProperty "tl_length" tl_length, 860 testProperty "t_compareLength" t_compareLength, 861 testProperty "tl_compareLength" tl_compareLength 862 ], 863 864 testGroup "transformations" [ 865 testProperty "s_map" s_map, 866 testProperty "s_map_s" s_map_s, 867 testProperty "sf_map" sf_map, 868 testProperty "t_map" t_map, 869 testProperty "tl_map" tl_map, 870 testProperty "t_intercalate" t_intercalate, 871 testProperty "tl_intercalate" tl_intercalate, 872 testProperty "s_intersperse" s_intersperse, 873 testProperty "s_intersperse_s" s_intersperse_s, 874 testProperty "sf_intersperse" sf_intersperse, 875 testProperty "t_intersperse" t_intersperse, 876 testProperty "tl_intersperse" tl_intersperse, 877 testProperty "t_transpose" t_transpose, 878 testProperty "tl_transpose" tl_transpose, 879 testProperty "t_reverse" t_reverse, 880 testProperty "tl_reverse" tl_reverse, 881 testProperty "t_reverse_short" t_reverse_short, 882 testProperty "t_replace" t_replace, 883 testProperty "tl_replace" tl_replace, 884 885 testGroup "case conversion" [ 886 testProperty "s_toCaseFold_length" s_toCaseFold_length, 887 testProperty "sf_toCaseFold_length" sf_toCaseFold_length, 888 testProperty "t_toCaseFold_length" t_toCaseFold_length, 889 testProperty "tl_toCaseFold_length" tl_toCaseFold_length, 890 testProperty "t_toLower_length" t_toLower_length, 891 testProperty "t_toLower_lower" t_toLower_lower, 892 testProperty "tl_toLower_lower" tl_toLower_lower, 893 testProperty "t_toUpper_length" t_toUpper_length, 894 testProperty "t_toUpper_upper" t_toUpper_upper, 895 testProperty "tl_toUpper_upper" tl_toUpper_upper 896 ], 897 898 testGroup "justification" [ 899 testProperty "s_justifyLeft" s_justifyLeft, 900 testProperty "s_justifyLeft_s" s_justifyLeft_s, 901 testProperty "sf_justifyLeft" sf_justifyLeft, 902 testProperty "t_justifyLeft" t_justifyLeft, 903 testProperty "tl_justifyLeft" tl_justifyLeft, 904 testProperty "t_justifyRight" t_justifyRight, 905 testProperty "tl_justifyRight" tl_justifyRight, 906 testProperty "t_center" t_center, 907 testProperty "tl_center" tl_center 908 ] 909 ], 910 911 testGroup "folds" [ 912 testProperty "sf_foldl" sf_foldl, 913 testProperty "t_foldl" t_foldl, 914 testProperty "tl_foldl" tl_foldl, 915 testProperty "sf_foldl'" sf_foldl', 916 testProperty "t_foldl'" t_foldl', 917 testProperty "tl_foldl'" tl_foldl', 918 testProperty "sf_foldl1" sf_foldl1, 919 testProperty "t_foldl1" t_foldl1, 920 testProperty "tl_foldl1" tl_foldl1, 921 testProperty "t_foldl1'" t_foldl1', 922 testProperty "sf_foldl1'" sf_foldl1', 923 testProperty "tl_foldl1'" tl_foldl1', 924 testProperty "sf_foldr" sf_foldr, 925 testProperty "t_foldr" t_foldr, 926 testProperty "tl_foldr" tl_foldr, 927 testProperty "sf_foldr1" sf_foldr1, 928 testProperty "t_foldr1" t_foldr1, 929 testProperty "tl_foldr1" tl_foldr1, 930 931 testGroup "special" [ 932 testProperty "s_concat_s" s_concat_s, 933 testProperty "sf_concat" sf_concat, 934 testProperty "t_concat" t_concat, 935 testProperty "tl_concat" tl_concat, 936 testProperty "sf_concatMap" sf_concatMap, 937 testProperty "t_concatMap" t_concatMap, 938 testProperty "tl_concatMap" tl_concatMap, 939 testProperty "sf_any" sf_any, 940 testProperty "t_any" t_any, 941 testProperty "tl_any" tl_any, 942 testProperty "sf_all" sf_all, 943 testProperty "t_all" t_all, 944 testProperty "tl_all" tl_all, 945 testProperty "sf_maximum" sf_maximum, 946 testProperty "t_maximum" t_maximum, 947 testProperty "tl_maximum" tl_maximum, 948 testProperty "sf_minimum" sf_minimum, 949 testProperty "t_minimum" t_minimum, 950 testProperty "tl_minimum" tl_minimum 951 ] 952 ], 953 954 testGroup "construction" [ 955 testGroup "scans" [ 956 testProperty "sf_scanl" sf_scanl, 957 testProperty "t_scanl" t_scanl, 958 testProperty "tl_scanl" tl_scanl, 959 testProperty "t_scanl1" t_scanl1, 960 testProperty "tl_scanl1" tl_scanl1, 961 testProperty "t_scanr" t_scanr, 962 testProperty "tl_scanr" tl_scanr, 963 testProperty "t_scanr1" t_scanr1, 964 testProperty "tl_scanr1" tl_scanr1 965 ], 966 967 testGroup "mapAccum" [ 968 testProperty "t_mapAccumL" t_mapAccumL, 969 testProperty "tl_mapAccumL" tl_mapAccumL, 970 testProperty "t_mapAccumR" t_mapAccumR, 971 testProperty "tl_mapAccumR" tl_mapAccumR 972 ], 973 974 testGroup "unfolds" [ 975 testProperty "t_replicate" t_replicate, 976 testProperty "tl_replicate" tl_replicate, 977 testProperty "t_unfoldr" t_unfoldr, 978 testProperty "tl_unfoldr" tl_unfoldr, 979 testProperty "t_unfoldrN" t_unfoldrN, 980 testProperty "tl_unfoldrN" tl_unfoldrN 981 ] 982 ], 983 984 testGroup "substrings" [ 985 testGroup "breaking" [ 986 testProperty "s_take" s_take, 987 testProperty "s_take_s" s_take_s, 988 testProperty "sf_take" sf_take, 989 testProperty "t_take" t_take, 990 testProperty "tl_take" tl_take, 991 testProperty "s_drop" s_drop, 992 testProperty "s_drop_s" s_drop_s, 993 testProperty "sf_drop" sf_drop, 994 testProperty "t_drop" t_drop, 995 testProperty "tl_drop" tl_drop, 996 testProperty "s_take_drop" s_take_drop, 997 testProperty "s_take_drop_s" s_take_drop_s, 998 testProperty "s_takeWhile" s_takeWhile, 999 testProperty "s_takeWhile_s" s_takeWhile_s, 1000 testProperty "sf_takeWhile" sf_takeWhile, 1001 testProperty "t_takeWhile" t_takeWhile, 1002 testProperty "tl_takeWhile" tl_takeWhile, 1003 testProperty "sf_dropWhile" sf_dropWhile, 1004 testProperty "s_dropWhile" s_dropWhile, 1005 testProperty "s_dropWhile_s" s_dropWhile_s, 1006 testProperty "t_dropWhile" t_dropWhile, 1007 testProperty "tl_dropWhile" tl_dropWhile, 1008 testProperty "t_dropWhileEnd" t_dropWhileEnd, 1009 testProperty "tl_dropWhileEnd" tl_dropWhileEnd, 1010 testProperty "t_dropAround" t_dropAround, 1011 testProperty "tl_dropAround" tl_dropAround, 1012 testProperty "t_stripStart" t_stripStart, 1013 testProperty "tl_stripStart" tl_stripStart, 1014 testProperty "t_stripEnd" t_stripEnd, 1015 testProperty "tl_stripEnd" tl_stripEnd, 1016 testProperty "t_strip" t_strip, 1017 testProperty "tl_strip" tl_strip, 1018 testProperty "t_splitAt" t_splitAt, 1019 testProperty "tl_splitAt" tl_splitAt, 1020 testProperty "t_spanBy" t_spanBy, 1021 testProperty "tl_spanBy" tl_spanBy, 1022 testProperty "t_break_id" t_break_id, 1023 testProperty "tl_break_id" tl_break_id, 1024 testProperty "t_break_start" t_break_start, 1025 testProperty "tl_break_start" tl_break_start, 1026 testProperty "t_breakEnd_end" t_breakEnd_end, 1027 testProperty "tl_breakEnd_end" tl_breakEnd_end, 1028 testProperty "t_breakBy" t_breakBy, 1029 testProperty "tl_breakBy" tl_breakBy, 1030 testProperty "t_group" t_group, 1031 testProperty "tl_group" tl_group, 1032 testProperty "t_groupBy" t_groupBy, 1033 testProperty "tl_groupBy" tl_groupBy, 1034 testProperty "t_inits" t_inits, 1035 testProperty "tl_inits" tl_inits, 1036 testProperty "t_tails" t_tails, 1037 testProperty "tl_tails" tl_tails 1038 ], 1039 1040 testGroup "breaking many" [ 1041 testProperty "t_findAppendId" t_findAppendId, 1042 testProperty "tl_findAppendId" tl_findAppendId, 1043 testProperty "t_findContains" t_findContains, 1044 testProperty "tl_findContains" tl_findContains, 1045 testProperty "sl_filterCount" sl_filterCount, 1046 testProperty "t_findCount" t_findCount, 1047 testProperty "tl_findCount" tl_findCount, 1048 testProperty "t_split_split" t_split_split, 1049 testProperty "tl_split_split" tl_split_split, 1050 testProperty "t_split_i" t_split_i, 1051 testProperty "tl_split_i" tl_split_i, 1052 testProperty "t_splitBy" t_splitBy, 1053 testProperty "t_splitBy_count" t_splitBy_count, 1054 testProperty "t_splitBy_split" t_splitBy_split, 1055 testProperty "tl_splitBy" tl_splitBy, 1056 testProperty "t_chunksOf_same_lengths" t_chunksOf_same_lengths, 1057 testProperty "t_chunksOf_length" t_chunksOf_length, 1058 testProperty "tl_chunksOf" tl_chunksOf 1059 ], 1060 1061 testGroup "lines and words" [ 1062 testProperty "t_lines" t_lines, 1063 testProperty "tl_lines" tl_lines, 1064 --testProperty "t_lines'" t_lines', 1065 testProperty "t_words" t_words, 1066 testProperty "tl_words" tl_words, 1067 testProperty "t_unlines" t_unlines, 1068 testProperty "tl_unlines" tl_unlines, 1069 testProperty "t_unwords" t_unwords, 1070 testProperty "tl_unwords" tl_unwords 1071 ] 1072 ], 1073 1074 testGroup "predicates" [ 1075 testProperty "s_isPrefixOf" s_isPrefixOf, 1076 testProperty "sf_isPrefixOf" sf_isPrefixOf, 1077 testProperty "t_isPrefixOf" t_isPrefixOf, 1078 testProperty "tl_isPrefixOf" tl_isPrefixOf, 1079 testProperty "t_isSuffixOf" t_isSuffixOf, 1080 testProperty "tl_isSuffixOf" tl_isSuffixOf, 1081 testProperty "t_isInfixOf" t_isInfixOf, 1082 testProperty "tl_isInfixOf" tl_isInfixOf, 1083 1084 testGroup "view" [ 1085 testProperty "t_prefixed" t_prefixed, 1086 testProperty "tl_prefixed" tl_prefixed, 1087 testProperty "t_suffixed" t_suffixed, 1088 testProperty "tl_suffixed" tl_suffixed 1089 ] 1090 ], 1091 1092 testGroup "searching" [ 1093 testProperty "sf_elem" sf_elem, 1094 testProperty "sf_filter" sf_filter, 1095 testProperty "t_filter" t_filter, 1096 testProperty "tl_filter" tl_filter, 1097 testProperty "sf_findBy" sf_findBy, 1098 testProperty "t_findBy" t_findBy, 1099 testProperty "tl_findBy" tl_findBy, 1100 testProperty "t_partition" t_partition, 1101 testProperty "tl_partition" tl_partition 1102 ], 1103 1104 testGroup "indexing" [ 1105 testProperty "sf_index" sf_index, 1106 testProperty "t_index" t_index, 1107 testProperty "tl_index" tl_index, 1108 testProperty "t_findIndex" t_findIndex, 1109 testProperty "t_count" t_count, 1110 testProperty "tl_count" tl_count, 1111 testProperty "t_indices" t_indices, 1112 testProperty "tl_indices" tl_indices, 1113 testProperty "t_indices_occurs" t_indices_occurs 1114 ], 1115 1116 testGroup "zips" [ 1117 testProperty "t_zip" t_zip, 1118 testProperty "tl_zip" tl_zip, 1119 testProperty "sf_zipWith" sf_zipWith, 1120 testProperty "t_zipWith" t_zipWith, 1121 testProperty "tl_zipWith" tl_zipWith 1122 ], 1123 1124 testGroup "regressions" [ 1125 testProperty "s_filter_eq" s_filter_eq 1126 ], 1127 1128 testGroup "shifts" [ 1129 testProperty "shiftL_Int" shiftL_Int, 1130 testProperty "shiftL_Word16" shiftL_Word16, 1131 testProperty "shiftL_Word32" shiftL_Word32, 1132 testProperty "shiftR_Int" shiftR_Int, 1133 testProperty "shiftR_Word16" shiftR_Word16, 1134 testProperty "shiftR_Word32" shiftR_Word32 1135 ], 1136 1137 testGroup "builder" [ 1138 testProperty "t_builderSingleton" t_builderSingleton, 1139 testProperty "t_builderFromText" t_builderFromText, 1140 testProperty "t_builderAssociative" t_builderAssociative 1141 ], 1142 1143 testGroup "input-output" [ 1144 testProperty "t_write_read" t_write_read, 1145 testProperty "tl_write_read" tl_write_read, 1146 testProperty "t_write_read_line" t_write_read_line, 1147 testProperty "tl_write_read_line" tl_write_read_line 1148 -- These tests are subject to I/O race conditions when run under 1149 -- test-framework-quickcheck2. 1150 -- testProperty "t_put_get" t_put_get 1151 -- testProperty "tl_put_get" tl_put_get 1152 ], 1153 1154 testGroup "lowlevel" [ 1155 testProperty "t_dropWord16" t_dropWord16, 1156 testProperty "t_takeWord16" t_takeWord16, 1157 testProperty "t_take_drop_16" t_take_drop_16, 1158 testProperty "t_use_from" t_use_from 1159 ] 1160 ]