add PrevAll() and PrevAllFiltered() with tests

This commit is contained in:
Martin Angers
2012-09-04 13:44:20 -04:00
parent 19c7e27fc0
commit af4a62048b
2 changed files with 53 additions and 0 deletions
+13
View File
@@ -203,6 +203,19 @@ func (this *Selection) PrevFiltered(selector string) *Selection {
return filterAndPush(this, getSiblingNodes(this.Nodes, siblingPrev), selector)
}
// PrevAll() gets all the preceding siblings of each element in the
// Selection. It returns a new Selection object containing the matched elements.
func (this *Selection) PrevAll() *Selection {
return pushStack(this, getSiblingNodes(this.Nodes, siblintPrevAll))
}
// PrevAllFiltered() gets all the preceding siblings of each element in the
// Selection filtered by a selector. It returns a new Selection object
// containing the matched elements.
func (this *Selection) PrevAllFiltered(selector string) *Selection {
return filterAndPush(this, getSiblingNodes(this.Nodes, siblintPrevAll), selector)
}
// Filter and push filters the nodes based on a selector, and pushes the results
// on the stack, with the srcSel as previous selection.
func filterAndPush(srcSel *Selection, nodes []*html.Node, selector string) *Selection {
+40
View File
@@ -178,3 +178,43 @@ func TestPrevFiltered(t *testing.T) {
sel := Doc().Root.Find(".row-fluid").PrevFiltered(".row-fluid")
AssertLength(t, sel.Nodes, 5)
}
func TestNextAll(t *testing.T) {
sel := Doc().Root.Find("#cf2 div:nth-child(1)").NextAll()
AssertLength(t, sel.Nodes, 3)
}
func TestNextAll2(t *testing.T) {
sel := Doc().Root.Find("div[ng-cloak]").NextAll()
AssertLength(t, sel.Nodes, 1)
}
func TestNextAllNone(t *testing.T) {
sel := Doc().Root.Find(".footer").NextAll()
AssertLength(t, sel.Nodes, 0)
}
func TestNextAllFiltered(t *testing.T) {
sel := Doc().Root.Find("#cf2 .row-fluid").NextAllFiltered("[ng-cloak]")
AssertLength(t, sel.Nodes, 2)
}
func TestNextAllFiltered2(t *testing.T) {
sel := Doc().Root.Find(".close").NextAllFiltered("h4")
AssertLength(t, sel.Nodes, 1)
}
func TestPrevAll(t *testing.T) {
sel := Doc().Root.Find("[ng-view]").PrevAll()
AssertLength(t, sel.Nodes, 2)
}
func TestPrevAll2(t *testing.T) {
sel := Doc().Root.Find(".pvk-gutter").PrevAll()
AssertLength(t, sel.Nodes, 6)
}
func TestPrevAllFiltered(t *testing.T) {
sel := Doc().Root.Find(".pvk-gutter").PrevAllFiltered(".pvk-content")
AssertLength(t, sel.Nodes, 3)
}