Commits

Bryan O'Sullivan  committed 5adc9f2

Write a property for the new split function, and fix a bug in it.

  • Participants
  • Parent commits e11fc6d

Comments (0)

Files changed (2)

File Data/Text.hs

 -- not copy the substrings, it just constructs new 'Text's that are
 -- slices of the original.
 split :: Text -> Text -> [Text]
-split pat = go
+split pat src0
+    | l == 0    = [src0]
+    | otherwise = go src0
   where
+    l      = length pat
     go src = search 0 src
       where
         search !n !s
             | null s             = [src]      -- not found
             | pat `isPrefixOf` s = take n src : go (drop l s)
             | otherwise          = search (n+1) (unsafeTail s)
-        l = length pat
 {-# INLINE split #-}
 
 -- | /O(n)/ Splits a 'Text' into components delimited by separators,

File tests/Properties.hs

 prop_T_tails           = L.tails       `eqP` (map unpackS . T.tails)
 prop_TL_tails          = L.tails       `eqP` (map unpackS . TL.tails)
 
+prop_T_split_i t       = id `eq` (T.intercalate t . T.split t)
 prop_T_splitChar_i c   = id `eq` (T.intercalate (T.singleton c) . T.splitChar c)
 prop_TL_split_i c      = id `eq` (TL.intercalate (TL.singleton c) . TL.split c)
 
   ("prop_T_tails", mytest prop_T_tails),
   ("prop_TL_tails", mytest prop_TL_tails),
 
+  ("prop_T_split_i", mytest prop_T_split_i),
   ("prop_T_splitChar_i", mytest prop_T_splitChar_i),
   ("prop_TL_split_i", mytest prop_TL_split_i),
   ("prop_T_splitWith", mytest prop_T_splitWith),