implement tests for selection methods with invalid selector strings

This commit is contained in:
Martin Angers
2016-06-15 08:42:27 -04:00
parent 2cd8b4e49a
commit 9cc531274b
7 changed files with 155 additions and 20 deletions

View File

@@ -14,6 +14,11 @@ func TestFirstEmpty(t *testing.T) {
assertLength(t, sel.Nodes, 0)
}
func TestFirstInvalid(t *testing.T) {
sel := Doc().Find("").First()
assertLength(t, sel.Nodes, 0)
}
func TestFirstRollback(t *testing.T) {
sel := Doc().Find(".pvk-content")
sel2 := sel.First().End()
@@ -36,6 +41,11 @@ func TestLastEmpty(t *testing.T) {
assertLength(t, sel.Nodes, 0)
}
func TestLastInvalid(t *testing.T) {
sel := Doc().Find("").Last()
assertLength(t, sel.Nodes, 0)
}
func TestLastRollback(t *testing.T) {
sel := Doc().Find(".pvk-content")
sel2 := sel.Last().End()
@@ -63,6 +73,11 @@ func TestEqEmpty(t *testing.T) {
assertLength(t, sel.Nodes, 0)
}
func TestEqInvalid(t *testing.T) {
sel := Doc().Find("").Eq(0)
assertLength(t, sel.Nodes, 0)
}
func TestEqInvalidPositive(t *testing.T) {
sel := Doc().Find(".pvk-content").Eq(3)
assertLength(t, sel.Nodes, 0)
@@ -85,6 +100,16 @@ func TestSlice(t *testing.T) {
assertLength(t, sel.Nodes, 2)
}
func TestSliceEmpty(t *testing.T) {
sel := Doc().Find("x").Slice(0, 2)
assertLength(t, sel.Nodes, 0)
}
func TestSliceInvalid(t *testing.T) {
sel := Doc().Find("").Slice(0, 2)
assertLength(t, sel.Nodes, 0)
}
func TestSliceOutOfBounds(t *testing.T) {
defer assertPanic(t)
Doc().Find(".pvk-content").Slice(2, 12)
@@ -157,6 +182,13 @@ func TestIndexSelector(t *testing.T) {
}
}
func TestIndexSelectorInvalid(t *testing.T) {
sel := Doc().Find(".hero-unit")
if i := sel.IndexSelector(""); i != -1 {
t.Errorf("Expected index of -1, got %v.", i)
}
}
func TestIndexOfNode(t *testing.T) {
sel := Doc().Find("div.pvk-gutter")
if i := sel.IndexOfNode(sel.Nodes[1]); i != 1 {