mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-10-05 08:46:53 +08:00
add Index() methods
This commit is contained in:
@@ -93,3 +93,39 @@ func TestGetInvalid(t *testing.T) {
|
||||
sel := doc.Find(".pvk-content")
|
||||
sel.Get(129)
|
||||
}
|
||||
|
||||
func TestIndex(t *testing.T) {
|
||||
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")
|
||||
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")
|
||||
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")
|
||||
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")
|
||||
if i := sel.IndexOfSelection(sel2); i != 4 {
|
||||
t.Errorf("Expected index of 4, got %v.", i)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user