mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-09-27 05:06:16 +08:00
make test assert helpers private
This commit is contained in:
@@ -6,23 +6,23 @@ import (
|
||||
|
||||
func TestFirst(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").First()
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestFirstEmpty(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-zzcontentzz").First()
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestFirstRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.First().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestLast(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Last()
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
|
||||
// Should contain Footer
|
||||
foot := Doc().Find(".footer")
|
||||
@@ -33,23 +33,23 @@ func TestLast(t *testing.T) {
|
||||
|
||||
func TestLastEmpty(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-zzcontentzz").Last()
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestLastRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.Last().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestEq(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Eq(1)
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestEqNegative(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Eq(-1)
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
|
||||
// Should contain Footer
|
||||
foot := Doc().Find(".footer")
|
||||
@@ -60,65 +60,65 @@ func TestEqNegative(t *testing.T) {
|
||||
|
||||
func TestEqEmpty(t *testing.T) {
|
||||
sel := Doc().Find("something_random_that_does_not_exists").Eq(0)
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestEqInvalidPositive(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Eq(3)
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestEqInvalidNegative(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Eq(-4)
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestEqRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.Eq(1).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestSlice(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Slice(0, 2)
|
||||
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestSliceOutOfBounds(t *testing.T) {
|
||||
defer AssertPanic(t)
|
||||
defer assertPanic(t)
|
||||
Doc().Find(".pvk-content").Slice(2, 12)
|
||||
}
|
||||
|
||||
func TestNegativeSliceStart(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").Slice(-2, 3)
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
AssertSelectionIs(t, sel.Eq(0), "#cf3")
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
assertSelectionIs(t, sel.Eq(0), "#cf3")
|
||||
}
|
||||
|
||||
func TestNegativeSliceEnd(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").Slice(1, -1)
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
AssertSelectionIs(t, sel.Eq(0), "#cf2")
|
||||
AssertSelectionIs(t, sel.Eq(1), "#cf3")
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
assertSelectionIs(t, sel.Eq(0), "#cf2")
|
||||
assertSelectionIs(t, sel.Eq(1), "#cf3")
|
||||
}
|
||||
|
||||
func TestNegativeSliceBoth(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").Slice(-3, -1)
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
AssertSelectionIs(t, sel.Eq(0), "#cf2")
|
||||
AssertSelectionIs(t, sel.Eq(1), "#cf3")
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
assertSelectionIs(t, sel.Eq(0), "#cf2")
|
||||
assertSelectionIs(t, sel.Eq(1), "#cf3")
|
||||
}
|
||||
|
||||
func TestNegativeSliceOutOfBounds(t *testing.T) {
|
||||
defer AssertPanic(t)
|
||||
defer assertPanic(t)
|
||||
Doc().Find(".container-fluid").Slice(-12, -7)
|
||||
}
|
||||
|
||||
func TestSliceRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.Slice(0, 2).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
@@ -138,7 +138,7 @@ func TestGetNegative(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetInvalid(t *testing.T) {
|
||||
defer AssertPanic(t)
|
||||
defer assertPanic(t)
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel.Get(129)
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ func BenchmarkMetalReviewExample(b *testing.B) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
b.StopTimer()
|
||||
doc := LoadDoc("metalreview.html")
|
||||
doc := loadDoc("metalreview.html")
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
doc.Find(".slider-row:nth-child(1) .slider-item").Each(func(i int, s *Selection) {
|
||||
|
@@ -6,63 +6,63 @@ import (
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
sel := Doc().Find("div.row-fluid").Add("a")
|
||||
AssertLength(t, sel.Nodes, 19)
|
||||
assertLength(t, sel.Nodes, 19)
|
||||
}
|
||||
|
||||
func TestAddRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.Add("a").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestAddSelection(t *testing.T) {
|
||||
sel := Doc().Find("div.row-fluid")
|
||||
sel2 := Doc().Find("a")
|
||||
sel = sel.AddSelection(sel2)
|
||||
AssertLength(t, sel.Nodes, 19)
|
||||
assertLength(t, sel.Nodes, 19)
|
||||
}
|
||||
|
||||
func TestAddSelectionNil(t *testing.T) {
|
||||
sel := Doc().Find("div.row-fluid")
|
||||
AssertLength(t, sel.Nodes, 9)
|
||||
assertLength(t, sel.Nodes, 9)
|
||||
|
||||
sel = sel.AddSelection(nil)
|
||||
AssertLength(t, sel.Nodes, 9)
|
||||
assertLength(t, sel.Nodes, 9)
|
||||
}
|
||||
|
||||
func TestAddSelectionRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.Find("a")
|
||||
sel2 = sel.AddSelection(sel2).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestAddNodes(t *testing.T) {
|
||||
sel := Doc().Find("div.pvk-gutter")
|
||||
sel2 := Doc().Find(".pvk-content")
|
||||
sel = sel.AddNodes(sel2.Nodes...)
|
||||
AssertLength(t, sel.Nodes, 9)
|
||||
assertLength(t, sel.Nodes, 9)
|
||||
}
|
||||
|
||||
func TestAddNodesNone(t *testing.T) {
|
||||
sel := Doc().Find("div.pvk-gutter").AddNodes()
|
||||
AssertLength(t, sel.Nodes, 6)
|
||||
assertLength(t, sel.Nodes, 6)
|
||||
}
|
||||
|
||||
func TestAddNodesRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.Find("a")
|
||||
sel2 = sel.AddNodes(sel2.Nodes...).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestAndSelf(t *testing.T) {
|
||||
sel := Doc().Find(".span12").Last().AndSelf()
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestAndSelfRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.Find("a").AndSelf().End().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
@@ -6,25 +6,25 @@ import (
|
||||
|
||||
func TestFilter(t *testing.T) {
|
||||
sel := Doc().Find(".span12").Filter(".alert")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestFilterNone(t *testing.T) {
|
||||
sel := Doc().Find(".span12").Filter(".zzalert")
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestFilterRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.Filter(".alert").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestFilterFunction(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").FilterFunction(func(i int, s *Selection) bool {
|
||||
return i > 0
|
||||
})
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestFilterFunctionRollback(t *testing.T) {
|
||||
@@ -32,33 +32,33 @@ func TestFilterFunctionRollback(t *testing.T) {
|
||||
sel2 := sel.FilterFunction(func(i int, s *Selection) bool {
|
||||
return i > 0
|
||||
}).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestFilterNode(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.FilterNodes(sel.Nodes[2])
|
||||
AssertLength(t, sel2.Nodes, 1)
|
||||
assertLength(t, sel2.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestFilterNodeRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.FilterNodes(sel.Nodes[2]).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestFilterSelection(t *testing.T) {
|
||||
sel := Doc().Find(".link")
|
||||
sel2 := Doc().Find("a[ng-click]")
|
||||
sel3 := sel.FilterSelection(sel2)
|
||||
AssertLength(t, sel3.Nodes, 1)
|
||||
assertLength(t, sel3.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestFilterSelectionRollback(t *testing.T) {
|
||||
sel := Doc().Find(".link")
|
||||
sel2 := Doc().Find("a[ng-click]")
|
||||
sel2 = sel.FilterSelection(sel2).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestFilterSelectionNil(t *testing.T) {
|
||||
@@ -66,30 +66,30 @@ func TestFilterSelectionNil(t *testing.T) {
|
||||
|
||||
sel := Doc().Find(".link")
|
||||
sel3 := sel.FilterSelection(sel2)
|
||||
AssertLength(t, sel3.Nodes, 0)
|
||||
assertLength(t, sel3.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestNot(t *testing.T) {
|
||||
sel := Doc().Find(".span12").Not(".alert")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestNotRollback(t *testing.T) {
|
||||
sel := Doc().Find(".span12")
|
||||
sel2 := sel.Not(".alert").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNotNone(t *testing.T) {
|
||||
sel := Doc().Find(".span12").Not(".zzalert")
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestNotFunction(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").NotFunction(func(i int, s *Selection) bool {
|
||||
return i > 0
|
||||
})
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestNotFunctionRollback(t *testing.T) {
|
||||
@@ -97,65 +97,65 @@ func TestNotFunctionRollback(t *testing.T) {
|
||||
sel2 := sel.NotFunction(func(i int, s *Selection) bool {
|
||||
return i > 0
|
||||
}).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNotNode(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.NotNodes(sel.Nodes[2])
|
||||
AssertLength(t, sel2.Nodes, 2)
|
||||
assertLength(t, sel2.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestNotNodeRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.NotNodes(sel.Nodes[2]).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNotSelection(t *testing.T) {
|
||||
sel := Doc().Find(".link")
|
||||
sel2 := Doc().Find("a[ng-click]")
|
||||
sel3 := sel.NotSelection(sel2)
|
||||
AssertLength(t, sel3.Nodes, 6)
|
||||
assertLength(t, sel3.Nodes, 6)
|
||||
}
|
||||
|
||||
func TestNotSelectionRollback(t *testing.T) {
|
||||
sel := Doc().Find(".link")
|
||||
sel2 := Doc().Find("a[ng-click]")
|
||||
sel2 = sel.NotSelection(sel2).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestIntersection(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter")
|
||||
sel2 := Doc().Find("div").Intersection(sel)
|
||||
AssertLength(t, sel2.Nodes, 6)
|
||||
assertLength(t, sel2.Nodes, 6)
|
||||
}
|
||||
|
||||
func TestIntersectionRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter")
|
||||
sel2 := Doc().Find("div")
|
||||
sel2 = sel.Intersection(sel2).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestHas(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").Has(".center-content")
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
// Has() returns the high-level .container-fluid div, and the one that is the immediate parent of center-content
|
||||
}
|
||||
|
||||
func TestHasRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.Has(".center-content").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestHasNodes(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := Doc().Find(".center-content")
|
||||
sel = sel.HasNodes(sel2.Nodes...)
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
// Has() returns the high-level .container-fluid div, and the one that is the immediate parent of center-content
|
||||
}
|
||||
|
||||
@@ -163,29 +163,29 @@ func TestHasNodesRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := Doc().Find(".center-content")
|
||||
sel2 = sel.HasNodes(sel2.Nodes...).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestHasSelection(t *testing.T) {
|
||||
sel := Doc().Find("p")
|
||||
sel2 := Doc().Find("small")
|
||||
sel = sel.HasSelection(sel2)
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestHasSelectionRollback(t *testing.T) {
|
||||
sel := Doc().Find("p")
|
||||
sel2 := Doc().Find("small")
|
||||
sel2 = sel.HasSelection(sel2).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestEnd(t *testing.T) {
|
||||
sel := Doc().Find("p").Has("small").End()
|
||||
AssertLength(t, sel.Nodes, 4)
|
||||
assertLength(t, sel.Nodes, 4)
|
||||
}
|
||||
|
||||
func TestEndToTop(t *testing.T) {
|
||||
sel := Doc().Find("p").Has("small").End().End().End()
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ func TestEach(t *testing.T) {
|
||||
if cnt != 4 {
|
||||
t.Errorf("Expected Each() to call function 4 times, got %v times.", cnt)
|
||||
}
|
||||
AssertLength(t, sel.Nodes, 6)
|
||||
assertLength(t, sel.Nodes, 6)
|
||||
}
|
||||
|
||||
func TestEachWithBreak(t *testing.T) {
|
||||
@@ -32,7 +32,7 @@ func TestEachWithBreak(t *testing.T) {
|
||||
if cnt != 1 {
|
||||
t.Errorf("Expected Each() to call function 1 time, got %v times.", cnt)
|
||||
}
|
||||
AssertLength(t, sel.Nodes, 6)
|
||||
assertLength(t, sel.Nodes, 6)
|
||||
}
|
||||
|
||||
func TestEachEmptySelection(t *testing.T) {
|
||||
@@ -46,7 +46,7 @@ func TestEachEmptySelection(t *testing.T) {
|
||||
t.Error("Expected Each() to not be called on empty Selection.")
|
||||
}
|
||||
sel2 := sel.Find("div")
|
||||
AssertLength(t, sel2.Nodes, 0)
|
||||
assertLength(t, sel2.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestMap(t *testing.T) {
|
||||
|
@@ -175,7 +175,7 @@ func (s *Selection) Before(selector string) *Selection {
|
||||
return s.BeforeMatcher(cascadia.MustCompile(selector))
|
||||
}
|
||||
|
||||
// BeforeSelector applies the matcher from the root document, and inserts the matched
|
||||
// BeforeMatcher applies the matcher from the root document, and inserts the matched
|
||||
// elements before each element in the set of matched elements.
|
||||
// This follows the same rules as Selection.After.
|
||||
func (s *Selection) BeforeMatcher(m Matcher) *Selection {
|
||||
@@ -214,7 +214,7 @@ func (s *Selection) Clone() *Selection {
|
||||
}
|
||||
|
||||
// Empty removes all children nodes from the set of matched elements.
|
||||
// Returns the children nodes in a new Selection on the current Selection stack.
|
||||
// Returns the children nodes in a new Selection.
|
||||
func (s *Selection) Empty() *Selection {
|
||||
nodes := make([]*html.Node, 0)
|
||||
|
||||
@@ -240,9 +240,9 @@ func (s *Selection) Remove() *Selection {
|
||||
return s
|
||||
}
|
||||
|
||||
// RemoveFilter removes the set of matched elements by selector.
|
||||
// RemoveFiltered removes the set of matched elements by selector.
|
||||
// Returns the Selection of removed nodes.
|
||||
func (s *Selection) RemoveFilter(selector string) *Selection {
|
||||
func (s *Selection) RemoveFiltered(selector string) *Selection {
|
||||
return s.RemoveMatcher(cascadia.MustCompile(selector))
|
||||
}
|
||||
|
||||
|
@@ -8,9 +8,20 @@ func TestAfter(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#main").After("#nf6")
|
||||
|
||||
AssertLength(t, doc.Find("#main #nf6").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#foot #nf6").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#main + #nf6").Nodes, 1)
|
||||
assertLength(t, doc.Find("#main #nf6").Nodes, 0)
|
||||
assertLength(t, doc.Find("#foot #nf6").Nodes, 0)
|
||||
assertLength(t, doc.Find("#main + #nf6").Nodes, 1)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestAfterMany(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find(".one").After("#nf6")
|
||||
|
||||
assertLength(t, doc.Find("#foot #nf6").Nodes, 1)
|
||||
assertLength(t, doc.Find("#main #nf6").Nodes, 1)
|
||||
assertLength(t, doc.Find(".one + #nf6").Nodes, 2)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestAfterWithRemoved(t *testing.T) {
|
||||
@@ -18,75 +29,94 @@ func TestAfterWithRemoved(t *testing.T) {
|
||||
s := doc.Find("#main").Remove()
|
||||
s.After("#nf6")
|
||||
|
||||
AssertLength(t, s.Find("#nf6").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#nf6").Nodes, 0)
|
||||
assertLength(t, s.Find("#nf6").Nodes, 0)
|
||||
assertLength(t, doc.Find("#nf6").Nodes, 0)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestAfterSelection(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#main").AfterSelection(doc.Find("#nf1, #nf2"))
|
||||
|
||||
AssertLength(t, doc.Find("#main #nf1, #main #nf2").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#foot #nf1, #foot #nf2").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#main + #nf1, #nf1 + #nf2").Nodes, 2)
|
||||
assertLength(t, doc.Find("#main #nf1, #main #nf2").Nodes, 0)
|
||||
assertLength(t, doc.Find("#foot #nf1, #foot #nf2").Nodes, 0)
|
||||
assertLength(t, doc.Find("#main + #nf1, #nf1 + #nf2").Nodes, 2)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestAfterHtml(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#main").AfterHtml("<strong>new node</strong>")
|
||||
|
||||
AssertLength(t, doc.Find("#main + strong").Nodes, 1)
|
||||
assertLength(t, doc.Find("#main + strong").Nodes, 1)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestAppend(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#main").Append("#nf6")
|
||||
|
||||
AssertLength(t, doc.Find("#foot #nf6").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#main #nf6").Nodes, 1)
|
||||
assertLength(t, doc.Find("#foot #nf6").Nodes, 0)
|
||||
assertLength(t, doc.Find("#main #nf6").Nodes, 1)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestAppendBody(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("body").Append("#nf6")
|
||||
|
||||
AssertLength(t, doc.Find("#foot #nf6").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#main #nf6").Nodes, 0)
|
||||
AssertLength(t, doc.Find("body > #nf6").Nodes, 1)
|
||||
assertLength(t, doc.Find("#foot #nf6").Nodes, 0)
|
||||
assertLength(t, doc.Find("#main #nf6").Nodes, 0)
|
||||
assertLength(t, doc.Find("body > #nf6").Nodes, 1)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestAppendSelection(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#main").AppendSelection(doc.Find("#nf1, #nf2"))
|
||||
|
||||
AssertLength(t, doc.Find("#foot #nf1").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#foot #nf2").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#main #nf1").Nodes, 1)
|
||||
AssertLength(t, doc.Find("#main #nf2").Nodes, 1)
|
||||
assertLength(t, doc.Find("#foot #nf1").Nodes, 0)
|
||||
assertLength(t, doc.Find("#foot #nf2").Nodes, 0)
|
||||
assertLength(t, doc.Find("#main #nf1").Nodes, 1)
|
||||
assertLength(t, doc.Find("#main #nf2").Nodes, 1)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestAppendSelectionExisting(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#main").AppendSelection(doc.Find("#n1, #n2"))
|
||||
|
||||
assertClass(t, doc.Find("#main :nth-child(1)"), "three")
|
||||
assertClass(t, doc.Find("#main :nth-child(5)"), "one")
|
||||
assertClass(t, doc.Find("#main :nth-child(6)"), "two")
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestAppendClone(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#n1").AppendSelection(doc.Find("#nf1").Clone())
|
||||
|
||||
AssertLength(t, doc.Find("#foot #nf1").Nodes, 1)
|
||||
AssertLength(t, doc.Find("#main #nf1").Nodes, 1)
|
||||
assertLength(t, doc.Find("#foot #nf1").Nodes, 1)
|
||||
assertLength(t, doc.Find("#main #nf1").Nodes, 1)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestAppendHtml(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("div").AppendHtml("<strong>new node</strong>")
|
||||
|
||||
AssertLength(t, doc.Find("strong").Nodes, 14)
|
||||
assertLength(t, doc.Find("strong").Nodes, 14)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestBefore(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#main").Before("#nf6")
|
||||
|
||||
AssertLength(t, doc.Find("#main #nf6").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#foot #nf6").Nodes, 0)
|
||||
AssertLength(t, doc.Find("body > #nf6:first-child").Nodes, 1)
|
||||
assertLength(t, doc.Find("#main #nf6").Nodes, 0)
|
||||
assertLength(t, doc.Find("#foot #nf6").Nodes, 0)
|
||||
assertLength(t, doc.Find("body > #nf6:first-child").Nodes, 1)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestBeforeWithRemoved(t *testing.T) {
|
||||
@@ -94,63 +124,71 @@ func TestBeforeWithRemoved(t *testing.T) {
|
||||
s := doc.Find("#main").Remove()
|
||||
s.Before("#nf6")
|
||||
|
||||
AssertLength(t, s.Find("#nf6").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#nf6").Nodes, 0)
|
||||
assertLength(t, s.Find("#nf6").Nodes, 0)
|
||||
assertLength(t, doc.Find("#nf6").Nodes, 0)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestBeforeSelection(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#main").BeforeSelection(doc.Find("#nf1, #nf2"))
|
||||
|
||||
AssertLength(t, doc.Find("#main #nf1, #main #nf2").Nodes, 0)
|
||||
AssertLength(t, doc.Find("#foot #nf1, #foot #nf2").Nodes, 0)
|
||||
AssertLength(t, doc.Find("body > #nf1:first-child, #nf1 + #nf2").Nodes, 2)
|
||||
assertLength(t, doc.Find("#main #nf1, #main #nf2").Nodes, 0)
|
||||
assertLength(t, doc.Find("#foot #nf1, #foot #nf2").Nodes, 0)
|
||||
assertLength(t, doc.Find("body > #nf1:first-child, #nf1 + #nf2").Nodes, 2)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestBeforeHtml(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#main").BeforeHtml("<strong>new node</strong>")
|
||||
|
||||
AssertLength(t, doc.Find("body > strong:first-child").Nodes, 1)
|
||||
assertLength(t, doc.Find("body > strong:first-child").Nodes, 1)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestEmpty(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
s := doc.Find("#main").Empty()
|
||||
|
||||
AssertLength(t, doc.Find("#main").Children().Nodes, 0)
|
||||
AssertLength(t, s.Filter("div").Nodes, 6)
|
||||
assertLength(t, doc.Find("#main").Children().Nodes, 0)
|
||||
assertLength(t, s.Filter("div").Nodes, 6)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestRemove(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("#nf1").Remove()
|
||||
|
||||
AssertLength(t, doc.Find("#foot #nf1").Nodes, 0)
|
||||
assertLength(t, doc.Find("#foot #nf1").Nodes, 0)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestRemoveAll(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("*").Remove()
|
||||
|
||||
AssertLength(t, doc.Find("*").Nodes, 0)
|
||||
assertLength(t, doc.Find("*").Nodes, 0)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestRemoveRoot(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
doc.Find("html").Remove()
|
||||
|
||||
AssertLength(t, doc.Find("html").Nodes, 0)
|
||||
assertLength(t, doc.Find("html").Nodes, 0)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestRemoveFilter(t *testing.T) {
|
||||
func TestRemoveFiltered(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
nf6 := doc.Find("#nf6")
|
||||
s := doc.Find("div").RemoveFilter("#nf6")
|
||||
s := doc.Find("div").RemoveFiltered("#nf6")
|
||||
|
||||
AssertLength(t, doc.Find("#nf6").Nodes, 0)
|
||||
AssertLength(t, s.Nodes, 1)
|
||||
assertLength(t, doc.Find("#nf6").Nodes, 0)
|
||||
assertLength(t, s.Nodes, 1)
|
||||
if nf6.Nodes[0] != s.Nodes[0] {
|
||||
t.Error("Removed node does not match original")
|
||||
}
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
@@ -7,672 +7,672 @@ import (
|
||||
|
||||
func TestFind(t *testing.T) {
|
||||
sel := Doc().Find("div.row-fluid")
|
||||
AssertLength(t, sel.Nodes, 9)
|
||||
assertLength(t, sel.Nodes, 9)
|
||||
}
|
||||
|
||||
func TestFindRollback(t *testing.T) {
|
||||
sel := Doc().Find("div.row-fluid")
|
||||
sel2 := sel.Find("a").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestFindNotSelf(t *testing.T) {
|
||||
sel := Doc().Find("h1").Find("h1")
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestFindInvalidSelector(t *testing.T) {
|
||||
defer AssertPanic(t)
|
||||
defer assertPanic(t)
|
||||
Doc().Find(":+ ^")
|
||||
}
|
||||
|
||||
func TestChainedFind(t *testing.T) {
|
||||
sel := Doc().Find("div.hero-unit").Find(".row-fluid")
|
||||
AssertLength(t, sel.Nodes, 4)
|
||||
assertLength(t, sel.Nodes, 4)
|
||||
}
|
||||
|
||||
func TestChildren(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Children()
|
||||
AssertLength(t, sel.Nodes, 5)
|
||||
assertLength(t, sel.Nodes, 5)
|
||||
}
|
||||
|
||||
func TestChildrenRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.Children().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestContents(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").Contents()
|
||||
AssertLength(t, sel.Nodes, 13)
|
||||
assertLength(t, sel.Nodes, 13)
|
||||
}
|
||||
|
||||
func TestContentsRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.Contents().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestChildrenFiltered(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").ChildrenFiltered(".hero-unit")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestChildrenFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.ChildrenFiltered(".hero-unit").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestContentsFiltered(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").ContentsFiltered(".hero-unit")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestContentsFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content")
|
||||
sel2 := sel.ContentsFiltered(".hero-unit").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestChildrenFilteredNone(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-content").ChildrenFiltered("a.btn")
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestParent(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").Parent()
|
||||
AssertLength(t, sel.Nodes, 3)
|
||||
assertLength(t, sel.Nodes, 3)
|
||||
}
|
||||
|
||||
func TestParentRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.Parent().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestParentBody(t *testing.T) {
|
||||
sel := Doc().Find("body").Parent()
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestParentFiltered(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").ParentFiltered(".hero-unit")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
AssertClass(t, sel, "hero-unit")
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
assertClass(t, sel, "hero-unit")
|
||||
}
|
||||
|
||||
func TestParentFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ParentFiltered(".hero-unit").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestParents(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").Parents()
|
||||
AssertLength(t, sel.Nodes, 8)
|
||||
assertLength(t, sel.Nodes, 8)
|
||||
}
|
||||
|
||||
func TestParentsOrder(t *testing.T) {
|
||||
sel := Doc().Find("#cf2").Parents()
|
||||
AssertLength(t, sel.Nodes, 6)
|
||||
AssertSelectionIs(t, sel, ".hero-unit", ".pvk-content", "div.row-fluid", "#cf1", "body", "html")
|
||||
assertLength(t, sel.Nodes, 6)
|
||||
assertSelectionIs(t, sel, ".hero-unit", ".pvk-content", "div.row-fluid", "#cf1", "body", "html")
|
||||
}
|
||||
|
||||
func TestParentsRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.Parents().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestParentsFiltered(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").ParentsFiltered("body")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestParentsFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ParentsFiltered("body").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestParentsUntil(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").ParentsUntil("body")
|
||||
AssertLength(t, sel.Nodes, 6)
|
||||
assertLength(t, sel.Nodes, 6)
|
||||
}
|
||||
|
||||
func TestParentsUntilRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ParentsUntil("body").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestParentsUntilSelection(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := Doc().Find(".pvk-content")
|
||||
sel = sel.ParentsUntilSelection(sel2)
|
||||
AssertLength(t, sel.Nodes, 3)
|
||||
assertLength(t, sel.Nodes, 3)
|
||||
}
|
||||
|
||||
func TestParentsUntilSelectionRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := Doc().Find(".pvk-content")
|
||||
sel2 = sel.ParentsUntilSelection(sel2).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestParentsUntilNodes(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := Doc().Find(".pvk-content, .hero-unit")
|
||||
sel = sel.ParentsUntilNodes(sel2.Nodes...)
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestParentsUntilNodesRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := Doc().Find(".pvk-content, .hero-unit")
|
||||
sel2 = sel.ParentsUntilNodes(sel2.Nodes...).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestParentsFilteredUntil(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").ParentsFilteredUntil(".pvk-content", "body")
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestParentsFilteredUntilRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ParentsFilteredUntil(".pvk-content", "body").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestParentsFilteredUntilSelection(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := Doc().Find(".row-fluid")
|
||||
sel = sel.ParentsFilteredUntilSelection("div", sel2)
|
||||
AssertLength(t, sel.Nodes, 3)
|
||||
assertLength(t, sel.Nodes, 3)
|
||||
}
|
||||
|
||||
func TestParentsFilteredUntilSelectionRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := Doc().Find(".row-fluid")
|
||||
sel2 = sel.ParentsFilteredUntilSelection("div", sel2).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestParentsFilteredUntilNodes(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := Doc().Find(".row-fluid")
|
||||
sel = sel.ParentsFilteredUntilNodes("body", sel2.Nodes...)
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestParentsFilteredUntilNodesRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := Doc().Find(".row-fluid")
|
||||
sel2 = sel.ParentsFilteredUntilNodes("body", sel2.Nodes...).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestSiblings(t *testing.T) {
|
||||
sel := Doc().Find("h1").Siblings()
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestSiblingsRollback(t *testing.T) {
|
||||
sel := Doc().Find("h1")
|
||||
sel2 := sel.Siblings().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestSiblings2(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter").Siblings()
|
||||
AssertLength(t, sel.Nodes, 9)
|
||||
assertLength(t, sel.Nodes, 9)
|
||||
}
|
||||
|
||||
func TestSiblings3(t *testing.T) {
|
||||
sel := Doc().Find("body>.container-fluid").Siblings()
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestSiblingsFiltered(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter").SiblingsFiltered(".pvk-content")
|
||||
AssertLength(t, sel.Nodes, 3)
|
||||
assertLength(t, sel.Nodes, 3)
|
||||
}
|
||||
|
||||
func TestSiblingsFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter")
|
||||
sel2 := sel.SiblingsFiltered(".pvk-content").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNext(t *testing.T) {
|
||||
sel := Doc().Find("h1").Next()
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestNextRollback(t *testing.T) {
|
||||
sel := Doc().Find("h1")
|
||||
sel2 := sel.Next().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNext2(t *testing.T) {
|
||||
sel := Doc().Find(".close").Next()
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestNextNone(t *testing.T) {
|
||||
sel := Doc().Find("small").Next()
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestNextFiltered(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").NextFiltered("div")
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestNextFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.NextFiltered("div").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNextFiltered2(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid").NextFiltered("[ng-view]")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestPrev(t *testing.T) {
|
||||
sel := Doc().Find(".red").Prev()
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
AssertClass(t, sel, "green")
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
assertClass(t, sel, "green")
|
||||
}
|
||||
|
||||
func TestPrevRollback(t *testing.T) {
|
||||
sel := Doc().Find(".red")
|
||||
sel2 := sel.Prev().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestPrev2(t *testing.T) {
|
||||
sel := Doc().Find(".row-fluid").Prev()
|
||||
AssertLength(t, sel.Nodes, 5)
|
||||
assertLength(t, sel.Nodes, 5)
|
||||
}
|
||||
|
||||
func TestPrevNone(t *testing.T) {
|
||||
sel := Doc().Find("h2").Prev()
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestPrevFiltered(t *testing.T) {
|
||||
sel := Doc().Find(".row-fluid").PrevFiltered(".row-fluid")
|
||||
AssertLength(t, sel.Nodes, 5)
|
||||
assertLength(t, sel.Nodes, 5)
|
||||
}
|
||||
|
||||
func TestPrevFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".row-fluid")
|
||||
sel2 := sel.PrevFiltered(".row-fluid").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNextAll(t *testing.T) {
|
||||
sel := Doc().Find("#cf2 div:nth-child(1)").NextAll()
|
||||
AssertLength(t, sel.Nodes, 3)
|
||||
assertLength(t, sel.Nodes, 3)
|
||||
}
|
||||
|
||||
func TestNextAllRollback(t *testing.T) {
|
||||
sel := Doc().Find("#cf2 div:nth-child(1)")
|
||||
sel2 := sel.NextAll().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNextAll2(t *testing.T) {
|
||||
sel := Doc().Find("div[ng-cloak]").NextAll()
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestNextAllNone(t *testing.T) {
|
||||
sel := Doc().Find(".footer").NextAll()
|
||||
AssertLength(t, sel.Nodes, 0)
|
||||
assertLength(t, sel.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestNextAllFiltered(t *testing.T) {
|
||||
sel := Doc().Find("#cf2 .row-fluid").NextAllFiltered("[ng-cloak]")
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestNextAllFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find("#cf2 .row-fluid")
|
||||
sel2 := sel.NextAllFiltered("[ng-cloak]").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNextAllFiltered2(t *testing.T) {
|
||||
sel := Doc().Find(".close").NextAllFiltered("h4")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
}
|
||||
|
||||
func TestPrevAll(t *testing.T) {
|
||||
sel := Doc().Find("[ng-view]").PrevAll()
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
}
|
||||
|
||||
func TestPrevAllOrder(t *testing.T) {
|
||||
sel := Doc().Find("[ng-view]").PrevAll()
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
AssertSelectionIs(t, sel, "#cf4", "#cf3")
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
assertSelectionIs(t, sel, "#cf4", "#cf3")
|
||||
}
|
||||
|
||||
func TestPrevAllRollback(t *testing.T) {
|
||||
sel := Doc().Find("[ng-view]")
|
||||
sel2 := sel.PrevAll().End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestPrevAll2(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter").PrevAll()
|
||||
AssertLength(t, sel.Nodes, 6)
|
||||
assertLength(t, sel.Nodes, 6)
|
||||
}
|
||||
|
||||
func TestPrevAllFiltered(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter").PrevAllFiltered(".pvk-content")
|
||||
AssertLength(t, sel.Nodes, 3)
|
||||
assertLength(t, sel.Nodes, 3)
|
||||
}
|
||||
|
||||
func TestPrevAllFilteredRollback(t *testing.T) {
|
||||
sel := Doc().Find(".pvk-gutter")
|
||||
sel2 := sel.PrevAllFiltered(".pvk-content").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNextUntil(t *testing.T) {
|
||||
sel := Doc().Find(".alert a").NextUntil("p")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
AssertSelectionIs(t, sel, "h4")
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
assertSelectionIs(t, sel, "h4")
|
||||
}
|
||||
|
||||
func TestNextUntil2(t *testing.T) {
|
||||
sel := Doc().Find("#cf2-1").NextUntil("[ng-cloak]")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
AssertSelectionIs(t, sel, "#cf2-2")
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
assertSelectionIs(t, sel, "#cf2-2")
|
||||
}
|
||||
|
||||
func TestNextUntilOrder(t *testing.T) {
|
||||
sel := Doc().Find("#cf2-1").NextUntil("#cf2-4")
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
AssertSelectionIs(t, sel, "#cf2-2", "#cf2-3")
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
assertSelectionIs(t, sel, "#cf2-2", "#cf2-3")
|
||||
}
|
||||
|
||||
func TestNextUntilRollback(t *testing.T) {
|
||||
sel := Doc().Find("#cf2-1")
|
||||
sel2 := sel.PrevUntil("#cf2-4").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNextUntilSelection(t *testing.T) {
|
||||
sel := Doc2().Find("#n2")
|
||||
sel2 := Doc2().Find("#n4")
|
||||
sel2 = sel.NextUntilSelection(sel2)
|
||||
AssertLength(t, sel2.Nodes, 1)
|
||||
AssertSelectionIs(t, sel2, "#n3")
|
||||
assertLength(t, sel2.Nodes, 1)
|
||||
assertSelectionIs(t, sel2, "#n3")
|
||||
}
|
||||
|
||||
func TestNextUntilSelectionRollback(t *testing.T) {
|
||||
sel := Doc2().Find("#n2")
|
||||
sel2 := Doc2().Find("#n4")
|
||||
sel2 = sel.NextUntilSelection(sel2).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNextUntilNodes(t *testing.T) {
|
||||
sel := Doc2().Find("#n2")
|
||||
sel2 := Doc2().Find("#n5")
|
||||
sel2 = sel.NextUntilNodes(sel2.Nodes...)
|
||||
AssertLength(t, sel2.Nodes, 2)
|
||||
AssertSelectionIs(t, sel2, "#n3", "#n4")
|
||||
assertLength(t, sel2.Nodes, 2)
|
||||
assertSelectionIs(t, sel2, "#n3", "#n4")
|
||||
}
|
||||
|
||||
func TestNextUntilNodesRollback(t *testing.T) {
|
||||
sel := Doc2().Find("#n2")
|
||||
sel2 := Doc2().Find("#n5")
|
||||
sel2 = sel.NextUntilNodes(sel2.Nodes...).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestPrevUntil(t *testing.T) {
|
||||
sel := Doc().Find(".alert p").PrevUntil("a")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
AssertSelectionIs(t, sel, "h4")
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
assertSelectionIs(t, sel, "h4")
|
||||
}
|
||||
|
||||
func TestPrevUntil2(t *testing.T) {
|
||||
sel := Doc().Find("[ng-cloak]").PrevUntil(":not([ng-cloak])")
|
||||
AssertLength(t, sel.Nodes, 1)
|
||||
AssertSelectionIs(t, sel, "[ng-cloak]")
|
||||
assertLength(t, sel.Nodes, 1)
|
||||
assertSelectionIs(t, sel, "[ng-cloak]")
|
||||
}
|
||||
|
||||
func TestPrevUntilOrder(t *testing.T) {
|
||||
sel := Doc().Find("#cf2-4").PrevUntil("#cf2-1")
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
AssertSelectionIs(t, sel, "#cf2-3", "#cf2-2")
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
assertSelectionIs(t, sel, "#cf2-3", "#cf2-2")
|
||||
}
|
||||
|
||||
func TestPrevUntilRollback(t *testing.T) {
|
||||
sel := Doc().Find("#cf2-4")
|
||||
sel2 := sel.PrevUntil("#cf2-1").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestPrevUntilSelection(t *testing.T) {
|
||||
sel := Doc2().Find("#n4")
|
||||
sel2 := Doc2().Find("#n2")
|
||||
sel2 = sel.PrevUntilSelection(sel2)
|
||||
AssertLength(t, sel2.Nodes, 1)
|
||||
AssertSelectionIs(t, sel2, "#n3")
|
||||
assertLength(t, sel2.Nodes, 1)
|
||||
assertSelectionIs(t, sel2, "#n3")
|
||||
}
|
||||
|
||||
func TestPrevUntilSelectionRollback(t *testing.T) {
|
||||
sel := Doc2().Find("#n4")
|
||||
sel2 := Doc2().Find("#n2")
|
||||
sel2 = sel.PrevUntilSelection(sel2).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestPrevUntilNodes(t *testing.T) {
|
||||
sel := Doc2().Find("#n5")
|
||||
sel2 := Doc2().Find("#n2")
|
||||
sel2 = sel.PrevUntilNodes(sel2.Nodes...)
|
||||
AssertLength(t, sel2.Nodes, 2)
|
||||
AssertSelectionIs(t, sel2, "#n4", "#n3")
|
||||
assertLength(t, sel2.Nodes, 2)
|
||||
assertSelectionIs(t, sel2, "#n4", "#n3")
|
||||
}
|
||||
|
||||
func TestPrevUntilNodesRollback(t *testing.T) {
|
||||
sel := Doc2().Find("#n5")
|
||||
sel2 := Doc2().Find("#n2")
|
||||
sel2 = sel.PrevUntilNodes(sel2.Nodes...).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNextFilteredUntil(t *testing.T) {
|
||||
sel := Doc2().Find(".two").NextFilteredUntil(".even", ".six")
|
||||
AssertLength(t, sel.Nodes, 4)
|
||||
AssertSelectionIs(t, sel, "#n3", "#n5", "#nf3", "#nf5")
|
||||
assertLength(t, sel.Nodes, 4)
|
||||
assertSelectionIs(t, sel, "#n3", "#n5", "#nf3", "#nf5")
|
||||
}
|
||||
|
||||
func TestNextFilteredUntilRollback(t *testing.T) {
|
||||
sel := Doc2().Find(".two")
|
||||
sel2 := sel.NextFilteredUntil(".even", ".six").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestNextFilteredUntilSelection(t *testing.T) {
|
||||
sel := Doc2().Find(".even")
|
||||
sel2 := Doc2().Find(".five")
|
||||
sel = sel.NextFilteredUntilSelection(".even", sel2)
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
AssertSelectionIs(t, sel, "#n3", "#nf3")
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
assertSelectionIs(t, sel, "#n3", "#nf3")
|
||||
}
|
||||
|
||||
func TestNextFilteredUntilSelectionRollback(t *testing.T) {
|
||||
sel := Doc2().Find(".even")
|
||||
sel2 := Doc2().Find(".five")
|
||||
sel3 := sel.NextFilteredUntilSelection(".even", sel2).End()
|
||||
AssertEqual(t, sel, sel3)
|
||||
assertEqual(t, sel, sel3)
|
||||
}
|
||||
|
||||
func TestNextFilteredUntilNodes(t *testing.T) {
|
||||
sel := Doc2().Find(".even")
|
||||
sel2 := Doc2().Find(".four")
|
||||
sel = sel.NextFilteredUntilNodes(".odd", sel2.Nodes...)
|
||||
AssertLength(t, sel.Nodes, 4)
|
||||
AssertSelectionIs(t, sel, "#n2", "#n6", "#nf2", "#nf6")
|
||||
assertLength(t, sel.Nodes, 4)
|
||||
assertSelectionIs(t, sel, "#n2", "#n6", "#nf2", "#nf6")
|
||||
}
|
||||
|
||||
func TestNextFilteredUntilNodesRollback(t *testing.T) {
|
||||
sel := Doc2().Find(".even")
|
||||
sel2 := Doc2().Find(".four")
|
||||
sel3 := sel.NextFilteredUntilNodes(".odd", sel2.Nodes...).End()
|
||||
AssertEqual(t, sel, sel3)
|
||||
assertEqual(t, sel, sel3)
|
||||
}
|
||||
|
||||
func TestPrevFilteredUntil(t *testing.T) {
|
||||
sel := Doc2().Find(".five").PrevFilteredUntil(".odd", ".one")
|
||||
AssertLength(t, sel.Nodes, 4)
|
||||
AssertSelectionIs(t, sel, "#n4", "#n2", "#nf4", "#nf2")
|
||||
assertLength(t, sel.Nodes, 4)
|
||||
assertSelectionIs(t, sel, "#n4", "#n2", "#nf4", "#nf2")
|
||||
}
|
||||
|
||||
func TestPrevFilteredUntilRollback(t *testing.T) {
|
||||
sel := Doc2().Find(".four")
|
||||
sel2 := sel.PrevFilteredUntil(".odd", ".one").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestPrevFilteredUntilSelection(t *testing.T) {
|
||||
sel := Doc2().Find(".odd")
|
||||
sel2 := Doc2().Find(".two")
|
||||
sel = sel.PrevFilteredUntilSelection(".odd", sel2)
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
AssertSelectionIs(t, sel, "#n4", "#nf4")
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
assertSelectionIs(t, sel, "#n4", "#nf4")
|
||||
}
|
||||
|
||||
func TestPrevFilteredUntilSelectionRollback(t *testing.T) {
|
||||
sel := Doc2().Find(".even")
|
||||
sel2 := Doc2().Find(".five")
|
||||
sel3 := sel.PrevFilteredUntilSelection(".even", sel2).End()
|
||||
AssertEqual(t, sel, sel3)
|
||||
assertEqual(t, sel, sel3)
|
||||
}
|
||||
|
||||
func TestPrevFilteredUntilNodes(t *testing.T) {
|
||||
sel := Doc2().Find(".even")
|
||||
sel2 := Doc2().Find(".four")
|
||||
sel = sel.PrevFilteredUntilNodes(".odd", sel2.Nodes...)
|
||||
AssertLength(t, sel.Nodes, 2)
|
||||
AssertSelectionIs(t, sel, "#n2", "#nf2")
|
||||
assertLength(t, sel.Nodes, 2)
|
||||
assertSelectionIs(t, sel, "#n2", "#nf2")
|
||||
}
|
||||
|
||||
func TestPrevFilteredUntilNodesRollback(t *testing.T) {
|
||||
sel := Doc2().Find(".even")
|
||||
sel2 := Doc2().Find(".four")
|
||||
sel3 := sel.PrevFilteredUntilNodes(".odd", sel2.Nodes...).End()
|
||||
AssertEqual(t, sel, sel3)
|
||||
assertEqual(t, sel, sel3)
|
||||
}
|
||||
|
||||
func TestClosestItself(t *testing.T) {
|
||||
sel := Doc2().Find(".three")
|
||||
sel2 := sel.Closest(".row")
|
||||
AssertLength(t, sel2.Nodes, sel.Length())
|
||||
AssertSelectionIs(t, sel2, "#n3", "#nf3")
|
||||
assertLength(t, sel2.Nodes, sel.Length())
|
||||
assertSelectionIs(t, sel2, "#n3", "#nf3")
|
||||
}
|
||||
|
||||
func TestClosestNoDupes(t *testing.T) {
|
||||
sel := Doc().Find(".span12")
|
||||
sel2 := sel.Closest(".pvk-content")
|
||||
AssertLength(t, sel2.Nodes, 1)
|
||||
AssertClass(t, sel2, "pvk-content")
|
||||
assertLength(t, sel2.Nodes, 1)
|
||||
assertClass(t, sel2, "pvk-content")
|
||||
}
|
||||
|
||||
func TestClosestNone(t *testing.T) {
|
||||
sel := Doc().Find("h4")
|
||||
sel2 := sel.Closest("a")
|
||||
AssertLength(t, sel2.Nodes, 0)
|
||||
assertLength(t, sel2.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestClosestMany(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.Closest(".pvk-content")
|
||||
AssertLength(t, sel2.Nodes, 2)
|
||||
AssertSelectionIs(t, sel2, "#pc1", "#pc2")
|
||||
assertLength(t, sel2.Nodes, 2)
|
||||
assertSelectionIs(t, sel2, "#pc1", "#pc2")
|
||||
}
|
||||
|
||||
func TestClosestRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.Closest(".pvk-content").End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestClosestSelectionItself(t *testing.T) {
|
||||
sel := Doc2().Find(".three")
|
||||
sel2 := sel.ClosestSelection(Doc2().Find(".row"))
|
||||
AssertLength(t, sel2.Nodes, sel.Length())
|
||||
assertLength(t, sel2.Nodes, sel.Length())
|
||||
}
|
||||
|
||||
func TestClosestSelectionNoDupes(t *testing.T) {
|
||||
sel := Doc().Find(".span12")
|
||||
sel2 := sel.ClosestSelection(Doc().Find(".pvk-content"))
|
||||
AssertLength(t, sel2.Nodes, 1)
|
||||
AssertClass(t, sel2, "pvk-content")
|
||||
assertLength(t, sel2.Nodes, 1)
|
||||
assertClass(t, sel2, "pvk-content")
|
||||
}
|
||||
|
||||
func TestClosestSelectionNone(t *testing.T) {
|
||||
sel := Doc().Find("h4")
|
||||
sel2 := sel.ClosestSelection(Doc().Find("a"))
|
||||
AssertLength(t, sel2.Nodes, 0)
|
||||
assertLength(t, sel2.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestClosestSelectionMany(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ClosestSelection(Doc().Find(".pvk-content"))
|
||||
AssertLength(t, sel2.Nodes, 2)
|
||||
AssertSelectionIs(t, sel2, "#pc1", "#pc2")
|
||||
assertLength(t, sel2.Nodes, 2)
|
||||
assertSelectionIs(t, sel2, "#pc1", "#pc2")
|
||||
}
|
||||
|
||||
func TestClosestSelectionRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ClosestSelection(Doc().Find(".pvk-content")).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestClosestNodesItself(t *testing.T) {
|
||||
sel := Doc2().Find(".three")
|
||||
sel2 := sel.ClosestNodes(Doc2().Find(".row").Nodes...)
|
||||
AssertLength(t, sel2.Nodes, sel.Length())
|
||||
assertLength(t, sel2.Nodes, sel.Length())
|
||||
}
|
||||
|
||||
func TestClosestNodesNoDupes(t *testing.T) {
|
||||
sel := Doc().Find(".span12")
|
||||
sel2 := sel.ClosestNodes(Doc().Find(".pvk-content").Nodes...)
|
||||
AssertLength(t, sel2.Nodes, 1)
|
||||
AssertClass(t, sel2, "pvk-content")
|
||||
assertLength(t, sel2.Nodes, 1)
|
||||
assertClass(t, sel2, "pvk-content")
|
||||
}
|
||||
|
||||
func TestClosestNodesNone(t *testing.T) {
|
||||
sel := Doc().Find("h4")
|
||||
sel2 := sel.ClosestNodes(Doc().Find("a").Nodes...)
|
||||
AssertLength(t, sel2.Nodes, 0)
|
||||
assertLength(t, sel2.Nodes, 0)
|
||||
}
|
||||
|
||||
func TestClosestNodesMany(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ClosestNodes(Doc().Find(".pvk-content").Nodes...)
|
||||
AssertLength(t, sel2.Nodes, 2)
|
||||
AssertSelectionIs(t, sel2, "#pc1", "#pc2")
|
||||
assertLength(t, sel2.Nodes, 2)
|
||||
assertSelectionIs(t, sel2, "#pc1", "#pc2")
|
||||
}
|
||||
|
||||
func TestClosestNodesRollback(t *testing.T) {
|
||||
sel := Doc().Find(".container-fluid")
|
||||
sel2 := sel.ClosestNodes(Doc().Find(".pvk-content").Nodes...).End()
|
||||
AssertEqual(t, sel, sel2)
|
||||
assertEqual(t, sel, sel2)
|
||||
}
|
||||
|
||||
func TestIssue26(t *testing.T) {
|
||||
@@ -692,6 +692,6 @@ func TestIssue26(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sel := doc.Find("img[src]")
|
||||
AssertLength(t, sel.Nodes, c.l)
|
||||
assertLength(t, sel.Nodes, c.l)
|
||||
}
|
||||
}
|
||||
|
30
type_test.go
30
type_test.go
@@ -17,7 +17,7 @@ var docW *Document
|
||||
|
||||
func Doc() *Document {
|
||||
if doc == nil {
|
||||
doc = LoadDoc("page.html")
|
||||
doc = loadDoc("page.html")
|
||||
}
|
||||
return doc
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func DocClone() *Document {
|
||||
}
|
||||
func Doc2() *Document {
|
||||
if doc2 == nil {
|
||||
doc2 = LoadDoc("page2.html")
|
||||
doc2 = loadDoc("page2.html")
|
||||
}
|
||||
return doc2
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func Doc2Clone() *Document {
|
||||
}
|
||||
func DocB() *Document {
|
||||
if docB == nil {
|
||||
docB = LoadDoc("gotesting.html")
|
||||
docB = loadDoc("gotesting.html")
|
||||
}
|
||||
return docB
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func DocBClone() *Document {
|
||||
}
|
||||
func DocW() *Document {
|
||||
if docW == nil {
|
||||
docW = LoadDoc("gowiki.html")
|
||||
docW = loadDoc("gowiki.html")
|
||||
}
|
||||
return docW
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func DocWClone() *Document {
|
||||
return NewDocumentFromDocument(DocW())
|
||||
}
|
||||
|
||||
func AssertLength(t *testing.T, nodes []*html.Node, length int) {
|
||||
func assertLength(t *testing.T, nodes []*html.Node, length int) {
|
||||
if len(nodes) != length {
|
||||
t.Errorf("Expected %d nodes, found %d.", length, len(nodes))
|
||||
for i, n := range nodes {
|
||||
@@ -61,25 +61,25 @@ func AssertLength(t *testing.T, nodes []*html.Node, length int) {
|
||||
}
|
||||
}
|
||||
|
||||
func AssertClass(t *testing.T, sel *Selection, class string) {
|
||||
func assertClass(t *testing.T, sel *Selection, class string) {
|
||||
if !sel.HasClass(class) {
|
||||
t.Errorf("Expected node to have class %s, found %+v.", class, sel.Get(0))
|
||||
}
|
||||
}
|
||||
|
||||
func AssertPanic(t *testing.T) {
|
||||
func assertPanic(t *testing.T) {
|
||||
if e := recover(); e == nil {
|
||||
t.Error("Expected a panic.")
|
||||
}
|
||||
}
|
||||
|
||||
func AssertEqual(t *testing.T, s1 *Selection, s2 *Selection) {
|
||||
func assertEqual(t *testing.T, s1 *Selection, s2 *Selection) {
|
||||
if s1 != s2 {
|
||||
t.Error("Expected selection objects to be the same.")
|
||||
}
|
||||
}
|
||||
|
||||
func AssertSelectionIs(t *testing.T, sel *Selection, is ...string) {
|
||||
func assertSelectionIs(t *testing.T, sel *Selection, is ...string) {
|
||||
for i := 0; i < sel.Length(); i++ {
|
||||
if !sel.Eq(i).Is(is[i]) {
|
||||
t.Errorf("Expected node %d to be %s, found %+v", i, is[i], sel.Get(i))
|
||||
@@ -87,7 +87,17 @@ func AssertSelectionIs(t *testing.T, sel *Selection, is ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
func LoadDoc(page string) *Document {
|
||||
func printSel(t *testing.T, sel *Selection) {
|
||||
if testing.Verbose() {
|
||||
h, err := sel.Html()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(h)
|
||||
}
|
||||
}
|
||||
|
||||
func loadDoc(page string) *Document {
|
||||
var f *os.File
|
||||
var e error
|
||||
|
||||
|
Reference in New Issue
Block a user