mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-10-05 00:42:50 +08:00
add Contents() and Children() with tests.
This commit is contained in:
@@ -28,22 +28,6 @@ func TestFindInvalidSelector(t *testing.T) {
|
||||
Doc().Find(":+ ^")
|
||||
}
|
||||
|
||||
func TestEachEmptySelection(t *testing.T) {
|
||||
var cnt int
|
||||
|
||||
sel := Doc().Find("zzzz")
|
||||
sel.Each(func(i int, n *Selection) {
|
||||
cnt++
|
||||
})
|
||||
if cnt > 0 {
|
||||
t.Error("Expected Each() to not be called on empty Selection.")
|
||||
}
|
||||
sel2 := sel.Find("div")
|
||||
if sel2.Nodes != nil {
|
||||
t.Error("Expected Find() on empty Selection to return an empty Selection.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestChainedFind(t *testing.T) {
|
||||
sel := Doc().Find("div.hero-unit").Find(".row-fluid")
|
||||
if sel.Nodes == nil || len(sel.Nodes) != 4 {
|
||||
@@ -53,6 +37,16 @@ func TestChainedFind(t *testing.T) {
|
||||
|
||||
func TestChildren(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Children()
|
||||
if len(sel.Nodes) != 5 {
|
||||
t.Errorf("Expected 5 child nodes, got %v.", len(sel.Nodes))
|
||||
for _, n := range sel.Nodes {
|
||||
t.Logf("%+v", n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestContents(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Contents()
|
||||
if len(sel.Nodes) != 13 {
|
||||
t.Errorf("Expected 13 child nodes, got %v.", len(sel.Nodes))
|
||||
for _, n := range sel.Nodes {
|
||||
@@ -71,6 +65,16 @@ func TestChildrenFiltered(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContentsFiltered(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").ContentsFiltered(".hero-unit")
|
||||
if len(sel.Nodes) != 1 {
|
||||
t.Errorf("Expected 1 child nodes, got %v.", len(sel.Nodes))
|
||||
for _, n := range sel.Nodes {
|
||||
t.Logf("%+v", n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestChildrenFilteredNone(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").ChildrenFiltered("a.btn")
|
||||
if len(sel.Nodes) != 0 {
|
||||
|
Reference in New Issue
Block a user