on master help sign in
Fix haddock & add tests for sequence split combinators
1820919adithyaov
src/Streamly/Internal/Data/Stream/IsStream.hs+1−1
@@ -4170,7 +4170,7 @@ splitOnAny subseq f m = undefined -- D.fromStreamD $ D.splitOnAny f subseq (D.to
4170-- > splitSuffixOn_ pat xs = S.toList $ S.splitSuffixOn (A.fromList pat) (FL.toList) (S.fromList xs)
4170-- > splitSuffixOn_ pat xs = S.toList $ S.splitSuffixOn (A.fromList pat) (FL.toList) (S.fromList xs)
4171--
4171--
4172-- >>> splitSuffixOn_ "." ""
4172-- >>> splitSuffixOn_ "." ""
4173−-- [""]
4173+-- []
4174--
4174--
4175-- >>> splitSuffixOn_ "." "."
4175-- >>> splitSuffixOn_ "." "."
4176-- [""]
4176-- [""]
test/Streamly/Test/Prelude/Serial.hs+55
@@ -41,6 +41,8 @@ import qualified Streamly.Prelude as S
41import qualified Streamly.Data.Fold as FL
41import qualified Streamly.Data.Fold as FL
42import qualified Streamly.Internal.Data.Unfold as UF
42import qualified Streamly.Internal.Data.Unfold as UF
43import qualified Streamly.Internal.Data.Stream.IsStream as IS
43import qualified Streamly.Internal.Data.Stream.IsStream as IS
44+import qualified Streamly.Data.Array.Storable.Foreign as A
45+
44import Streamly.Internal.Data.Time.Units
46import Streamly.Internal.Data.Time.Units
45 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
47 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
46
48
@@ -51,9 +53,62 @@ import Streamly.Internal.Data.Time.Clock (Clock(Monotonic), getTime)
51import Streamly.Test.Common
53import Streamly.Test.Common
52import Streamly.Test.Prelude.Common
54import Streamly.Test.Prelude.Common
53
55
56+splitOnSeq :: Spec
57+splitOnSeq = do
58+ describe "Tests for splitOnSeq" $ do
59+ it "splitOnSeq' \"hello\" \"\" = [\"\"]"
60+ $ splitOnSeq' "hello" "" `shouldReturn` [""]
61+ it "splitOnSeq' \"hello\" \"hello\" = [\"\", \"\"]"
62+ $ splitOnSeq' "hello" "hello" `shouldReturn` ["", ""]
63+ it "splitOnSeq' \"x\" \"hello\" = [\"hello\"]"
64+ $ splitOnSeq' "x" "hello" `shouldReturn` ["hello"]
65+ it "splitOnSeq' \"h\" \"hello\" = [\"\", \"ello\"]"
66+ $ splitOnSeq' "h" "hello" `shouldReturn` ["", "ello"]
67+ it "splitOnSeq' \"o\" \"hello\" = [\"hell\", \"\"]"
68+ $ splitOnSeq' "o" "hello" `shouldReturn` ["hell", ""]
69+ it "splitOnSeq' \"e\" \"hello\" = [\"h\", \"llo\"]"
70+ $ splitOnSeq' "e" "hello" `shouldReturn` ["h", "llo"]
71+ it "splitOnSeq' \"l\" \"hello\" = [\"he\", \"\", \"o\"]"
72+ $ splitOnSeq' "l" "hello" `shouldReturn` ["he", "", "o"]
73+ it "splitOnSeq' \"ll\" \"hello\" = [\"he\", \"o\"]"
74+ $ splitOnSeq' "ll" "hello" `shouldReturn` ["he", "o"]
75+
76+ where
77+
78+ splitOnSeq' pat xs =
79+ S.toList $ IS.splitOnSeq (A.fromList pat) (FL.toList) (S.fromList xs)
80+
81+splitOnSuffixSeq :: Spec
82+splitOnSuffixSeq = do
83+ describe "Tests for splitOnSuffixSeq" $ do
84+ it "splitSuffixOn_ \".\" \"\" [\"\"]"
85+ $ splitSuffixOn_ "." "" `shouldReturn` []
86+ it "splitSuffixOn_ \".\" \".\" [\"\"]"
87+ $ splitSuffixOn_ "." "." `shouldReturn` [""]
88+ it "splitSuffixOn_ \".\" \"a\" [\"a\"]"
89+ $ splitSuffixOn_ "." "a" `shouldReturn` ["a"]
90+ it "splitSuffixOn_ \".\" \".a\" [\"\",\"a\"]"
91+ $ splitSuffixOn_ "." ".a" `shouldReturn` ["", "a"]
92+ it "splitSuffixOn_ \".\" \"a.\" [\"a\"]"
93+ $ splitSuffixOn_ "." "a." `shouldReturn` ["a"]
94+ it "splitSuffixOn_ \".\" \"a.b\" [\"a\",\"b\"]"
95+ $ splitSuffixOn_ "." "a.b" `shouldReturn` ["a", "b"]
96+ it "splitSuffixOn_ \".\" \"a.b.\" [\"a\",\"b\"]"
97+ $ splitSuffixOn_ "." "a.b." `shouldReturn` ["a", "b"]
98+ it "splitSuffixOn_ \".\" \"a..b..\" [\"a\",\"\",\"b\",\"\"]"
99+ $ splitSuffixOn_ "." "a..b.." `shouldReturn` ["a", "", "b", ""]
100+
101+ where
102+
103+ splitSuffixOn_ pat xs =
104+ S.toList
105+ $ IS.splitOnSuffixSeq (A.fromList pat) (FL.toList) (S.fromList xs)
106+
54groupSplitOps :: String -> Spec
107groupSplitOps :: String -> Spec
55groupSplitOps desc = do
108groupSplitOps desc = do
56 -- splitting
109 -- splitting
110+ splitOnSeq
111+ splitOnSuffixSeq
57 -- XXX add tests with multichar separators too
112 -- XXX add tests with multichar separators too
58{-
113{-
59 prop (desc <> " intercalate . splitOnSeq == id (nil separator)") $
114 prop (desc <> " intercalate . splitOnSeq == id (nil separator)") $