Skip to content

Commit

Permalink
Move multiple sequence splitting doctests into the test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Jan 7, 2025
1 parent cde9fea commit 05d6e90
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 84 deletions.
82 changes: 6 additions & 76 deletions core/src/Streamly/Internal/Data/Stream/Nesting.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2786,45 +2786,21 @@ data SplitOnSeqState mba rb rh ck w fs s b x =
-- >>> splitSepBy "" ""
-- []
--
-- >>> splitSepBy "." ""
-- []
--
-- >>> splitSepBy ".." ""
-- []
--
-- >>> splitSepBy "..." ""
-- []
--
-- >>> splitSepBy "" "a...b"
-- ["a",".",".",".","b"]
--
-- >>> splitSepBy "." "a...b"
-- ["a","","","b"]
-- >>> splitSepBy ".." ""
-- []
--
-- >>> splitSepBy ".." "a...b"
-- ["a",".b"]
--
-- >>> splitSepBy "..." "a...b"
-- ["a","b"]
--
-- >>> splitSepBy "." "abc"
-- ["abc"]
--
-- >>> splitSepBy ".." "abc"
-- ["abc"]
--
-- >>> splitSepBy "..." "abc"
-- ["abc"]
--
-- >>> splitSepBy "." "."
-- ["",""]
--
-- >>> splitSepBy ".." ".."
-- ["",""]
--
-- >>> splitSepBy "..." "..."
-- ["",""]
--
-- >>> splitSepBy "." ".a"
-- ["","a"]
--
Expand Down Expand Up @@ -3609,45 +3585,23 @@ splitOnSuffixSeq withSep patArr (Fold fstep initial _ final) (Stream step state)
-- >>> splitEndBy "" ""
-- []
--
-- >>> splitEndBy "." ""
-- []
-- >>> splitEndBy "" "a...b"
-- ["a",".",".",".","b"]
--
-- >>> splitEndBy ".." ""
-- []
--
-- >>> splitEndBy "..." ""
-- []
--
-- >>> splitEndBy "" "a...b"
-- ["a",".",".",".","b"]
--
-- >>> splitEndBy "." "a...b"
-- ["a.",".",".","b"]
--
-- >>> splitEndBy ".." "a...b"
-- ["a..",".b"]
--
-- >>> splitEndBy "..." "a...b"
-- ["a...","b"]
--
-- >>> splitEndBy "." "abc"
-- ["abc"]
--
-- >>> splitEndBy ".." "abc"
-- ["abc"]
--
-- >>> splitEndBy "..." "abc"
-- ["abc"]
--
-- >>> splitEndBy "." "."
-- ["."]
--
-- >>> splitEndBy ".." ".."
-- [".."]
--
-- >>> splitEndBy "..." "..."
-- ["..."]
--
-- >>> splitEndBy "." ".a"
-- [".","a"]
--
Expand Down Expand Up @@ -3679,45 +3633,21 @@ splitEndBySeq = splitOnSuffixSeq True
-- >>> splitEndBy_ "" ""
-- []
--
-- >>> splitEndBy_ "." ""
-- []
--
-- >>> splitEndBy_ ".." ""
-- []
--
-- >>> splitEndBy_ "..." ""
-- []
--
-- >>> splitEndBy_ "" "a...b"
-- ["a",".",".",".","b"]
--
-- >>> splitEndBy_ "." "a...b"
-- ["a","","","b"]
-- >>> splitEndBy_ ".." ""
-- []
--
-- >>> splitEndBy_ ".." "a...b"
-- ["a",".b"]
--
-- >>> splitEndBy_ "..." "a...b"
-- ["a","b"]
--
-- >>> splitEndBy_ "." "abc"
-- ["abc"]
--
-- >>> splitEndBy_ ".." "abc"
-- ["abc"]
--
-- >>> splitEndBy_ "..." "abc"
-- ["abc"]
--
-- >>> splitEndBy_ "." "."
-- [""]
--
-- >>> splitEndBy_ ".." ".."
-- [""]
--
-- >>> splitEndBy_ "..." "..."
-- [""]
--
-- >>> splitEndBy_ "." ".a"
-- ["","a"]
--
Expand Down
79 changes: 71 additions & 8 deletions test/Streamly/Test/Data/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,80 @@ groupSplitOps desc = do
splitOnSuffixSeq splitOnSuffixSeqStream
-- Some ad-hoc tests
it "splitEndBySeq word hash cases" $ do
let f input result =
let f sep input result =
Stream.toList
( Stream.splitEndBySeq (Array.fromList "ab") Fold.toList
( Stream.splitEndBySeq (Array.fromList sep) Fold.toList
$ Stream.fromList input
) `shouldReturn` result
f "a" ["a"]
f "ab" ["ab"]
f "aba" ["ab","a"]
f "abab" ["ab","ab"]
f "abc" ["ab","c"]
f "xab" ["xab"]

f "ab" "a" ["a"]
f "ab" "ab" ["ab"]
f "ab" "aba" ["ab","a"]
f "ab" "abab" ["ab","ab"]
f "ab" "abc" ["ab","c"]
f "ab" "xab" ["xab"]
f "" "" []
f "." "" []
f ".." "" []
f "..." "" []
f "" "a...b" ["a",".",".",".","b"]
f "." "a...b" ["a.",".",".","b"]
f ".." "a...b" ["a..",".b"]
f "..." "a...b" ["a...","b"]
f "." "abc" ["abc"]
f ".." "abc" ["abc"]
f "..." "abc" ["abc"]
f "." "." ["."]
f ".." ".." [".."]
f "..." "..." ["..."]
f "." ".a" [".","a"]
f "." "a." ["a."]

it "splitEndBySeq_ word hash cases" $ do
let f sep input result =
Stream.toList
( Stream.splitEndBySeq_ (Array.fromList sep) Fold.toList
$ Stream.fromList input
) `shouldReturn` result
f "" "" []
f "." "" []
f ".." "" []
f "..." "" []
f "" "a...b" ["a",".",".",".","b"]
f "." "a...b" ["a","","","b"]
f ".." "a...b" ["a",".b"]
f "..." "a...b" ["a","b"]
f "." "abc" ["abc"]
f ".." "abc" ["abc"]
f "..." "abc" ["abc"]
f "." "." [""]
f ".." ".." [""]
f "..." "..." [""]
f "." ".a" ["","a"]
f "." "a." ["a"]

it "splitSepBySeq_ word hash cases" $ do
let f sep input result =
Stream.toList
( Stream.splitSepBySeq_ (Array.fromList sep) Fold.toList
$ Stream.fromList input
) `shouldReturn` result
f "" "" []
f "." "" []
f ".." "" []
f "..." "" []
f "" "a...b" ["a",".",".",".","b"]
f "." "a...b" ["a","","","b"]
f ".." "a...b" ["a",".b"]
f "..." "a...b" ["a","b"]
f "." "abc" ["abc"]
f ".." "abc" ["abc"]
f "..." "abc" ["abc"]
f "." "." ["",""]
f ".." ".." ["",""]
f "..." "..." ["",""]
f "." ".a" ["","a"]
f "." "a." ["a",""]

let takeEndBySeq pat input result =
Stream.toList
Expand Down

0 comments on commit 05d6e90

Please sign in to comment.