-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into websocket-http2
# Conflicts: # http2/transport_test.go
- Loading branch information
Showing
19 changed files
with
858 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= | ||
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= | ||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= | ||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM= | ||
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8= | ||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= | ||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= | ||
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= | ||
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= | ||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= | ||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU= | ||
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= | ||
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= | ||
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.23 | ||
|
||
package html | ||
|
||
import "iter" | ||
|
||
// Ancestors returns an iterator over the ancestors of n, starting with n.Parent. | ||
// | ||
// Mutating a Node or its parents while iterating may have unexpected results. | ||
func (n *Node) Ancestors() iter.Seq[*Node] { | ||
_ = n.Parent // eager nil check | ||
|
||
return func(yield func(*Node) bool) { | ||
for p := n.Parent; p != nil && yield(p); p = p.Parent { | ||
} | ||
} | ||
} | ||
|
||
// ChildNodes returns an iterator over the immediate children of n, | ||
// starting with n.FirstChild. | ||
// | ||
// Mutating a Node or its children while iterating may have unexpected results. | ||
func (n *Node) ChildNodes() iter.Seq[*Node] { | ||
_ = n.FirstChild // eager nil check | ||
|
||
return func(yield func(*Node) bool) { | ||
for c := n.FirstChild; c != nil && yield(c); c = c.NextSibling { | ||
} | ||
} | ||
|
||
} | ||
|
||
// Descendants returns an iterator over all nodes recursively beneath | ||
// n, excluding n itself. Nodes are visited in depth-first preorder. | ||
// | ||
// 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) | ||
} | ||
} | ||
|
||
func (n *Node) descendants(yield func(*Node) bool) bool { | ||
for c := range n.ChildNodes() { | ||
if !yield(c) || !c.descendants(yield) { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build go1.23 | ||
|
||
package html | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestNode_ChildNodes(t *testing.T) { | ||
tests := []struct { | ||
in string | ||
want string | ||
}{ | ||
{"", ""}, | ||
{"<a></a>", "a"}, | ||
{"a", "a"}, | ||
{"<a></a><!--b-->", "a b"}, | ||
{"a<b></b>c", "a b c"}, | ||
{"a<b><!--c--></b>d", "a b d"}, | ||
{"<a><b>c<!--d-->e</b></a>f<!--g--><h>i</h>", "a f g h"}, | ||
} | ||
for _, test := range tests { | ||
doc, err := Parse(strings.NewReader(test.in)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// Drill to <html><head></head><body> | ||
n := doc.FirstChild.FirstChild.NextSibling | ||
var results []string | ||
for c := range n.ChildNodes() { | ||
results = append(results, c.Data) | ||
} | ||
if got := strings.Join(results, " "); got != test.want { | ||
t.Errorf("ChildNodes = %q, want %q", got, test.want) | ||
} | ||
} | ||
} | ||
|
||
func TestNode_Descendants(t *testing.T) { | ||
tests := []struct { | ||
in string | ||
want string | ||
}{ | ||
{"", ""}, | ||
{"<a></a>", "a"}, | ||
{"<a><b></b></a>", "a b"}, | ||
{"<a>b</a>", "a b"}, | ||
{"<a><!--b--></a>", "a b"}, | ||
{"<a>b<c></c>d</a>", "a b c d"}, | ||
{"<a>b<c><!--d--></c>e</a>", "a b c d e"}, | ||
{"<a><b><c>d<!--e-->f</c></b>g<!--h--><i>j</i></a>", "a b c d e f g h i j"}, | ||
} | ||
for _, test := range tests { | ||
doc, err := Parse(strings.NewReader(test.in)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// Drill to <html><head></head><body> | ||
n := doc.FirstChild.FirstChild.NextSibling | ||
var results []string | ||
for c := range n.Descendants() { | ||
results = append(results, c.Data) | ||
} | ||
if got := strings.Join(results, " "); got != test.want { | ||
t.Errorf("Descendants = %q; want: %q", got, test.want) | ||
} | ||
} | ||
} | ||
|
||
func TestNode_Ancestors(t *testing.T) { | ||
for _, size := range []int{0, 1, 2, 10, 100, 10_000} { | ||
n := buildChain(size) | ||
nParents := 0 | ||
for _ = range n.Ancestors() { | ||
nParents++ | ||
} | ||
if nParents != size { | ||
t.Errorf("number of Ancestors = %d; want: %d", nParents, size) | ||
} | ||
} | ||
} | ||
|
||
func buildChain(size int) *Node { | ||
child := new(Node) | ||
for range size { | ||
parent := child | ||
child = new(Node) | ||
parent.AppendChild(child) | ||
} | ||
return child | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.