@@ -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
44import Streamly.Internal.Data.Time.Units
46import Streamly.Internal.Data.Time.Units
45 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
47 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
@@ -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
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"]
79+ S.toList $ IS.splitOnSeq (A.fromList pat) (FL.toList) (S.fromList xs)
81+splitOnSuffixSeq :: Spec
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", ""]
103+ splitSuffixOn_ pat xs =
105+ $ IS.splitOnSuffixSeq (A.fromList pat) (FL.toList) (S.fromList xs)
54groupSplitOps :: String -> Spec
107groupSplitOps :: String -> Spec
55groupSplitOps desc = do
108groupSplitOps desc = do
56 -- splitting
109 -- splitting
57 -- XXX add tests with multichar separators too
112 -- XXX add tests with multichar separators too
59 prop (desc <> " intercalate . splitOnSeq == id (nil separator)") $
114 prop (desc <> " intercalate . splitOnSeq == id (nil separator)") $