mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-10-30 19:26:25 +08:00
fix tests after reorganization
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func TestFirst(t *testing.T) {
|
||||
sel := doc.Find(".pvk-content").First()
|
||||
sel := Doc().Find(".pvk-content").First()
|
||||
if len(sel.Nodes) != 1 {
|
||||
t.Errorf("Expected 1 node, found %v.", len(sel.Nodes))
|
||||
}
|
||||
@@ -17,42 +17,42 @@ func TestFirstEmpty(t *testing.T) {
|
||||
t.Error("Expected a panic, First() called on empty Selection.")
|
||||
}
|
||||
}()
|
||||
doc.Find(".pvk-zzcontentzz").First()
|
||||
Doc().Find(".pvk-zzcontentzz").First()
|
||||
}
|
||||
|
||||
func TestLast(t *testing.T) {
|
||||
sel := doc.Find(".pvk-content").Last()
|
||||
sel := Doc().Find(".pvk-content").Last()
|
||||
if len(sel.Nodes) != 1 {
|
||||
t.Errorf("Expected 1 node, found %v.", len(sel.Nodes))
|
||||
}
|
||||
// Should contain Footer
|
||||
foot := doc.Find(".footer")
|
||||
foot := Doc().Find(".footer")
|
||||
if !sel.Contains(foot.Nodes[0]) {
|
||||
t.Error("Last .pvk-content should contain .footer.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEq(t *testing.T) {
|
||||
sel := doc.Find(".pvk-content").Eq(1)
|
||||
sel := Doc().Find(".pvk-content").Eq(1)
|
||||
if len(sel.Nodes) != 1 {
|
||||
t.Errorf("Expected 1 node, found %v.", len(sel.Nodes))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqNegative(t *testing.T) {
|
||||
sel := doc.Find(".pvk-content").Eq(-1)
|
||||
sel := Doc().Find(".pvk-content").Eq(-1)
|
||||
if len(sel.Nodes) != 1 {
|
||||
t.Errorf("Expected 1 node, found %v.", len(sel.Nodes))
|
||||
}
|
||||
// Should contain Footer
|
||||
foot := doc.Find(".footer")
|
||||
foot := Doc().Find(".footer")
|
||||
if !sel.Contains(foot.Nodes[0]) {
|
||||
t.Error("Index -1 of .pvk-content should contain .footer.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSlice(t *testing.T) {
|
||||
sel := doc.Find(".pvk-content").Slice(0, 2)
|
||||
sel := Doc().Find(".pvk-content").Slice(0, 2)
|
||||
if len(sel.Nodes) != 2 {
|
||||
t.Errorf("Expected 2 nodes, found %v.", len(sel.Nodes))
|
||||
}
|
||||
@@ -64,11 +64,11 @@ func TestSliceOutOfBounds(t *testing.T) {
|
||||
t.Error("Expected a panic, Slice() called with out of bounds indices.")
|
||||
}
|
||||
}()
|
||||
doc.Find(".pvk-content").Slice(2, 12)
|
||||
Doc().Find(".pvk-content").Slice(2, 12)
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
sel := doc.Find(".pvk-content")
|
||||
sel := Doc().Find(".pvk-content")
|
||||
node := sel.Get(1)
|
||||
if sel.Nodes[1] != node {
|
||||
t.Errorf("Expected node %v to be %v.", node, sel.Nodes[1])
|
||||
@@ -76,7 +76,7 @@ func TestGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNegative(t *testing.T) {
|
||||
sel := doc.Find(".pvk-content")
|
||||
sel := Doc().Find(".pvk-content")
|
||||
node := sel.Get(-3)
|
||||
if sel.Nodes[0] != node {
|
||||
t.Errorf("Expected node %v to be %v.", node, sel.Nodes[0])
|
||||
@@ -90,41 +90,41 @@ func TestGetInvalid(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
sel := doc.Find(".pvk-content")
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel.Get(129)
|
||||
}
|
||||
|
||||
func TestIndex(t *testing.T) {
|
||||
sel := doc.Find(".pvk-content")
|
||||
sel := Doc().Find(".pvk-content")
|
||||
if i := sel.Index(); i != 1 {
|
||||
t.Errorf("Expected index of 1, got %v.", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexSelector(t *testing.T) {
|
||||
sel := doc.Find(".hero-unit")
|
||||
sel := Doc().Find(".hero-unit")
|
||||
if i := sel.IndexSelector("div"); i != 4 {
|
||||
t.Errorf("Expected index of 4, got %v.", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexOfNode(t *testing.T) {
|
||||
sel := doc.Find("div.pvk-gutter")
|
||||
sel := Doc().Find("div.pvk-gutter")
|
||||
if i := sel.IndexOfNode(sel.Nodes[1]); i != 1 {
|
||||
t.Errorf("Expected index of 1, got %v.", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexOfNilNode(t *testing.T) {
|
||||
sel := doc.Find("div.pvk-gutter")
|
||||
sel := Doc().Find("div.pvk-gutter")
|
||||
if i := sel.IndexOfNode(nil); i != -1 {
|
||||
t.Errorf("Expected index of -1, got %v.", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexOfSelection(t *testing.T) {
|
||||
sel := doc.Find("div")
|
||||
sel2 := doc.Find(".hero-unit")
|
||||
sel := Doc().Find("div")
|
||||
sel2 := Doc().Find(".hero-unit")
|
||||
if i := sel.IndexOfSelection(sel2); i != 4 {
|
||||
t.Errorf("Expected index of 4, got %v.", i)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user