on master help sign in
Fix haddock & add tests for sequence split combinators

Fix haddock for spliOnSuffixSeq Add tests for splitOnSeq & spliOnSuffixSeq

commit1820919c73e1514aff6f179180ae06ecf3b0b950 authoradithyaov <adithya@composewell.com> dateTue 27 Oct 2020, 20:16 (6 years ago) parent6c3f1ed
2 files changed+56−1
src/Streamly/Internal/Data/Stream/IsStream.hs+1−1 test/Streamly/Test/Prelude/Serial.hs+55
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
41704170-- > splitSuffixOn_ pat xs = S.toList $ S.splitSuffixOn (A.fromList pat) (FL.toList) (S.fromList xs)
41714171--
41724172-- >>> splitSuffixOn_ "." ""
4173−-- [""]
4173+-- []
41744174--
41754175-- >>> splitSuffixOn_ "." "."
41764176-- [""]
test/Streamly/Test/Prelude/Serial.hs+55
@@ -41,6 +41,8 @@ import qualified Streamly.Prelude as S
4141import qualified Streamly.Data.Fold as FL
4242import qualified Streamly.Internal.Data.Unfold as UF
4343import qualified Streamly.Internal.Data.Stream.IsStream as IS
44+import qualified Streamly.Data.Array.Storable.Foreign as A
45+
4446import Streamly.Internal.Data.Time.Units
4547 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
4648
@@ -51,9 +53,62 @@ import Streamly.Internal.Data.Time.Clock (Clock(Monotonic), getTime)
5153import Streamly.Test.Common
5254import Streamly.Test.Prelude.Common
5355
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+
54107groupSplitOps :: String -> Spec
55108groupSplitOps desc = do
56109 -- splitting
110+ splitOnSeq
111+ splitOnSuffixSeq
57112 -- XXX add tests with multichar separators too
58113{-
59114 prop (desc <> " intercalate . splitOnSeq == id (nil separator)") $