on master help sign in
Fix a bug in splitWith.

--HG-- extra : convert_revision : 25a269f26b0321c5c25b4cb34f8062897a87ed58

commitbd24b5cb429f733099319f7ca9cb4ff312f03635 authorBryan O'Sullivan <bos@serpentine.com> dateFri 14 Aug 2009, 05:18 (17 years ago) parent1ef6b04
2 files changed+4−2
Data/Text.hs+2−2 tests/Properties.hs+2
Data/Text.hs+2−2
@@ -984,9 +984,9 @@ splitTimesEnd k pat src =
984984-- separators result in an empty component in the output. eg.
985985--
986986-- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
987−-- > splitWith (=='a') [] == []
987+-- > splitWith (=='a') "" == [""]
988988splitWith :: (Char -> Bool) -> Text -> [Text]
989−splitWith _ (Text _off _arr 0) = []
989+splitWith _ t@(Text _off _arr 0) = [t]
990990splitWith p t = loop t
991991 where loop s | null s' = [l]
992992 | otherwise = l : loop (unsafeTail s')
tests/Properties.hs+2
@@ -305,6 +305,7 @@ prop_T_splitChar_i c = id `eq` (T.intercalate (T.singleton c) . T.splitChar c)
305305prop_TL_split_i c = id `eq` (TL.intercalate (TL.singleton c) . TL.split c)
306306
307307prop_T_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
308+prop_T_splitWith_split c = T.splitWith (==c) `eq` T.split (T.singleton c)
308309prop_TL_splitWith p = splitWith p `eqP` (map unpackS . TL.splitWith p)
309310
310311splitWith :: (a -> Bool) -> [a] -> [[a]]
@@ -569,6 +570,7 @@ tests = [
569570 ("prop_T_splitChar_i", mytest prop_T_splitChar_i),
570571 ("prop_TL_split_i", mytest prop_TL_split_i),
571572 ("prop_T_splitWith", mytest prop_T_splitWith),
573+ ("prop_T_splitWith_split", mytest prop_T_splitWith_split),
572574 ("prop_TL_splitWith", mytest prop_TL_splitWith),
573575 ("prop_T_chunksOf_same_lengths", mytest prop_T_chunksOf_same_lengths),
574576 ("prop_T_chunksOf_length", mytest prop_T_chunksOf_length),