mirror of
https://github.com/PuerkitoBio/goquery.git
synced 2024-04-21 12:31:36 +00:00
change Each() signature to receive a *Selection containing only the node instead of the node
This commit is contained in:
+2
-2
@@ -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
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user