mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-10-05 00:42:50 +08:00
implement tests for selection methods with invalid selector strings
This commit is contained in:
@@ -21,9 +21,9 @@ func TestFindNotSelf(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestFindInvalidSelector(t *testing.T) {
|
||||
defer assertPanic(t)
|
||||
Doc().Find(":+ ^")
|
||||
func TestFindInvalid(t *testing.T) {
|
||||
sel := Doc().Find(":+ ^")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestChainedFind(t *testing.T) {
|
||||
@@ -31,6 +31,11 @@ func TestChainedFind(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 4)
|
||||
}
|
||||
|
||||
func TestChainedFindInvalid(t *testing.T) {
|
||||
sel := Doc().Find("div.hero-unit").Find("")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestChildren(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Children()
|
||||
assertLength(t, sel.Nodes, 5)
|
||||
@@ -58,6 +63,11 @@ func TestChildrenFiltered(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestChildrenFilteredInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").ChildrenFiltered("")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestChildrenFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.ChildrenFiltered(".hero-unit").End()
|
||||
@@ -69,6 +79,11 @@ func TestContentsFiltered(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestContentsFilteredInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").ContentsFiltered("~")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestContentsFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.ContentsFiltered(".hero-unit").End()
|
||||
@@ -102,6 +117,11 @@ func TestParentFiltered(t *testing.T) {
|
||||
assertClass(t, sel, "hero-unit")
|
||||
}
|
||||
|
||||
func TestParentFilteredInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").ParentFiltered("")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestParentFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ParentFiltered(".hero-unit").End()
|
||||
@@ -130,6 +150,11 @@ func TestParentsFiltered(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestParentsFilteredInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").ParentsFiltered("")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestParentsFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ParentsFiltered("body").End()
|
||||
@@ -141,6 +166,11 @@ func TestParentsUntil(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 6)
|
||||
}
|
||||
|
||||
func TestParentsUntilInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").ParentsUntil("")
|
||||
assertLength(t, sel.Nodes, 666) // TODO : ?
|
||||
}
|
||||
|
||||
func TestParentsUntilRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ParentsUntil("body").End()
|
||||
@@ -180,6 +210,11 @@ func TestParentsFilteredUntil(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestParentsFilteredUntilInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").ParentsFilteredUntil("", "")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestParentsFilteredUntilRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ParentsFilteredUntil(".pvk-content", "body").End()
|
||||
@@ -240,6 +275,11 @@ func TestSiblingsFiltered(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 3)
|
||||
}
|
||||
|
||||
func TestSiblingsFilteredInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter").SiblingsFiltered("")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestSiblingsFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter")
|
||||
sel2 := sel.SiblingsFiltered(".pvk-content").End()
|
||||
@@ -272,6 +312,11 @@ func TestNextFiltered(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestNextFilteredInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").NextFiltered("")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestNextFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.NextFiltered("div").End()
|
||||
@@ -310,6 +355,11 @@ func TestPrevFiltered(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 5)
|
||||
}
|
||||
|
||||
func TestPrevFilteredInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".row-fluid").PrevFiltered("")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestPrevFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".row-fluid")
|
||||
sel2 := sel.PrevFiltered(".row-fluid").End()
|
||||
@@ -342,6 +392,11 @@ func TestNextAllFiltered(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestNextAllFilteredInvalid(t *testing.T) {
|
||||
sel := Doc().Find("#cf2 .row-fluid").NextAllFiltered("")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestNextAllFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find("#cf2 .row-fluid")
|
||||
sel2 := sel.NextAllFiltered("[ng-cloak]").End()
|
||||
@@ -380,6 +435,11 @@ func TestPrevAllFiltered(t *testing.T) {
|
||||
assertLength(t, sel.Nodes, 3)
|
||||
}
|
||||
|
||||
func TestPrevAllFilteredInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter").PrevAllFiltered("")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestPrevAllFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter")
|
||||
sel2 := sel.PrevAllFiltered(".pvk-content").End()
|
||||
@@ -392,6 +452,11 @@ func TestNextUntil(t *testing.T) {
|
||||
assertSelectionIs(t, sel, "h4")
|
||||
}
|
||||
|
||||
func TestNextUntilInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".alert a").NextUntil("")
|
||||
assertLength(t, sel.Nodes, 100) // TODO : ?
|
||||
}
|
||||
|
||||
func TestNextUntil2(t *testing.T) {
|
||||
sel := Doc().Find("#cf2-1").NextUntil("[ng-cloak]")
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
@@ -446,6 +511,11 @@ func TestPrevUntil(t *testing.T) {
|
||||
assertSelectionIs(t, sel, "h4")
|
||||
}
|
||||
|
||||
func TestPrevUntilInvalid(t *testing.T) {
|
||||
sel := Doc().Find(".alert p").PrevUntil("")
|
||||
assertLength(t, sel.Nodes, 100) // TODO : ?
|
||||
}
|
||||
|
||||
func TestPrevUntil2(t *testing.T) {
|
||||
sel := Doc().Find("[ng-cloak]").PrevUntil(":not([ng-cloak])")
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
@@ -500,6 +570,11 @@ func TestNextFilteredUntil(t *testing.T) {
|
||||
assertSelectionIs(t, sel, "#n3", "#n5", "#nf3", "#nf5")
|
||||
}
|
||||
|
||||
func TestNextFilteredUntilInvalid(t *testing.T) {
|
||||
sel := Doc2().Find(".two").NextFilteredUntil("", "")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestNextFilteredUntilRollback(t *testing.T) {
|
||||
sel := Doc2().Find(".two")
|
||||
sel2 := sel.NextFilteredUntil(".even", ".six").End()
|
||||
@@ -542,6 +617,11 @@ func TestPrevFilteredUntil(t *testing.T) {
|
||||
assertSelectionIs(t, sel, "#n4", "#n2", "#nf4", "#nf2")
|
||||
}
|
||||
|
||||
func TestPrevFilteredUntilInvalid(t *testing.T) {
|
||||
sel := Doc2().Find(".five").PrevFilteredUntil("", "")
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestPrevFilteredUntilRollback(t *testing.T) {
|
||||
sel := Doc2().Find(".four")
|
||||
sel2 := sel.PrevFilteredUntil(".odd", ".one").End()
|
||||
@@ -598,6 +678,12 @@ func TestClosestNone(t *testing.T) {
|
||||
assertLength(t, sel2.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestClosestInvalid(t *testing.T) {
|
||||
sel := Doc().Find("h4")
|
||||
sel2 := sel.Closest("")
|
||||
assertLength(t, sel2.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestClosestMany(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.Closest(".pvk-content")
|
||||
|
Reference in New Issue
Block a user