Skip to content

Commit

Permalink
Rename Children to ChildNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Oct 28, 2024
1 parent ac0b9cf commit bb50757
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions html/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func (n *Node) Ancestors() iter.Seq[*Node] {
}
}

// Children returns an iterator over the immediate children of n,
// ChildNodes returns an iterator over the immediate children of n,
// starting with n.FirstChild.
//
// Example:
//
// for child := range n.Children() { ... }
// for child := range n.ChildNodes() { ... }
//
// Mutating a Node or its children while iterating may have unexpected results.
func (n *Node) Children() iter.Seq[*Node] {
func (n *Node) ChildNodes() iter.Seq[*Node] {
_ = n.FirstChild // eager nil check

return func(yield func(*Node) bool) {
Expand All @@ -59,7 +59,7 @@ func (n *Node) Descendants() iter.Seq[*Node] {
}

func (n *Node) descendants(yield func(*Node) bool) bool {
for c := range n.Children() {
for c := range n.ChildNodes() {
if !yield(c) || !c.descendants(yield) {
return false
}
Expand Down
6 changes: 3 additions & 3 deletions html/iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"
)

func TestNode_Children(t *testing.T) {
func TestNode_ChildNodes(t *testing.T) {
tests := []struct {
in string
want string
Expand All @@ -32,11 +32,11 @@ func TestNode_Children(t *testing.T) {
// Drill to <html><head></head><body>
n := doc.FirstChild.FirstChild.NextSibling
var results []string
for c := range n.Children() {
for c := range n.ChildNodes() {
results = append(results, c.Data)
}
if got := strings.Join(results, " "); got != test.want {
t.Errorf("unexpected children yielded by Children; want: %q got: %q", test.want, got)
t.Errorf("unexpected children yielded by ChildNodes; want: %q got: %q", test.want, got)
}
}
}
Expand Down

0 comments on commit bb50757

Please sign in to comment.