Files
goquery/iteration_test.go
2012-08-30 17:38:51 -04:00

22 lines
428 B
Go

package goquery
import (
"testing"
)
func TestEach(t *testing.T) {
var cnt int
sel := Doc().Find(".hero-unit .row-fluid").Each(func(i int, n *Selection) {
cnt++
t.Logf("At index %v, node %v", i, n.Nodes[0].Data)
}).Find("a")
if cnt != 4 {
t.Errorf("Expected Each() to call function 4 times, got %v times.", cnt)
}
if len(sel.Nodes) != 6 {
t.Errorf("Expected 6 matching nodes, found %v.", len(sel.Nodes))
}
}