Files
goquery/iteration123_test.go
amikai 6802fc5555 Re-orangize code for compitable
- We don't need to use the iter.Seq2 type; instead, we can use func(yield func(int, *Selection) bool). In fact, the underlying type of iter.Seq2 is func(yield func(int, *Selection) bool), so we don't need to upgrade the go.mod version.
- For for-range testing in version 1.23, we can use build tags to compile only for versions above 1.23.
2024-07-24 15:02:18 +08:00

43 lines
785 B
Go

//go:build go1.23
// +build go1.23
package goquery
import "testing"
func TestEachIter123(t *testing.T) {
var cnt int
sel := Doc().Find(".hero-unit .row-fluid")
for i, s := range sel.EachIter() {
cnt++
t.Logf("At index %v, node %v", i, s.Nodes[0].Data)
}
sel = sel.Find("a")
if cnt != 4 {
t.Errorf("Expected EachIter() to call function 4 times, got %v times.", cnt)
}
assertLength(t, sel.Nodes, 6)
}
func TestEachIterWithBreak123(t *testing.T) {
var cnt int
sel := Doc().Find(".hero-unit .row-fluid")
for i, s := range sel.EachIter() {
cnt++
t.Logf("At index %v, node %v", i, s.Nodes[0].Data)
break
}
sel = sel.Find("a")
if cnt != 1 {
t.Errorf("Expected EachIter() to call function 1 time, got %v times.", cnt)
}
assertLength(t, sel.Nodes, 6)
}