change Each() signature to receive a *Selection containing only the node instead of the node

This commit is contained in:
Martin Angers
2012-08-29 14:21:17 -04:00
parent 4cc3f30d4a
commit 47f6aa5cbf
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -109,9 +109,9 @@ func (this *Selection) Find(selector string) *Selection {
}
// Returns this (same Selection object)
func (this *Selection) Each(f func(int, *html.Node)) *Selection {
func (this *Selection) Each(f func(int, *Selection)) *Selection {
for i, n := range this.Nodes {
f(i, n)
f(i, &Selection{[]*html.Node{n}, this.document})
}
return this
}
+3 -3
View File
@@ -35,7 +35,7 @@ func TestFindInvalidSelector(t *testing.T) {
if sel.Nodes != nil {
t.Error("Expected a Selection object with Nodes == nil.")
}
sel.Each(func(i int, n *html.Node) {
sel.Each(func(i int, n *Selection) {
cnt++
})
if cnt > 0 {
@@ -57,9 +57,9 @@ func TestChainedFind(t *testing.T) {
func TestEach(t *testing.T) {
var cnt int
sel := doc.Find(".hero-unit .row-fluid").Each(func(i int, n *html.Node) {
sel := doc.Find(".hero-unit .row-fluid").Each(func(i int, n *Selection) {
cnt++
t.Logf("At index %v, node %v", i, n.Data)
t.Logf("At index %v, node %v", i, n.Nodes[0].Data)
}).Find("a")
if cnt != 4 {