Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Oct 29, 2024
1 parent bb50757 commit d99de58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
14 changes: 1 addition & 13 deletions html/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import "iter"

// Ancestors returns an iterator over the ancestors of n, starting with n.Parent.
//
// Example:
//
// for ancestor := range n.Ancestors() { ... }
//
// Mutating a Node or its parents while iterating may have unexpected results.
func (n *Node) Ancestors() iter.Seq[*Node] {
_ = n.Parent // eager nil check
Expand All @@ -27,10 +23,6 @@ func (n *Node) Ancestors() iter.Seq[*Node] {
// ChildNodes returns an iterator over the immediate children of n,
// starting with n.FirstChild.
//
// Example:
//
// for child := range n.ChildNodes() { ... }
//
// Mutating a Node or its children while iterating may have unexpected results.
func (n *Node) ChildNodes() iter.Seq[*Node] {
_ = n.FirstChild // eager nil check
Expand All @@ -45,16 +37,12 @@ func (n *Node) ChildNodes() iter.Seq[*Node] {
// Descendants returns an iterator over all nodes recursively beneath
// n, excluding n itself. Nodes are visited in depth-first preorder.
//
// Example:
//
// for desc := range n.Descendants() { ... }
//
// Mutating a Node or its descendants while iterating may have unexpected results.
func (n *Node) Descendants() iter.Seq[*Node] {
_ = n.FirstChild // eager nil check

return func(yield func(*Node) bool) {
_ = n.descendants(yield)
n.descendants(yield)
}
}

Expand Down
7 changes: 3 additions & 4 deletions html/iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestNode_ChildNodes(t *testing.T) {
results = append(results, c.Data)
}
if got := strings.Join(results, " "); got != test.want {
t.Errorf("unexpected children yielded by ChildNodes; want: %q got: %q", test.want, got)
t.Errorf("ChildNodes = %q, want %q", got, test.want)
}
}
}
Expand Down Expand Up @@ -67,8 +67,7 @@ func TestNode_Descendants(t *testing.T) {
results = append(results, c.Data)
}
if got := strings.Join(results, " "); got != test.want {
t.Errorf("unexpected children yielded by Descendants; want: %q got: %q",
test.want, got)
t.Errorf("Descendants = %q; want: %q", got, test.want)
}
}
}
Expand All @@ -81,7 +80,7 @@ func TestNode_Ancestors(t *testing.T) {
nParents++
}
if nParents != size {
t.Errorf("unexpected number of Ancestors; want %d got: %d", size, nParents)
t.Errorf("number of Ancestors = %d; want: %d", nParents, size)
}
}
}
Expand Down

0 comments on commit d99de58

Please sign in to comment.