fix(package): [iterator] report available elements in HasNext (#392)

This commit is contained in:
Yusuf Efe authored and GitHub committed 2026-10-22 10:34:04 +08:00
1 parent 9685357daf
commit be3bc0c43f
2 files changed
+39 -2

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
package iterator
import "testing"
func TestTakeHasNextExhaustedSource(t *testing.T) {
it := Take[int](FromSlice([]int{1}), 3)
if value, ok := it.Next(); !ok || value != 1 {
t.Fatal("missing first value")
}
if it.HasNext() {
t.Error("exhausted source still reports an element")
}
}
func TestFilterHasNextMatches(t *testing.T) {
it := Filter[int](FromSlice([]int{1, 2, 3}), func(value int) bool { return value%2 == 0 })
if !it.HasNext() || !it.HasNext() {
t.Fatal("missing matching value")
}
if value, ok := it.Next(); !ok || value != 2 {
t.Fatal("HasNext consumed the matching value")
}
if it.HasNext() {
t.Error("unmatched tail reported as another element")
}
}