Skip to content

Commit c0ca1fb

Browse files
committed
test(seq,seqe): NotNil
1 parent 4990ae5 commit c0ca1fb

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

seq/test/api_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,17 @@ func Test_ConvertNilSafe(t *testing.T) {
793793
assert.Equal(t, expected, s)
794794
}
795795

796+
func Test_NotLit(t *testing.T) {
797+
var (
798+
first = "first"
799+
third = "third"
800+
fifth = "fifth"
801+
source = seq.Of(&first, nil, &third, nil, &fifth)
802+
result = seq.NotNil(source)
803+
)
804+
assert.Equal(t, slice.Of(&first, &third, &fifth), result.Slice())
805+
}
806+
796807
func Test_ConvertOK(t *testing.T) {
797808
s := seq.Of(1, 3, 4, 5, 7, 8, 9, 11)
798809
converter := func(i int) (string, bool) { return strconv.Itoa(i), even(i) }

seqe/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func Group[S ~SeqE[T], T any, K comparable, V any](seq S, keyExtractor func(T) K
426426
}
427427

428428
// NotNil returns teh seq without nil elements.
429-
func NotNil[T any](seq SeqE[*T]) SeqE[*T] {
429+
func NotNil[T any](seq SeqE[*T]) seq.SeqE[*T] {
430430
return Filter(seq, not.Nil[T])
431431
}
432432

seqe/test/api_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,19 @@ func Test_ConvertNilSafe(t *testing.T) {
828828
assert.Equal(t, expected, s)
829829
}
830830

831+
func Test_NotLit(t *testing.T) {
832+
var (
833+
first = "first"
834+
third = "third"
835+
fifth = "fifth"
836+
source = seq.ToSeq2(seq.Of(&first, nil, &third, nil, &fifth), noErr)
837+
result = seqe.NotNil(source)
838+
)
839+
s, err := result.Slice()
840+
assert.Equal(t, slice.Of(&first, &third, &fifth), s)
841+
assert.NoError(t, err)
842+
}
843+
831844
func Test_ConvertOK(t *testing.T) {
832845
s := seq.ToSeq2(seq.Of(1, 3, 4, 5, 7, 8, 9, 11), noErr)
833846
converter := func(i int) (string, bool) { return strconv.Itoa(i), even(i) }

slice/test/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ func Test_ConvertNotNil(t *testing.T) {
298298
func Test_ConvertValues(t *testing.T) {
299299
type entity struct{ val string }
300300
var (
301-
source = []*entity{{"first"}, nil, {"third"}, nil, {"fifth"}}
301+
source = []*entity{{"first"}, nil, {"third"}, {}, {"fifth"}}
302302
result = convert.NotNil(source, as.Val[entity])
303-
expected = []entity{{"first"}, {"third"}, {"fifth"}}
303+
expected = []entity{{"first"}, {"third"}, {}, {"fifth"}}
304304
)
305305
assert.Equal(t, expected, result)
306306
}

0 commit comments

Comments
 (0)