on master help sign in
Make the split* functions undefined over empty delimiters as inputs.
bdb68cbBryan O'Sullivan
tests/Properties.hs+20−18
@@ -27,7 +27,7 @@ import System.IO.Unsafe (unsafePerformIO)
27import Test.Framework (defaultMain, testGroup)
27import Test.Framework (defaultMain, testGroup)
28import Test.Framework.Providers.QuickCheck (testProperty)
28import Test.Framework.Providers.QuickCheck (testProperty)
29
29
30−import QuickCheckUtils ()
30+import QuickCheckUtils (NotEmpty(..))
31
31
32-- Ensure that two potentially bottom values (in the sense of crashing
32-- Ensure that two potentially bottom values (in the sense of crashing
33-- for some inputs, not looping infinitely) either both crash, or both
33-- for some inputs, not looping infinitely) either both crash, or both
@@ -209,7 +209,7 @@ tl_replace s d = (L.intercalate d . split s) `eqP` (unpackS . TL.replace (TL
209
209
210split :: (Eq a) => [a] -> [a] -> [[a]]
210split :: (Eq a) => [a] -> [a] -> [[a]]
211split pat src0
211split pat src0
212− | l == 0 = [src0]
212+ | l == 0 = error "empty"
213 | otherwise = go src0
213 | otherwise = go src0
214 where
214 where
215 l = length pat
215 l = length pat
@@ -377,22 +377,24 @@ tl_inits = L.inits `eqP` (map unpackS . TL.inits)
377t_tails = L.tails `eqP` (map unpackS . T.tails)
377t_tails = L.tails `eqP` (map unpackS . T.tails)
378tl_tails = L.tails `eqP` (map unpackS . TL.tails)
378tl_tails = L.tails `eqP` (map unpackS . TL.tails)
379
379
380−t_split_i t = id `eq` (T.intercalate t . T.split t)
380+t_split_i (NotEmpty t) = id `eq` (T.intercalate t . T.split t)
381+tl_split_i (NotEmpty t) = id `eq` (TL.intercalate t . TL.split t)
381−t_splitTimes_i k t = id `eq` (T.intercalate t . T.splitTimes k t)
382+t_splitTimes_i k (NotEmpty t) = id `eq` (T.intercalate t . T.splitTimes k t)
382−tl_splitTimes_i k t = id `eq` (TL.intercalate t . TL.splitTimes k t)
383+tl_splitTimes_i k (NotEmpty t) = id `eq` (TL.intercalate t . TL.splitTimes k t)
383−t_splitTimes_split k t = T.splitTimes k t `eq` \u ->
384+t_splitTimes_split k (NotEmpty t) =
385+ T.splitTimes k t `eq` \u ->
384− case L.splitAt k (T.split t u) of
386+ case L.splitAt k (T.split t u) of
385− (a,[]) -> a
387+ (a,[]) -> a
386− (a,b) -> a ++ [T.intercalate t b]
388+ (a,b) -> a ++ [T.intercalate t b]
387−tl_splitTimes_split k t = TL.splitTimes k t `eq` \u ->
389+tl_splitTimes_split k (NotEmpty t) =
390+ TL.splitTimes k t `eq` \u ->
388− case L.splitAt (fromIntegral k) (TL.split t u) of
391+ case L.splitAt (fromIntegral k) (TL.split t u) of
389− (a,[]) -> a
392+ (a,[]) -> a
390− (a,b) -> a ++ [TL.intercalate t b]
393+ (a,b) -> a ++ [TL.intercalate t b]
391−t_splitTimesEnd_i k t = id `eq` (T.intercalate t . T.splitTimesEnd k t)
394+t_splitTimesEnd_i k (NotEmpty t) = id `eq` (T.intercalate t . T.splitTimesEnd k t)
392−tl_splitTimesEnd_i k t = id `eq` (TL.intercalate t . TL.splitTimesEnd k t)
395+tl_splitTimesEnd_i k (NotEmpty t) = id `eq` (TL.intercalate t . TL.splitTimesEnd k t)
393−t_splitTimesEnd_split t = T.splitTimesEnd maxBound t `eq` T.split t
396+t_splitTimesEnd_split (NotEmpty t) = T.splitTimesEnd maxBound t `eq` T.split t
394−tl_splitTimesEnd_split t = TL.splitTimesEnd maxBound t `eq` TL.split t
397+tl_splitTimesEnd_split (NotEmpty t) = TL.splitTimesEnd maxBound t `eq` TL.split t
395−tl_split_i t = id `eq` (TL.intercalate t . TL.split t)
396
398
397t_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
399t_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
398t_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.countChar c)
400t_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.countChar c)