Skip to content

Commit

Permalink
#86 Add empty test case
Browse files Browse the repository at this point in the history
  • Loading branch information
meian committed Feb 5, 2022
1 parent f1e92e4 commit bab37dd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@ func testBeforeAndAfter[T any](t *testing.T, itb gcf.Iterable[T]) {
//
// - emptyIterable chaining
// - test any func chaining result from emptyIterable is emptyIterable or not.
// - no panic from empty
// - test that panic does not occurred when any func chaining from empty elements that are not emptyIterable.
func testEmpties(t *testing.T, f func(itb gcf.Iterable[int]) gcf.Iterable[int]) {
t.Helper()
t.Run("emptyIterable chaining", func(t *testing.T) {
itb := gcf.FromSlice([]int{}) // returns emptyIterable
itb = f(itb)
assert.True(t, gcf.IsEmptyIterable(itb), "%v", gcf.ToSlice(itb))
})
t.Run("no panic from empty", func(t *testing.T) {
defer func() {
err := recover()
if err != nil {
t.Errorf("%v", err)
}
}()
itb := gcf.FromSlice([]int{1})
itb = gcf.Filter(itb, func(v int) bool { return false })
itb = f(itb)
_ = gcf.ToSlice(itb)
})
}

0 comments on commit bab37dd

Please sign in to comment.