mirror of
https://github.com/PuerkitoBio/goquery.git
synced 2024-04-21 12:31:36 +00:00
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package goquery
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestFilter(t *testing.T) {
|
|
sel := Doc().Find(".span12").Filter(".alert")
|
|
if len(sel.Nodes) != 1 {
|
|
t.Errorf("Expected 1 node, found %v.", len(sel.Nodes))
|
|
}
|
|
}
|
|
|
|
func TestFilterNone(t *testing.T) {
|
|
sel := Doc().Find(".span12").Filter(".zzalert")
|
|
if sel.Nodes != nil {
|
|
t.Error("Expected no node (nil), found some.")
|
|
}
|
|
}
|
|
|
|
func TestFilterFunction(t *testing.T) {
|
|
sel := Doc().Find(".pvk-content").FilterFunction(func(i int, s *Selection) bool {
|
|
return i > 0
|
|
})
|
|
if len(sel.Nodes) != 2 {
|
|
t.Errorf("Expected 2 nodes, found %v.", len(sel.Nodes))
|
|
}
|
|
}
|
|
|
|
func TestFilterNode(t *testing.T) {
|
|
sel := Doc().Find(".pvk-content")
|
|
sel2 := sel.FilterNodes(sel.Nodes[2])
|
|
if len(sel2.Nodes) != 1 {
|
|
t.Errorf("Expected 1 node, found %v.", len(sel2.Nodes))
|
|
}
|
|
}
|
|
|
|
func TestFilterSelection(t *testing.T) {
|
|
sel := Doc().Find(".link")
|
|
sel2 := Doc().Find("a[ng-click]")
|
|
sel3 := sel.FilterSelection(sel2)
|
|
if len(sel3.Nodes) != 1 {
|
|
t.Errorf("Expected 1 node, found %v.", len(sel3.Nodes))
|
|
}
|
|
}
|