mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(package): [iterator] report available elements in HasNext (#392)
This commit is contained in:
1 parent
9685357daf
commit
be3bc0c43f
2 files changed
+39
-2
No files matched your search
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user