Bryan O'Sullivan avatar Bryan O'Sullivan committed f4a6e76

Make the split* functions undefined over empty delimiters as inputs.

Comments (0)

Files changed (1)

tests/Properties.hs

 import Test.Framework (defaultMain, testGroup)
 import Test.Framework.Providers.QuickCheck (testProperty)
 
-import QuickCheckUtils ()
+import QuickCheckUtils (NotEmpty(..))
 
 -- Ensure that two potentially bottom values (in the sense of crashing
 -- for some inputs, not looping infinitely) either both crash, or both
 
 split :: (Eq a) => [a] -> [a] -> [[a]]
 split pat src0
-    | l == 0    = [src0]
+    | l == 0    = error "empty"
     | otherwise = go src0
   where
     l           = length pat
 t_tails           = L.tails       `eqP` (map unpackS . T.tails)
 tl_tails          = L.tails       `eqP` (map unpackS . TL.tails)
 
-t_split_i t       = id `eq` (T.intercalate t . T.split t)
-t_splitTimes_i k t = id `eq` (T.intercalate t . T.splitTimes k t)
-tl_splitTimes_i k t = id `eq` (TL.intercalate t . TL.splitTimes k t)
-t_splitTimes_split k t = T.splitTimes k t `eq` \u ->
-                              case L.splitAt k (T.split t u) of
-                                (a,[]) -> a
-                                (a,b)  -> a ++ [T.intercalate t b]
-tl_splitTimes_split k t = TL.splitTimes k t `eq` \u ->
-                              case L.splitAt (fromIntegral k) (TL.split t u) of
-                                (a,[]) -> a
-                                (a,b)  -> a ++ [TL.intercalate t b]
-t_splitTimesEnd_i k t = id `eq` (T.intercalate t . T.splitTimesEnd k t)
-tl_splitTimesEnd_i k t = id `eq` (TL.intercalate t . TL.splitTimesEnd k t)
-t_splitTimesEnd_split t = T.splitTimesEnd maxBound t `eq` T.split t
-tl_splitTimesEnd_split t = TL.splitTimesEnd maxBound t `eq` TL.split t
-tl_split_i t      = id `eq` (TL.intercalate t . TL.split t)
+t_split_i (NotEmpty t)  = id `eq` (T.intercalate t . T.split t)
+tl_split_i (NotEmpty t) = id `eq` (TL.intercalate t . TL.split t)
+t_splitTimes_i k (NotEmpty t) = id `eq` (T.intercalate t . T.splitTimes k t)
+tl_splitTimes_i k (NotEmpty t) = id `eq` (TL.intercalate t . TL.splitTimes k t)
+t_splitTimes_split k (NotEmpty t) =
+    T.splitTimes k t `eq` \u ->
+        case L.splitAt k (T.split t u) of
+          (a,[]) -> a
+          (a,b)  -> a ++ [T.intercalate t b]
+tl_splitTimes_split k (NotEmpty t) =
+    TL.splitTimes k t `eq` \u ->
+        case L.splitAt (fromIntegral k) (TL.split t u) of
+          (a,[]) -> a
+          (a,b)  -> a ++ [TL.intercalate t b]
+t_splitTimesEnd_i k (NotEmpty t) = id `eq` (T.intercalate t . T.splitTimesEnd k t)
+tl_splitTimesEnd_i k (NotEmpty t) = id `eq` (TL.intercalate t . TL.splitTimesEnd k t)
+t_splitTimesEnd_split (NotEmpty t) = T.splitTimesEnd maxBound t `eq` T.split t
+tl_splitTimesEnd_split (NotEmpty t) = TL.splitTimesEnd maxBound t `eq` TL.split t
 
 t_splitWith p     = splitWith p `eqP` (map unpackS . T.splitWith p)
 t_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.countChar c)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.