mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-10-05 16:56:57 +08:00
remove Document.Root, Document is itself a Selection (using embedded struct)
This commit is contained in:
@@ -24,7 +24,7 @@ To run benchmarks, run this command in goquery's source directory:
|
|||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
* **v0.2.0** : Add support for negative indices in Slice(). *Upcoming* : add jQuery's Closest() method.
|
* **v0.2.0** : (*in progress on master branch*) Add support for negative indices in Slice(). *Upcoming* : add jQuery's Closest() method.
|
||||||
* **v0.1.1** : Add benchmarks to use as baseline for refactorings, refactor Next...() and Prev...() methods to use the new html package's linked list features (Next/PrevSibling, FirstChild). Good performance boost (40+% in some cases).
|
* **v0.1.1** : Add benchmarks to use as baseline for refactorings, refactor Next...() and Prev...() methods to use the new html package's linked list features (Next/PrevSibling, FirstChild). Good performance boost (40+% in some cases).
|
||||||
* **v0.1.0** : Initial release. See [TODOs](#a1) for a list of upcoming features.
|
* **v0.1.0** : Initial release. See [TODOs](#a1) for a list of upcoming features.
|
||||||
|
|
||||||
|
2
array.go
2
array.go
@@ -63,7 +63,7 @@ func (this *Selection) Index() int {
|
|||||||
// not found.
|
// not found.
|
||||||
func (this *Selection) IndexSelector(selector string) int {
|
func (this *Selection) IndexSelector(selector string) int {
|
||||||
if len(this.Nodes) > 0 {
|
if len(this.Nodes) > 0 {
|
||||||
sel := this.document.Root.Find(selector)
|
sel := this.document.Find(selector)
|
||||||
return indexInSlice(sel.Nodes, this.Nodes[0])
|
return indexInSlice(sel.Nodes, this.Nodes[0])
|
||||||
}
|
}
|
||||||
return -1
|
return -1
|
||||||
|
@@ -5,86 +5,86 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestFirst(t *testing.T) {
|
func TestFirst(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").First()
|
sel := Doc().Find(".pvk-content").First()
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFirstEmpty(t *testing.T) {
|
func TestFirstEmpty(t *testing.T) {
|
||||||
defer AssertPanic(t)
|
defer AssertPanic(t)
|
||||||
Doc().Root.Find(".pvk-zzcontentzz").First()
|
Doc().Find(".pvk-zzcontentzz").First()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFirstRollback(t *testing.T) {
|
func TestFirstRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.First().End()
|
sel2 := sel.First().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLast(t *testing.T) {
|
func TestLast(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").Last()
|
sel := Doc().Find(".pvk-content").Last()
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
|
|
||||||
// Should contain Footer
|
// Should contain Footer
|
||||||
foot := Doc().Root.Find(".footer")
|
foot := Doc().Find(".footer")
|
||||||
if !sel.Contains(foot.Nodes[0]) {
|
if !sel.Contains(foot.Nodes[0]) {
|
||||||
t.Error("Last .pvk-content should contain .footer.")
|
t.Error("Last .pvk-content should contain .footer.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLastRollback(t *testing.T) {
|
func TestLastRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.Last().End()
|
sel2 := sel.Last().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEq(t *testing.T) {
|
func TestEq(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").Eq(1)
|
sel := Doc().Find(".pvk-content").Eq(1)
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEqNegative(t *testing.T) {
|
func TestEqNegative(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").Eq(-1)
|
sel := Doc().Find(".pvk-content").Eq(-1)
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
|
|
||||||
// Should contain Footer
|
// Should contain Footer
|
||||||
foot := Doc().Root.Find(".footer")
|
foot := Doc().Find(".footer")
|
||||||
if !sel.Contains(foot.Nodes[0]) {
|
if !sel.Contains(foot.Nodes[0]) {
|
||||||
t.Error("Index -1 of .pvk-content should contain .footer.")
|
t.Error("Index -1 of .pvk-content should contain .footer.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEqRollback(t *testing.T) {
|
func TestEqRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.Eq(1).End()
|
sel2 := sel.Eq(1).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSlice(t *testing.T) {
|
func TestSlice(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").Slice(0, 2)
|
sel := Doc().Find(".pvk-content").Slice(0, 2)
|
||||||
|
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSliceOutOfBounds(t *testing.T) {
|
func TestSliceOutOfBounds(t *testing.T) {
|
||||||
defer AssertPanic(t)
|
defer AssertPanic(t)
|
||||||
Doc().Root.Find(".pvk-content").Slice(2, 12)
|
Doc().Find(".pvk-content").Slice(2, 12)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNegativeSliceStart(t *testing.T) {
|
func TestNegativeSliceStart(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").Slice(-2, 3)
|
sel := Doc().Find(".container-fluid").Slice(-2, 3)
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
AssertSelectionIs(t, sel.Eq(0), "#cf3")
|
AssertSelectionIs(t, sel.Eq(0), "#cf3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNegativeSliceEnd(t *testing.T) {
|
func TestNegativeSliceEnd(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").Slice(1, -1)
|
sel := Doc().Find(".container-fluid").Slice(1, -1)
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
AssertSelectionIs(t, sel.Eq(0), "#cf2")
|
AssertSelectionIs(t, sel.Eq(0), "#cf2")
|
||||||
AssertSelectionIs(t, sel.Eq(1), "#cf3")
|
AssertSelectionIs(t, sel.Eq(1), "#cf3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNegativeSliceBoth(t *testing.T) {
|
func TestNegativeSliceBoth(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").Slice(-3, -1)
|
sel := Doc().Find(".container-fluid").Slice(-3, -1)
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
AssertSelectionIs(t, sel.Eq(0), "#cf2")
|
AssertSelectionIs(t, sel.Eq(0), "#cf2")
|
||||||
AssertSelectionIs(t, sel.Eq(1), "#cf3")
|
AssertSelectionIs(t, sel.Eq(1), "#cf3")
|
||||||
@@ -92,17 +92,17 @@ func TestNegativeSliceBoth(t *testing.T) {
|
|||||||
|
|
||||||
func TestNegativeSliceOutOfBounds(t *testing.T) {
|
func TestNegativeSliceOutOfBounds(t *testing.T) {
|
||||||
defer AssertPanic(t)
|
defer AssertPanic(t)
|
||||||
Doc().Root.Find(".container-fluid").Slice(-12, -7)
|
Doc().Find(".container-fluid").Slice(-12, -7)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSliceRollback(t *testing.T) {
|
func TestSliceRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.Slice(0, 2).End()
|
sel2 := sel.Slice(0, 2).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGet(t *testing.T) {
|
func TestGet(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
node := sel.Get(1)
|
node := sel.Get(1)
|
||||||
if sel.Nodes[1] != node {
|
if sel.Nodes[1] != node {
|
||||||
t.Errorf("Expected node %v to be %v.", node, sel.Nodes[1])
|
t.Errorf("Expected node %v to be %v.", node, sel.Nodes[1])
|
||||||
@@ -110,7 +110,7 @@ func TestGet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetNegative(t *testing.T) {
|
func TestGetNegative(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
node := sel.Get(-3)
|
node := sel.Get(-3)
|
||||||
if sel.Nodes[0] != node {
|
if sel.Nodes[0] != node {
|
||||||
t.Errorf("Expected node %v to be %v.", node, sel.Nodes[0])
|
t.Errorf("Expected node %v to be %v.", node, sel.Nodes[0])
|
||||||
@@ -119,41 +119,41 @@ func TestGetNegative(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetInvalid(t *testing.T) {
|
func TestGetInvalid(t *testing.T) {
|
||||||
defer AssertPanic(t)
|
defer AssertPanic(t)
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel.Get(129)
|
sel.Get(129)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIndex(t *testing.T) {
|
func TestIndex(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
if i := sel.Index(); i != 1 {
|
if i := sel.Index(); i != 1 {
|
||||||
t.Errorf("Expected index of 1, got %v.", i)
|
t.Errorf("Expected index of 1, got %v.", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexSelector(t *testing.T) {
|
func TestIndexSelector(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".hero-unit")
|
sel := Doc().Find(".hero-unit")
|
||||||
if i := sel.IndexSelector("div"); i != 4 {
|
if i := sel.IndexSelector("div"); i != 4 {
|
||||||
t.Errorf("Expected index of 4, got %v.", i)
|
t.Errorf("Expected index of 4, got %v.", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexOfNode(t *testing.T) {
|
func TestIndexOfNode(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div.pvk-gutter")
|
sel := Doc().Find("div.pvk-gutter")
|
||||||
if i := sel.IndexOfNode(sel.Nodes[1]); i != 1 {
|
if i := sel.IndexOfNode(sel.Nodes[1]); i != 1 {
|
||||||
t.Errorf("Expected index of 1, got %v.", i)
|
t.Errorf("Expected index of 1, got %v.", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexOfNilNode(t *testing.T) {
|
func TestIndexOfNilNode(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div.pvk-gutter")
|
sel := Doc().Find("div.pvk-gutter")
|
||||||
if i := sel.IndexOfNode(nil); i != -1 {
|
if i := sel.IndexOfNode(nil); i != -1 {
|
||||||
t.Errorf("Expected index of -1, got %v.", i)
|
t.Errorf("Expected index of -1, got %v.", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexOfSelection(t *testing.T) {
|
func TestIndexOfSelection(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div")
|
sel := Doc().Find("div")
|
||||||
sel2 := Doc().Root.Find(".hero-unit")
|
sel2 := Doc().Find(".hero-unit")
|
||||||
if i := sel.IndexOfSelection(sel2); i != 4 {
|
if i := sel.IndexOfSelection(sel2); i != 4 {
|
||||||
t.Errorf("Expected index of 4, got %v.", i)
|
t.Errorf("Expected index of 4, got %v.", i)
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
func BenchmarkFirst(b *testing.B) {
|
func BenchmarkFirst(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("dd")
|
sel := DocB().Find("dd")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
sel.First()
|
sel.First()
|
||||||
@@ -15,7 +15,7 @@ func BenchmarkFirst(b *testing.B) {
|
|||||||
|
|
||||||
func BenchmarkLast(b *testing.B) {
|
func BenchmarkLast(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("dd")
|
sel := DocB().Find("dd")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
sel.Last()
|
sel.Last()
|
||||||
@@ -24,7 +24,7 @@ func BenchmarkLast(b *testing.B) {
|
|||||||
|
|
||||||
func BenchmarkEq(b *testing.B) {
|
func BenchmarkEq(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("dd")
|
sel := DocB().Find("dd")
|
||||||
j := 0
|
j := 0
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -37,7 +37,7 @@ func BenchmarkEq(b *testing.B) {
|
|||||||
|
|
||||||
func BenchmarkSlice(b *testing.B) {
|
func BenchmarkSlice(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("dd")
|
sel := DocB().Find("dd")
|
||||||
j := 0
|
j := 0
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -50,7 +50,7 @@ func BenchmarkSlice(b *testing.B) {
|
|||||||
|
|
||||||
func BenchmarkGet(b *testing.B) {
|
func BenchmarkGet(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("dd")
|
sel := DocB().Find("dd")
|
||||||
j := 0
|
j := 0
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -65,7 +65,7 @@ func BenchmarkIndex(b *testing.B) {
|
|||||||
var j int
|
var j int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("#Main")
|
sel := DocB().Find("#Main")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
j = sel.Index()
|
j = sel.Index()
|
||||||
@@ -77,7 +77,7 @@ func BenchmarkIndexSelector(b *testing.B) {
|
|||||||
var j int
|
var j int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("#manual-nav dl dd:nth-child(1)")
|
sel := DocB().Find("#manual-nav dl dd:nth-child(1)")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
j = sel.IndexSelector("dd")
|
j = sel.IndexSelector("dd")
|
||||||
@@ -89,8 +89,8 @@ func BenchmarkIndexOfNode(b *testing.B) {
|
|||||||
var j int
|
var j int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("span a")
|
sel := DocB().Find("span a")
|
||||||
sel2 := DocB().Root.Find("span a:nth-child(3)")
|
sel2 := DocB().Find("span a:nth-child(3)")
|
||||||
n := sel2.Get(0)
|
n := sel2.Get(0)
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -102,8 +102,8 @@ func BenchmarkIndexOfNode(b *testing.B) {
|
|||||||
func BenchmarkIndexOfSelection(b *testing.B) {
|
func BenchmarkIndexOfSelection(b *testing.B) {
|
||||||
var j int
|
var j int
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("span a")
|
sel := DocB().Find("span a")
|
||||||
sel2 := DocB().Root.Find("span a:nth-child(3)")
|
sel2 := DocB().Find("span a:nth-child(3)")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
j = sel.IndexOfSelection(sel2)
|
j = sel.IndexOfSelection(sel2)
|
||||||
|
@@ -15,7 +15,7 @@ func BenchmarkMetalReviewExample(b *testing.B) {
|
|||||||
doc := LoadDoc("metalreview.html")
|
doc := LoadDoc("metalreview.html")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
doc.Root.Find(".slider-row:nth-child(1) .slider-item").Each(func(i int, s *Selection) {
|
doc.Find(".slider-row:nth-child(1) .slider-item").Each(func(i int, s *Selection) {
|
||||||
var band, title string
|
var band, title string
|
||||||
var score float64
|
var score float64
|
||||||
var e error
|
var e error
|
||||||
|
@@ -8,7 +8,7 @@ func BenchmarkAdd(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("dd")
|
sel := DocB().Find("dd")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -24,8 +24,8 @@ func BenchmarkAddSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("dd")
|
sel := DocB().Find("dd")
|
||||||
sel2 := DocB().Root.Find("h2[title]")
|
sel2 := DocB().Find("h2[title]")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -41,8 +41,8 @@ func BenchmarkAddNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("dd")
|
sel := DocB().Find("dd")
|
||||||
sel2 := DocB().Root.Find("h2[title]")
|
sel2 := DocB().Find("h2[title]")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -59,7 +59,7 @@ func BenchmarkAndSelf(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocB().Root.Find("dd").Parent()
|
sel := DocB().Find("dd").Parent()
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
|
@@ -8,7 +8,7 @@ func BenchmarkFilter(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -24,7 +24,7 @@ func BenchmarkNot(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -40,7 +40,7 @@ func BenchmarkFilterFunction(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
f := func(i int, s *Selection) bool {
|
f := func(i int, s *Selection) bool {
|
||||||
return len(s.Get(0).Attr) > 0
|
return len(s.Get(0).Attr) > 0
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ func BenchmarkNotFunction(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
f := func(i int, s *Selection) bool {
|
f := func(i int, s *Selection) bool {
|
||||||
return len(s.Get(0).Attr) > 0
|
return len(s.Get(0).Attr) > 0
|
||||||
}
|
}
|
||||||
@@ -78,8 +78,8 @@ func BenchmarkFilterNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
sel2 := DocW().Root.Find(".toclevel-2")
|
sel2 := DocW().Find(".toclevel-2")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -96,8 +96,8 @@ func BenchmarkNotNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
sel2 := DocW().Root.Find(".toclevel-1")
|
sel2 := DocW().Find(".toclevel-1")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -114,8 +114,8 @@ func BenchmarkFilterSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
sel2 := DocW().Root.Find(".toclevel-2")
|
sel2 := DocW().Find(".toclevel-2")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -131,8 +131,8 @@ func BenchmarkNotSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
sel2 := DocW().Root.Find(".toclevel-1")
|
sel2 := DocW().Find(".toclevel-1")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -148,7 +148,7 @@ func BenchmarkHas(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -164,8 +164,8 @@ func BenchmarkHasNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
sel2 := DocW().Root.Find(".tocnumber")
|
sel2 := DocW().Find(".tocnumber")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -182,8 +182,8 @@ func BenchmarkHasSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
sel2 := DocW().Root.Find(".tocnumber")
|
sel2 := DocW().Find(".tocnumber")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -199,7 +199,7 @@ func BenchmarkEnd(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li").Has(".tocnumber")
|
sel := DocW().Find("li").Has(".tocnumber")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
|
@@ -8,7 +8,7 @@ func BenchmarkEach(b *testing.B) {
|
|||||||
var tmp, n int
|
var tmp, n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("td")
|
sel := DocW().Find("td")
|
||||||
f := func(i int, s *Selection) {
|
f := func(i int, s *Selection) {
|
||||||
tmp++
|
tmp++
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ func BenchmarkMap(b *testing.B) {
|
|||||||
var tmp, n int
|
var tmp, n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("td")
|
sel := DocW().Find("td")
|
||||||
f := func(i int, s *Selection) string {
|
f := func(i int, s *Selection) string {
|
||||||
tmp++
|
tmp++
|
||||||
return string(tmp)
|
return string(tmp)
|
||||||
|
@@ -8,7 +8,7 @@ func BenchmarkAttr(b *testing.B) {
|
|||||||
var s string
|
var s string
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h1")
|
sel := DocW().Find("h1")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
s, _ = sel.Attr("id")
|
s, _ = sel.Attr("id")
|
||||||
@@ -18,7 +18,7 @@ func BenchmarkAttr(b *testing.B) {
|
|||||||
|
|
||||||
func BenchmarkText(b *testing.B) {
|
func BenchmarkText(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
sel.Text()
|
sel.Text()
|
||||||
@@ -29,7 +29,7 @@ func BenchmarkLength(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
n = sel.Length()
|
n = sel.Length()
|
||||||
@@ -39,7 +39,7 @@ func BenchmarkLength(b *testing.B) {
|
|||||||
|
|
||||||
func BenchmarkHtml(b *testing.B) {
|
func BenchmarkHtml(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
sel.Html()
|
sel.Html()
|
||||||
|
@@ -8,7 +8,7 @@ func BenchmarkIs(b *testing.B) {
|
|||||||
var y bool
|
var y bool
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
y = sel.Is(".toclevel-2")
|
y = sel.Is(".toclevel-2")
|
||||||
@@ -20,7 +20,7 @@ func BenchmarkIsPositional(b *testing.B) {
|
|||||||
var y bool
|
var y bool
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
y = sel.Is("li:nth-child(2)")
|
y = sel.Is("li:nth-child(2)")
|
||||||
@@ -32,7 +32,7 @@ func BenchmarkIsFunction(b *testing.B) {
|
|||||||
var y bool
|
var y bool
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find(".toclevel-1")
|
sel := DocW().Find(".toclevel-1")
|
||||||
f := func(i int, s *Selection) bool {
|
f := func(i int, s *Selection) bool {
|
||||||
return i == 8
|
return i == 8
|
||||||
}
|
}
|
||||||
@@ -47,8 +47,8 @@ func BenchmarkIsSelection(b *testing.B) {
|
|||||||
var y bool
|
var y bool
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
sel2 := DocW().Root.Find(".toclevel-2")
|
sel2 := DocW().Find(".toclevel-2")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
y = sel.IsSelection(sel2)
|
y = sel.IsSelection(sel2)
|
||||||
@@ -60,8 +60,8 @@ func BenchmarkIsNodes(b *testing.B) {
|
|||||||
var y bool
|
var y bool
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
sel2 := DocW().Root.Find(".toclevel-2")
|
sel2 := DocW().Find(".toclevel-2")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -74,7 +74,7 @@ func BenchmarkHasClass(b *testing.B) {
|
|||||||
var y bool
|
var y bool
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("span")
|
sel := DocW().Find("span")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
y = sel.HasClass("official")
|
y = sel.HasClass("official")
|
||||||
@@ -86,8 +86,8 @@ func BenchmarkContains(b *testing.B) {
|
|||||||
var y bool
|
var y bool
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("span.url")
|
sel := DocW().Find("span.url")
|
||||||
sel2 := DocW().Root.Find("a[rel=\"nofollow\"]")
|
sel2 := DocW().Find("a[rel=\"nofollow\"]")
|
||||||
node := sel2.Nodes[0]
|
node := sel2.Nodes[0]
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
@@ -9,10 +9,10 @@ func BenchmarkFind(b *testing.B) {
|
|||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
n = DocB().Root.Find("dd").Length()
|
n = DocB().Find("dd").Length()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
DocB().Root.Find("dd")
|
DocB().Find("dd")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.Logf("Find=%d", n)
|
b.Logf("Find=%d", n)
|
||||||
@@ -22,7 +22,7 @@ func BenchmarkFindWithinSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("ul")
|
sel := DocW().Find("ul")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -38,8 +38,8 @@ func BenchmarkFindSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("ul")
|
sel := DocW().Find("ul")
|
||||||
sel2 := DocW().Root.Find("span")
|
sel2 := DocW().Find("span")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -55,8 +55,8 @@ func BenchmarkFindNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("ul")
|
sel := DocW().Find("ul")
|
||||||
sel2 := DocW().Root.Find("span")
|
sel2 := DocW().Find("span")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -73,7 +73,7 @@ func BenchmarkContents(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find(".toclevel-1")
|
sel := DocW().Find(".toclevel-1")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -89,7 +89,7 @@ func BenchmarkContentsFiltered(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find(".toclevel-1")
|
sel := DocW().Find(".toclevel-1")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -105,7 +105,7 @@ func BenchmarkChildren(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find(".toclevel-2")
|
sel := DocW().Find(".toclevel-2")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -121,7 +121,7 @@ func BenchmarkChildrenFiltered(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h3")
|
sel := DocW().Find("h3")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -137,7 +137,7 @@ func BenchmarkParent(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -153,7 +153,7 @@ func BenchmarkParentFiltered(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li")
|
sel := DocW().Find("li")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -169,7 +169,7 @@ func BenchmarkParents(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("th a")
|
sel := DocW().Find("th a")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -185,7 +185,7 @@ func BenchmarkParentsFiltered(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("th a")
|
sel := DocW().Find("th a")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -201,7 +201,7 @@ func BenchmarkParentsUntil(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("th a")
|
sel := DocW().Find("th a")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -217,8 +217,8 @@ func BenchmarkParentsUntilSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("th a")
|
sel := DocW().Find("th a")
|
||||||
sel2 := DocW().Root.Find("#content")
|
sel2 := DocW().Find("#content")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -234,8 +234,8 @@ func BenchmarkParentsUntilNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("th a")
|
sel := DocW().Find("th a")
|
||||||
sel2 := DocW().Root.Find("#content")
|
sel2 := DocW().Find("#content")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -252,7 +252,7 @@ func BenchmarkParentsFilteredUntil(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find(".toclevel-1 a")
|
sel := DocW().Find(".toclevel-1 a")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -268,8 +268,8 @@ func BenchmarkParentsFilteredUntilSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find(".toclevel-1 a")
|
sel := DocW().Find(".toclevel-1 a")
|
||||||
sel2 := DocW().Root.Find("ul")
|
sel2 := DocW().Find("ul")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -285,8 +285,8 @@ func BenchmarkParentsFilteredUntilNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find(".toclevel-1 a")
|
sel := DocW().Find(".toclevel-1 a")
|
||||||
sel2 := DocW().Root.Find("ul")
|
sel2 := DocW().Find("ul")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -303,7 +303,7 @@ func BenchmarkSiblings(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("ul li:nth-child(1)")
|
sel := DocW().Find("ul li:nth-child(1)")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -319,7 +319,7 @@ func BenchmarkSiblingsFiltered(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("ul li:nth-child(1)")
|
sel := DocW().Find("ul li:nth-child(1)")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -335,7 +335,7 @@ func BenchmarkNext(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li:nth-child(1)")
|
sel := DocW().Find("li:nth-child(1)")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -351,7 +351,7 @@ func BenchmarkNextFiltered(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li:nth-child(1)")
|
sel := DocW().Find("li:nth-child(1)")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -367,7 +367,7 @@ func BenchmarkNextAll(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li:nth-child(3)")
|
sel := DocW().Find("li:nth-child(3)")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -383,7 +383,7 @@ func BenchmarkNextAllFiltered(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li:nth-child(3)")
|
sel := DocW().Find("li:nth-child(3)")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -399,7 +399,7 @@ func BenchmarkPrev(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li:last-child")
|
sel := DocW().Find("li:last-child")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -415,7 +415,7 @@ func BenchmarkPrevFiltered(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li:last-child")
|
sel := DocW().Find("li:last-child")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -433,7 +433,7 @@ func BenchmarkPrevAll(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li:nth-child(4)")
|
sel := DocW().Find("li:nth-child(4)")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -449,7 +449,7 @@ func BenchmarkPrevAllFiltered(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li:nth-child(4)")
|
sel := DocW().Find("li:nth-child(4)")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -465,7 +465,7 @@ func BenchmarkNextUntil(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li:first-child")
|
sel := DocW().Find("li:first-child")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -481,8 +481,8 @@ func BenchmarkNextUntilSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
sel2 := DocW().Root.Find("ul")
|
sel2 := DocW().Find("ul")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -498,8 +498,8 @@ func BenchmarkNextUntilNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
sel2 := DocW().Root.Find("p")
|
sel2 := DocW().Find("p")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -516,7 +516,7 @@ func BenchmarkPrevUntil(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("li:last-child")
|
sel := DocW().Find("li:last-child")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -532,8 +532,8 @@ func BenchmarkPrevUntilSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
sel2 := DocW().Root.Find("ul")
|
sel2 := DocW().Find("ul")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -549,8 +549,8 @@ func BenchmarkPrevUntilNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
sel2 := DocW().Root.Find("p")
|
sel2 := DocW().Find("p")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -567,7 +567,7 @@ func BenchmarkNextFilteredUntil(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -583,8 +583,8 @@ func BenchmarkNextFilteredUntilSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
sel2 := DocW().Root.Find("div")
|
sel2 := DocW().Find("div")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -600,8 +600,8 @@ func BenchmarkNextFilteredUntilNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
sel2 := DocW().Root.Find("div")
|
sel2 := DocW().Find("div")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -618,7 +618,7 @@ func BenchmarkPrevFilteredUntil(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -634,8 +634,8 @@ func BenchmarkPrevFilteredUntilSelection(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
sel2 := DocW().Root.Find("div")
|
sel2 := DocW().Find("div")
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
@@ -651,8 +651,8 @@ func BenchmarkPrevFilteredUntilNodes(b *testing.B) {
|
|||||||
var n int
|
var n int
|
||||||
|
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
sel := DocW().Root.Find("h2")
|
sel := DocW().Find("h2")
|
||||||
sel2 := DocW().Root.Find("div")
|
sel2 := DocW().Find("div")
|
||||||
nodes := sel2.Nodes
|
nodes := sel2.Nodes
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
@@ -20,7 +20,7 @@ func ExampleScrape_MetalReview() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the review items (the type of the Selection would be *goquery.Selection)
|
// Find the review items (the type of the Selection would be *goquery.Selection)
|
||||||
doc.Root.Find(".slider-row:nth-child(1) .slider-item").Each(func(i int, s *Selection) {
|
doc.Find(".slider-row:nth-child(1) .slider-item").Each(func(i int, s *Selection) {
|
||||||
var band, title string
|
var band, title string
|
||||||
var score float64
|
var score float64
|
||||||
|
|
||||||
|
@@ -5,25 +5,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestAdd(t *testing.T) {
|
func TestAdd(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div.row-fluid").Add("a")
|
sel := Doc().Find("div.row-fluid").Add("a")
|
||||||
AssertLength(t, sel.Nodes, 19)
|
AssertLength(t, sel.Nodes, 19)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddRollback(t *testing.T) {
|
func TestAddRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.Add("a").End()
|
sel2 := sel.Add("a").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddSelection(t *testing.T) {
|
func TestAddSelection(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div.row-fluid")
|
sel := Doc().Find("div.row-fluid")
|
||||||
sel2 := Doc().Root.Find("a")
|
sel2 := Doc().Find("a")
|
||||||
sel = sel.AddSelection(sel2)
|
sel = sel.AddSelection(sel2)
|
||||||
AssertLength(t, sel.Nodes, 19)
|
AssertLength(t, sel.Nodes, 19)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddSelectionNil(t *testing.T) {
|
func TestAddSelectionNil(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div.row-fluid")
|
sel := Doc().Find("div.row-fluid")
|
||||||
AssertLength(t, sel.Nodes, 9)
|
AssertLength(t, sel.Nodes, 9)
|
||||||
|
|
||||||
sel = sel.AddSelection(nil)
|
sel = sel.AddSelection(nil)
|
||||||
@@ -31,38 +31,38 @@ func TestAddSelectionNil(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAddSelectionRollback(t *testing.T) {
|
func TestAddSelectionRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.Find("a")
|
sel2 := sel.Find("a")
|
||||||
sel2 = sel.AddSelection(sel2).End()
|
sel2 = sel.AddSelection(sel2).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddNodes(t *testing.T) {
|
func TestAddNodes(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div.pvk-gutter")
|
sel := Doc().Find("div.pvk-gutter")
|
||||||
sel2 := Doc().Root.Find(".pvk-content")
|
sel2 := Doc().Find(".pvk-content")
|
||||||
sel = sel.AddNodes(sel2.Nodes...)
|
sel = sel.AddNodes(sel2.Nodes...)
|
||||||
AssertLength(t, sel.Nodes, 9)
|
AssertLength(t, sel.Nodes, 9)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddNodesNone(t *testing.T) {
|
func TestAddNodesNone(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div.pvk-gutter").AddNodes()
|
sel := Doc().Find("div.pvk-gutter").AddNodes()
|
||||||
AssertLength(t, sel.Nodes, 6)
|
AssertLength(t, sel.Nodes, 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddNodesRollback(t *testing.T) {
|
func TestAddNodesRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.Find("a")
|
sel2 := sel.Find("a")
|
||||||
sel2 = sel.AddNodes(sel2.Nodes...).End()
|
sel2 = sel.AddNodes(sel2.Nodes...).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAndSelf(t *testing.T) {
|
func TestAndSelf(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".span12").Last().AndSelf()
|
sel := Doc().Find(".span12").Last().AndSelf()
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAndSelfRollback(t *testing.T) {
|
func TestAndSelfRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.Find("a").AndSelf().End().End()
|
sel2 := sel.Find("a").AndSelf().End().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
@@ -70,7 +70,7 @@ func (this *Selection) Intersection(s *Selection) *Selection {
|
|||||||
// that matches the selector.
|
// that matches the selector.
|
||||||
// It returns a new Selection object with the matching elements.
|
// It returns a new Selection object with the matching elements.
|
||||||
func (this *Selection) Has(selector string) *Selection {
|
func (this *Selection) Has(selector string) *Selection {
|
||||||
return this.HasSelection(this.document.Root.Find(selector))
|
return this.HasSelection(this.document.Find(selector))
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasNodes() reduces the set of matched elements to those that have a
|
// HasNodes() reduces the set of matched elements to those that have a
|
||||||
|
@@ -5,30 +5,30 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestFilter(t *testing.T) {
|
func TestFilter(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".span12").Filter(".alert")
|
sel := Doc().Find(".span12").Filter(".alert")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterNone(t *testing.T) {
|
func TestFilterNone(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".span12").Filter(".zzalert")
|
sel := Doc().Find(".span12").Filter(".zzalert")
|
||||||
AssertLength(t, sel.Nodes, 0)
|
AssertLength(t, sel.Nodes, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterRollback(t *testing.T) {
|
func TestFilterRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.Filter(".alert").End()
|
sel2 := sel.Filter(".alert").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterFunction(t *testing.T) {
|
func TestFilterFunction(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").FilterFunction(func(i int, s *Selection) bool {
|
sel := Doc().Find(".pvk-content").FilterFunction(func(i int, s *Selection) bool {
|
||||||
return i > 0
|
return i > 0
|
||||||
})
|
})
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterFunctionRollback(t *testing.T) {
|
func TestFilterFunctionRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.FilterFunction(func(i int, s *Selection) bool {
|
sel2 := sel.FilterFunction(func(i int, s *Selection) bool {
|
||||||
return i > 0
|
return i > 0
|
||||||
}).End()
|
}).End()
|
||||||
@@ -36,27 +36,27 @@ func TestFilterFunctionRollback(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterNode(t *testing.T) {
|
func TestFilterNode(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.FilterNodes(sel.Nodes[2])
|
sel2 := sel.FilterNodes(sel.Nodes[2])
|
||||||
AssertLength(t, sel2.Nodes, 1)
|
AssertLength(t, sel2.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterNodeRollback(t *testing.T) {
|
func TestFilterNodeRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.FilterNodes(sel.Nodes[2]).End()
|
sel2 := sel.FilterNodes(sel.Nodes[2]).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterSelection(t *testing.T) {
|
func TestFilterSelection(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".link")
|
sel := Doc().Find(".link")
|
||||||
sel2 := Doc().Root.Find("a[ng-click]")
|
sel2 := Doc().Find("a[ng-click]")
|
||||||
sel3 := sel.FilterSelection(sel2)
|
sel3 := sel.FilterSelection(sel2)
|
||||||
AssertLength(t, sel3.Nodes, 1)
|
AssertLength(t, sel3.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterSelectionRollback(t *testing.T) {
|
func TestFilterSelectionRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".link")
|
sel := Doc().Find(".link")
|
||||||
sel2 := Doc().Root.Find("a[ng-click]")
|
sel2 := Doc().Find("a[ng-click]")
|
||||||
sel2 = sel.FilterSelection(sel2).End()
|
sel2 = sel.FilterSelection(sel2).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
@@ -64,36 +64,36 @@ func TestFilterSelectionRollback(t *testing.T) {
|
|||||||
func TestFilterSelectionNil(t *testing.T) {
|
func TestFilterSelectionNil(t *testing.T) {
|
||||||
var sel2 *Selection
|
var sel2 *Selection
|
||||||
|
|
||||||
sel := Doc().Root.Find(".link")
|
sel := Doc().Find(".link")
|
||||||
sel3 := sel.FilterSelection(sel2)
|
sel3 := sel.FilterSelection(sel2)
|
||||||
AssertLength(t, sel3.Nodes, 0)
|
AssertLength(t, sel3.Nodes, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNot(t *testing.T) {
|
func TestNot(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".span12").Not(".alert")
|
sel := Doc().Find(".span12").Not(".alert")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotRollback(t *testing.T) {
|
func TestNotRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".span12")
|
sel := Doc().Find(".span12")
|
||||||
sel2 := sel.Not(".alert").End()
|
sel2 := sel.Not(".alert").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotNone(t *testing.T) {
|
func TestNotNone(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".span12").Not(".zzalert")
|
sel := Doc().Find(".span12").Not(".zzalert")
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotFunction(t *testing.T) {
|
func TestNotFunction(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").NotFunction(func(i int, s *Selection) bool {
|
sel := Doc().Find(".pvk-content").NotFunction(func(i int, s *Selection) bool {
|
||||||
return i > 0
|
return i > 0
|
||||||
})
|
})
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotFunctionRollback(t *testing.T) {
|
func TestNotFunctionRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.NotFunction(func(i int, s *Selection) bool {
|
sel2 := sel.NotFunction(func(i int, s *Selection) bool {
|
||||||
return i > 0
|
return i > 0
|
||||||
}).End()
|
}).End()
|
||||||
@@ -101,91 +101,91 @@ func TestNotFunctionRollback(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNotNode(t *testing.T) {
|
func TestNotNode(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.NotNodes(sel.Nodes[2])
|
sel2 := sel.NotNodes(sel.Nodes[2])
|
||||||
AssertLength(t, sel2.Nodes, 2)
|
AssertLength(t, sel2.Nodes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotNodeRollback(t *testing.T) {
|
func TestNotNodeRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.NotNodes(sel.Nodes[2]).End()
|
sel2 := sel.NotNodes(sel.Nodes[2]).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotSelection(t *testing.T) {
|
func TestNotSelection(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".link")
|
sel := Doc().Find(".link")
|
||||||
sel2 := Doc().Root.Find("a[ng-click]")
|
sel2 := Doc().Find("a[ng-click]")
|
||||||
sel3 := sel.NotSelection(sel2)
|
sel3 := sel.NotSelection(sel2)
|
||||||
AssertLength(t, sel3.Nodes, 6)
|
AssertLength(t, sel3.Nodes, 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNotSelectionRollback(t *testing.T) {
|
func TestNotSelectionRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".link")
|
sel := Doc().Find(".link")
|
||||||
sel2 := Doc().Root.Find("a[ng-click]")
|
sel2 := Doc().Find("a[ng-click]")
|
||||||
sel2 = sel.NotSelection(sel2).End()
|
sel2 = sel.NotSelection(sel2).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIntersection(t *testing.T) {
|
func TestIntersection(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-gutter")
|
sel := Doc().Find(".pvk-gutter")
|
||||||
sel2 := Doc().Root.Find("div").Intersection(sel)
|
sel2 := Doc().Find("div").Intersection(sel)
|
||||||
AssertLength(t, sel2.Nodes, 6)
|
AssertLength(t, sel2.Nodes, 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIntersectionRollback(t *testing.T) {
|
func TestIntersectionRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-gutter")
|
sel := Doc().Find(".pvk-gutter")
|
||||||
sel2 := Doc().Root.Find("div")
|
sel2 := Doc().Find("div")
|
||||||
sel2 = sel.Intersection(sel2).End()
|
sel2 = sel.Intersection(sel2).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHas(t *testing.T) {
|
func TestHas(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").Has(".center-content")
|
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
|
// Has() returns the high-level .container-fluid div, and the one that is the immediate parent of center-content
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHasRollback(t *testing.T) {
|
func TestHasRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := sel.Has(".center-content").End()
|
sel2 := sel.Has(".center-content").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHasNodes(t *testing.T) {
|
func TestHasNodes(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := Doc().Root.Find(".center-content")
|
sel2 := Doc().Find(".center-content")
|
||||||
sel = sel.HasNodes(sel2.Nodes...)
|
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
|
// Has() returns the high-level .container-fluid div, and the one that is the immediate parent of center-content
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHasNodesRollback(t *testing.T) {
|
func TestHasNodesRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := Doc().Root.Find(".center-content")
|
sel2 := Doc().Find(".center-content")
|
||||||
sel2 = sel.HasNodes(sel2.Nodes...).End()
|
sel2 = sel.HasNodes(sel2.Nodes...).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHasSelection(t *testing.T) {
|
func TestHasSelection(t *testing.T) {
|
||||||
sel := Doc().Root.Find("p")
|
sel := Doc().Find("p")
|
||||||
sel2 := Doc().Root.Find("small")
|
sel2 := Doc().Find("small")
|
||||||
sel = sel.HasSelection(sel2)
|
sel = sel.HasSelection(sel2)
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHasSelectionRollback(t *testing.T) {
|
func TestHasSelectionRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find("p")
|
sel := Doc().Find("p")
|
||||||
sel2 := Doc().Root.Find("small")
|
sel2 := Doc().Find("small")
|
||||||
sel2 = sel.HasSelection(sel2).End()
|
sel2 = sel.HasSelection(sel2).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnd(t *testing.T) {
|
func TestEnd(t *testing.T) {
|
||||||
sel := Doc().Root.Find("p").Has("small").End()
|
sel := Doc().Find("p").Has("small").End()
|
||||||
AssertLength(t, sel.Nodes, 4)
|
AssertLength(t, sel.Nodes, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEndToTop(t *testing.T) {
|
func TestEndToTop(t *testing.T) {
|
||||||
sel := Doc().Root.Find("p").Has("small").End().End().End()
|
sel := Doc().Find("p").Has("small").End().End().End()
|
||||||
AssertLength(t, sel.Nodes, 0)
|
AssertLength(t, sel.Nodes, 0)
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@ import (
|
|||||||
func TestEach(t *testing.T) {
|
func TestEach(t *testing.T) {
|
||||||
var cnt int
|
var cnt int
|
||||||
|
|
||||||
sel := Doc().Root.Find(".hero-unit .row-fluid").Each(func(i int, n *Selection) {
|
sel := Doc().Find(".hero-unit .row-fluid").Each(func(i int, n *Selection) {
|
||||||
cnt++
|
cnt++
|
||||||
t.Logf("At index %v, node %v", i, n.Nodes[0].Data)
|
t.Logf("At index %v, node %v", i, n.Nodes[0].Data)
|
||||||
}).Find("a")
|
}).Find("a")
|
||||||
@@ -22,7 +22,7 @@ func TestEach(t *testing.T) {
|
|||||||
func TestEachEmptySelection(t *testing.T) {
|
func TestEachEmptySelection(t *testing.T) {
|
||||||
var cnt int
|
var cnt int
|
||||||
|
|
||||||
sel := Doc().Root.Find("zzzz")
|
sel := Doc().Find("zzzz")
|
||||||
sel.Each(func(i int, n *Selection) {
|
sel.Each(func(i int, n *Selection) {
|
||||||
cnt++
|
cnt++
|
||||||
})
|
})
|
||||||
@@ -34,7 +34,7 @@ func TestEachEmptySelection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMap(t *testing.T) {
|
func TestMap(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
vals := sel.Map(func(i int, s *Selection) string {
|
vals := sel.Map(func(i int, s *Selection) string {
|
||||||
n := s.Get(0)
|
n := s.Get(0)
|
||||||
if n.Type == html.ElementNode {
|
if n.Type == html.ElementNode {
|
||||||
|
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestAttrExists(t *testing.T) {
|
func TestAttrExists(t *testing.T) {
|
||||||
if val, ok := Doc().Root.Find("a").Attr("href"); !ok {
|
if val, ok := Doc().Find("a").Attr("href"); !ok {
|
||||||
t.Error("Expected a value for the href attribute.")
|
t.Error("Expected a value for the href attribute.")
|
||||||
} else {
|
} else {
|
||||||
t.Logf("Href of first anchor: %v.", val)
|
t.Logf("Href of first anchor: %v.", val)
|
||||||
@@ -15,20 +15,20 @@ func TestAttrExists(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAttrNotExist(t *testing.T) {
|
func TestAttrNotExist(t *testing.T) {
|
||||||
if val, ok := Doc().Root.Find("div.row-fluid").Attr("href"); ok {
|
if val, ok := Doc().Find("div.row-fluid").Attr("href"); ok {
|
||||||
t.Errorf("Expected no value for the href attribute, got %v.", val)
|
t.Errorf("Expected no value for the href attribute, got %v.", val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestText(t *testing.T) {
|
func TestText(t *testing.T) {
|
||||||
txt := Doc().Root.Find("h1").Text()
|
txt := Doc().Find("h1").Text()
|
||||||
if strings.Trim(txt, " \n\r\t") != "Provok.in" {
|
if strings.Trim(txt, " \n\r\t") != "Provok.in" {
|
||||||
t.Errorf("Expected text to be Provok.in, found %s.", txt)
|
t.Errorf("Expected text to be Provok.in, found %s.", txt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestText2(t *testing.T) {
|
func TestText2(t *testing.T) {
|
||||||
txt := Doc().Root.Find(".hero-unit .container-fluid .row-fluid:nth-child(1)").Text()
|
txt := Doc().Find(".hero-unit .container-fluid .row-fluid:nth-child(1)").Text()
|
||||||
if ok, e := regexp.MatchString(`^\s+Provok\.in\s+Prove your point.\s+$`, txt); !ok || e != nil {
|
if ok, e := regexp.MatchString(`^\s+Provok\.in\s+Prove your point.\s+$`, txt); !ok || e != nil {
|
||||||
t.Errorf("Expected text to be Provok.in Prove your point., found %s.", txt)
|
t.Errorf("Expected text to be Provok.in Prove your point., found %s.", txt)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
@@ -38,7 +38,7 @@ func TestText2(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestText3(t *testing.T) {
|
func TestText3(t *testing.T) {
|
||||||
txt := Doc().Root.Find(".pvk-gutter").First().Text()
|
txt := Doc().Find(".pvk-gutter").First().Text()
|
||||||
// There's an character in there...
|
// There's an character in there...
|
||||||
if ok, e := regexp.MatchString(`^[\s\x{00A0}]+$`, txt); !ok || e != nil {
|
if ok, e := regexp.MatchString(`^[\s\x{00A0}]+$`, txt); !ok || e != nil {
|
||||||
t.Errorf("Expected spaces, found <%v>.", txt)
|
t.Errorf("Expected spaces, found <%v>.", txt)
|
||||||
@@ -49,7 +49,7 @@ func TestText3(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHtml(t *testing.T) {
|
func TestHtml(t *testing.T) {
|
||||||
txt, e := Doc().Root.Find("h1").Html()
|
txt, e := Doc().Find("h1").Html()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
t.Errorf("Error: %s.", e)
|
t.Errorf("Error: %s.", e)
|
||||||
}
|
}
|
||||||
|
@@ -5,28 +5,28 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestIs(t *testing.T) {
|
func TestIs(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".footer p:nth-child(1)")
|
sel := Doc().Find(".footer p:nth-child(1)")
|
||||||
if !sel.Is("p") {
|
if !sel.Is("p") {
|
||||||
t.Error("Expected .footer p:nth-child(1) to be p.")
|
t.Error("Expected .footer p:nth-child(1) to be p.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsPositional(t *testing.T) {
|
func TestIsPositional(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".footer p:nth-child(2)")
|
sel := Doc().Find(".footer p:nth-child(2)")
|
||||||
if !sel.Is("p:nth-child(2)") {
|
if !sel.Is("p:nth-child(2)") {
|
||||||
t.Error("Expected .footer p:nth-child(2) to be p:nth-child(2).")
|
t.Error("Expected .footer p:nth-child(2) to be p:nth-child(2).")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsPositionalNot(t *testing.T) {
|
func TestIsPositionalNot(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".footer p:nth-child(1)")
|
sel := Doc().Find(".footer p:nth-child(1)")
|
||||||
if sel.Is("p:nth-child(2)") {
|
if sel.Is("p:nth-child(2)") {
|
||||||
t.Error("Expected .footer p:nth-child(1) NOT to be p:nth-child(2).")
|
t.Error("Expected .footer p:nth-child(1) NOT to be p:nth-child(2).")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsFunction(t *testing.T) {
|
func TestIsFunction(t *testing.T) {
|
||||||
ok := Doc().Root.Find("div").IsFunction(func(i int, s *Selection) bool {
|
ok := Doc().Find("div").IsFunction(func(i int, s *Selection) bool {
|
||||||
return s.HasClass("container-fluid")
|
return s.HasClass("container-fluid")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ func TestIsFunction(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIsFunctionRollback(t *testing.T) {
|
func TestIsFunctionRollback(t *testing.T) {
|
||||||
ok := Doc().Root.Find("div").IsFunction(func(i int, s *Selection) bool {
|
ok := Doc().Find("div").IsFunction(func(i int, s *Selection) bool {
|
||||||
return s.HasClass("container-fluid")
|
return s.HasClass("container-fluid")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -46,8 +46,8 @@ func TestIsFunctionRollback(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIsSelection(t *testing.T) {
|
func TestIsSelection(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div")
|
sel := Doc().Find("div")
|
||||||
sel2 := Doc().Root.Find(".pvk-gutter")
|
sel2 := Doc().Find(".pvk-gutter")
|
||||||
|
|
||||||
if !sel.IsSelection(sel2) {
|
if !sel.IsSelection(sel2) {
|
||||||
t.Error("Expected some div to have a pvk-gutter class.")
|
t.Error("Expected some div to have a pvk-gutter class.")
|
||||||
@@ -55,8 +55,8 @@ func TestIsSelection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIsSelectionNot(t *testing.T) {
|
func TestIsSelectionNot(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div")
|
sel := Doc().Find("div")
|
||||||
sel2 := Doc().Root.Find("a")
|
sel2 := Doc().Find("a")
|
||||||
|
|
||||||
if sel.IsSelection(sel2) {
|
if sel.IsSelection(sel2) {
|
||||||
t.Error("Expected some div NOT to be an anchor.")
|
t.Error("Expected some div NOT to be an anchor.")
|
||||||
@@ -64,8 +64,8 @@ func TestIsSelectionNot(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIsNodes(t *testing.T) {
|
func TestIsNodes(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div")
|
sel := Doc().Find("div")
|
||||||
sel2 := Doc().Root.Find(".footer")
|
sel2 := Doc().Find(".footer")
|
||||||
|
|
||||||
if !sel.IsNodes(sel2.Nodes[0]) {
|
if !sel.IsNodes(sel2.Nodes[0]) {
|
||||||
t.Error("Expected some div to have a footer class.")
|
t.Error("Expected some div to have a footer class.")
|
||||||
@@ -73,44 +73,44 @@ func TestIsNodes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHasClass(t *testing.T) {
|
func TestHasClass(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div")
|
sel := Doc().Find("div")
|
||||||
if !sel.HasClass("span12") {
|
if !sel.HasClass("span12") {
|
||||||
t.Error("Expected at least one div to have class span12.")
|
t.Error("Expected at least one div to have class span12.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHasClassNone(t *testing.T) {
|
func TestHasClassNone(t *testing.T) {
|
||||||
sel := Doc().Root.Find("h2")
|
sel := Doc().Find("h2")
|
||||||
if sel.HasClass("toto") {
|
if sel.HasClass("toto") {
|
||||||
t.Error("Expected h1 to have no class.")
|
t.Error("Expected h1 to have no class.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHasClassNotFirst(t *testing.T) {
|
func TestHasClassNotFirst(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".alert")
|
sel := Doc().Find(".alert")
|
||||||
if !sel.HasClass("alert-error") {
|
if !sel.HasClass("alert-error") {
|
||||||
t.Error("Expected .alert to also have class .alert-error.")
|
t.Error("Expected .alert to also have class .alert-error.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDocContains(t *testing.T) {
|
func TestDocContains(t *testing.T) {
|
||||||
sel := Doc().Root.Find("h1")
|
sel := Doc().Find("h1")
|
||||||
if !Doc().Root.Contains(sel.Nodes[0]) {
|
if !Doc().Contains(sel.Nodes[0]) {
|
||||||
t.Error("Expected document to contain H1 tag.")
|
t.Error("Expected document to contain H1 tag.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSelContains(t *testing.T) {
|
func TestSelContains(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".row-fluid")
|
sel := Doc().Find(".row-fluid")
|
||||||
sel2 := Doc().Root.Find("a[ng-click]")
|
sel2 := Doc().Find("a[ng-click]")
|
||||||
if !sel.Contains(sel2.Nodes[0]) {
|
if !sel.Contains(sel2.Nodes[0]) {
|
||||||
t.Error("Expected .row-fluid to contain a[ng-click] tag.")
|
t.Error("Expected .row-fluid to contain a[ng-click] tag.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSelNotContains(t *testing.T) {
|
func TestSelNotContains(t *testing.T) {
|
||||||
sel := Doc().Root.Find("a.link")
|
sel := Doc().Find("a.link")
|
||||||
sel2 := Doc().Root.Find("span")
|
sel2 := Doc().Find("span")
|
||||||
if sel.Contains(sel2.Nodes[0]) {
|
if sel.Contains(sel2.Nodes[0]) {
|
||||||
t.Error("Expected a.link to NOT contain span tag.")
|
t.Error("Expected a.link to NOT contain span tag.")
|
||||||
}
|
}
|
||||||
|
@@ -5,574 +5,574 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestFind(t *testing.T) {
|
func TestFind(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div.row-fluid")
|
sel := Doc().Find("div.row-fluid")
|
||||||
AssertLength(t, sel.Nodes, 9)
|
AssertLength(t, sel.Nodes, 9)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindRollback(t *testing.T) {
|
func TestFindRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div.row-fluid")
|
sel := Doc().Find("div.row-fluid")
|
||||||
sel2 := sel.Find("a").End()
|
sel2 := sel.Find("a").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindNotSelf(t *testing.T) {
|
func TestFindNotSelf(t *testing.T) {
|
||||||
sel := Doc().Root.Find("h1").Find("h1")
|
sel := Doc().Find("h1").Find("h1")
|
||||||
AssertLength(t, sel.Nodes, 0)
|
AssertLength(t, sel.Nodes, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindInvalidSelector(t *testing.T) {
|
func TestFindInvalidSelector(t *testing.T) {
|
||||||
defer AssertPanic(t)
|
defer AssertPanic(t)
|
||||||
Doc().Root.Find(":+ ^")
|
Doc().Find(":+ ^")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChainedFind(t *testing.T) {
|
func TestChainedFind(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div.hero-unit").Find(".row-fluid")
|
sel := Doc().Find("div.hero-unit").Find(".row-fluid")
|
||||||
AssertLength(t, sel.Nodes, 4)
|
AssertLength(t, sel.Nodes, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChildren(t *testing.T) {
|
func TestChildren(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").Children()
|
sel := Doc().Find(".pvk-content").Children()
|
||||||
AssertLength(t, sel.Nodes, 5)
|
AssertLength(t, sel.Nodes, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChildrenRollback(t *testing.T) {
|
func TestChildrenRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.Children().End()
|
sel2 := sel.Children().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContents(t *testing.T) {
|
func TestContents(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").Contents()
|
sel := Doc().Find(".pvk-content").Contents()
|
||||||
AssertLength(t, sel.Nodes, 13)
|
AssertLength(t, sel.Nodes, 13)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContentsRollback(t *testing.T) {
|
func TestContentsRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.Contents().End()
|
sel2 := sel.Contents().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChildrenFiltered(t *testing.T) {
|
func TestChildrenFiltered(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").ChildrenFiltered(".hero-unit")
|
sel := Doc().Find(".pvk-content").ChildrenFiltered(".hero-unit")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChildrenFilteredRollback(t *testing.T) {
|
func TestChildrenFilteredRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.ChildrenFiltered(".hero-unit").End()
|
sel2 := sel.ChildrenFiltered(".hero-unit").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContentsFiltered(t *testing.T) {
|
func TestContentsFiltered(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").ContentsFiltered(".hero-unit")
|
sel := Doc().Find(".pvk-content").ContentsFiltered(".hero-unit")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContentsFilteredRollback(t *testing.T) {
|
func TestContentsFilteredRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content")
|
sel := Doc().Find(".pvk-content")
|
||||||
sel2 := sel.ContentsFiltered(".hero-unit").End()
|
sel2 := sel.ContentsFiltered(".hero-unit").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChildrenFilteredNone(t *testing.T) {
|
func TestChildrenFilteredNone(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-content").ChildrenFiltered("a.btn")
|
sel := Doc().Find(".pvk-content").ChildrenFiltered("a.btn")
|
||||||
AssertLength(t, sel.Nodes, 0)
|
AssertLength(t, sel.Nodes, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParent(t *testing.T) {
|
func TestParent(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").Parent()
|
sel := Doc().Find(".container-fluid").Parent()
|
||||||
AssertLength(t, sel.Nodes, 3)
|
AssertLength(t, sel.Nodes, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentRollback(t *testing.T) {
|
func TestParentRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := sel.Parent().End()
|
sel2 := sel.Parent().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentBody(t *testing.T) {
|
func TestParentBody(t *testing.T) {
|
||||||
sel := Doc().Root.Find("body").Parent()
|
sel := Doc().Find("body").Parent()
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentFiltered(t *testing.T) {
|
func TestParentFiltered(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").ParentFiltered(".hero-unit")
|
sel := Doc().Find(".container-fluid").ParentFiltered(".hero-unit")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
AssertClass(t, sel, "hero-unit")
|
AssertClass(t, sel, "hero-unit")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentFilteredRollback(t *testing.T) {
|
func TestParentFilteredRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := sel.ParentFiltered(".hero-unit").End()
|
sel2 := sel.ParentFiltered(".hero-unit").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParents(t *testing.T) {
|
func TestParents(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").Parents()
|
sel := Doc().Find(".container-fluid").Parents()
|
||||||
AssertLength(t, sel.Nodes, 8)
|
AssertLength(t, sel.Nodes, 8)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsOrder(t *testing.T) {
|
func TestParentsOrder(t *testing.T) {
|
||||||
sel := Doc().Root.Find("#cf2").Parents()
|
sel := Doc().Find("#cf2").Parents()
|
||||||
AssertLength(t, sel.Nodes, 6)
|
AssertLength(t, sel.Nodes, 6)
|
||||||
AssertSelectionIs(t, sel, ".hero-unit", ".pvk-content", "div.row-fluid", "#cf1", "body", "html")
|
AssertSelectionIs(t, sel, ".hero-unit", ".pvk-content", "div.row-fluid", "#cf1", "body", "html")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsRollback(t *testing.T) {
|
func TestParentsRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := sel.Parents().End()
|
sel2 := sel.Parents().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsFiltered(t *testing.T) {
|
func TestParentsFiltered(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").ParentsFiltered("body")
|
sel := Doc().Find(".container-fluid").ParentsFiltered("body")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsFilteredRollback(t *testing.T) {
|
func TestParentsFilteredRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := sel.ParentsFiltered("body").End()
|
sel2 := sel.ParentsFiltered("body").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsUntil(t *testing.T) {
|
func TestParentsUntil(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").ParentsUntil("body")
|
sel := Doc().Find(".container-fluid").ParentsUntil("body")
|
||||||
AssertLength(t, sel.Nodes, 6)
|
AssertLength(t, sel.Nodes, 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsUntilRollback(t *testing.T) {
|
func TestParentsUntilRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := sel.ParentsUntil("body").End()
|
sel2 := sel.ParentsUntil("body").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsUntilSelection(t *testing.T) {
|
func TestParentsUntilSelection(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := Doc().Root.Find(".pvk-content")
|
sel2 := Doc().Find(".pvk-content")
|
||||||
sel = sel.ParentsUntilSelection(sel2)
|
sel = sel.ParentsUntilSelection(sel2)
|
||||||
AssertLength(t, sel.Nodes, 3)
|
AssertLength(t, sel.Nodes, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsUntilSelectionRollback(t *testing.T) {
|
func TestParentsUntilSelectionRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := Doc().Root.Find(".pvk-content")
|
sel2 := Doc().Find(".pvk-content")
|
||||||
sel2 = sel.ParentsUntilSelection(sel2).End()
|
sel2 = sel.ParentsUntilSelection(sel2).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsUntilNodes(t *testing.T) {
|
func TestParentsUntilNodes(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := Doc().Root.Find(".pvk-content, .hero-unit")
|
sel2 := Doc().Find(".pvk-content, .hero-unit")
|
||||||
sel = sel.ParentsUntilNodes(sel2.Nodes...)
|
sel = sel.ParentsUntilNodes(sel2.Nodes...)
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsUntilNodesRollback(t *testing.T) {
|
func TestParentsUntilNodesRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := Doc().Root.Find(".pvk-content, .hero-unit")
|
sel2 := Doc().Find(".pvk-content, .hero-unit")
|
||||||
sel2 = sel.ParentsUntilNodes(sel2.Nodes...).End()
|
sel2 = sel.ParentsUntilNodes(sel2.Nodes...).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsFilteredUntil(t *testing.T) {
|
func TestParentsFilteredUntil(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").ParentsFilteredUntil(".pvk-content", "body")
|
sel := Doc().Find(".container-fluid").ParentsFilteredUntil(".pvk-content", "body")
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsFilteredUntilRollback(t *testing.T) {
|
func TestParentsFilteredUntilRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := sel.ParentsFilteredUntil(".pvk-content", "body").End()
|
sel2 := sel.ParentsFilteredUntil(".pvk-content", "body").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsFilteredUntilSelection(t *testing.T) {
|
func TestParentsFilteredUntilSelection(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := Doc().Root.Find(".row-fluid")
|
sel2 := Doc().Find(".row-fluid")
|
||||||
sel = sel.ParentsFilteredUntilSelection("div", sel2)
|
sel = sel.ParentsFilteredUntilSelection("div", sel2)
|
||||||
AssertLength(t, sel.Nodes, 3)
|
AssertLength(t, sel.Nodes, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsFilteredUntilSelectionRollback(t *testing.T) {
|
func TestParentsFilteredUntilSelectionRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := Doc().Root.Find(".row-fluid")
|
sel2 := Doc().Find(".row-fluid")
|
||||||
sel2 = sel.ParentsFilteredUntilSelection("div", sel2).End()
|
sel2 = sel.ParentsFilteredUntilSelection("div", sel2).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsFilteredUntilNodes(t *testing.T) {
|
func TestParentsFilteredUntilNodes(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := Doc().Root.Find(".row-fluid")
|
sel2 := Doc().Find(".row-fluid")
|
||||||
sel = sel.ParentsFilteredUntilNodes("body", sel2.Nodes...)
|
sel = sel.ParentsFilteredUntilNodes("body", sel2.Nodes...)
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentsFilteredUntilNodesRollback(t *testing.T) {
|
func TestParentsFilteredUntilNodesRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := Doc().Root.Find(".row-fluid")
|
sel2 := Doc().Find(".row-fluid")
|
||||||
sel2 = sel.ParentsFilteredUntilNodes("body", sel2.Nodes...).End()
|
sel2 = sel.ParentsFilteredUntilNodes("body", sel2.Nodes...).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSiblings(t *testing.T) {
|
func TestSiblings(t *testing.T) {
|
||||||
sel := Doc().Root.Find("h1").Siblings()
|
sel := Doc().Find("h1").Siblings()
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSiblingsRollback(t *testing.T) {
|
func TestSiblingsRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find("h1")
|
sel := Doc().Find("h1")
|
||||||
sel2 := sel.Siblings().End()
|
sel2 := sel.Siblings().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSiblings2(t *testing.T) {
|
func TestSiblings2(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-gutter").Siblings()
|
sel := Doc().Find(".pvk-gutter").Siblings()
|
||||||
AssertLength(t, sel.Nodes, 9)
|
AssertLength(t, sel.Nodes, 9)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSiblings3(t *testing.T) {
|
func TestSiblings3(t *testing.T) {
|
||||||
sel := Doc().Root.Find("body>.container-fluid").Siblings()
|
sel := Doc().Find("body>.container-fluid").Siblings()
|
||||||
AssertLength(t, sel.Nodes, 0)
|
AssertLength(t, sel.Nodes, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSiblingsFiltered(t *testing.T) {
|
func TestSiblingsFiltered(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-gutter").SiblingsFiltered(".pvk-content")
|
sel := Doc().Find(".pvk-gutter").SiblingsFiltered(".pvk-content")
|
||||||
AssertLength(t, sel.Nodes, 3)
|
AssertLength(t, sel.Nodes, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSiblingsFilteredRollback(t *testing.T) {
|
func TestSiblingsFilteredRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-gutter")
|
sel := Doc().Find(".pvk-gutter")
|
||||||
sel2 := sel.SiblingsFiltered(".pvk-content").End()
|
sel2 := sel.SiblingsFiltered(".pvk-content").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNext(t *testing.T) {
|
func TestNext(t *testing.T) {
|
||||||
sel := Doc().Root.Find("h1").Next()
|
sel := Doc().Find("h1").Next()
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextRollback(t *testing.T) {
|
func TestNextRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find("h1")
|
sel := Doc().Find("h1")
|
||||||
sel2 := sel.Next().End()
|
sel2 := sel.Next().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNext2(t *testing.T) {
|
func TestNext2(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".close").Next()
|
sel := Doc().Find(".close").Next()
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextNone(t *testing.T) {
|
func TestNextNone(t *testing.T) {
|
||||||
sel := Doc().Root.Find("small").Next()
|
sel := Doc().Find("small").Next()
|
||||||
AssertLength(t, sel.Nodes, 0)
|
AssertLength(t, sel.Nodes, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextFiltered(t *testing.T) {
|
func TestNextFiltered(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").NextFiltered("div")
|
sel := Doc().Find(".container-fluid").NextFiltered("div")
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextFilteredRollback(t *testing.T) {
|
func TestNextFilteredRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid")
|
sel := Doc().Find(".container-fluid")
|
||||||
sel2 := sel.NextFiltered("div").End()
|
sel2 := sel.NextFiltered("div").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextFiltered2(t *testing.T) {
|
func TestNextFiltered2(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".container-fluid").NextFiltered("[ng-view]")
|
sel := Doc().Find(".container-fluid").NextFiltered("[ng-view]")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrev(t *testing.T) {
|
func TestPrev(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".red").Prev()
|
sel := Doc().Find(".red").Prev()
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
AssertClass(t, sel, "green")
|
AssertClass(t, sel, "green")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevRollback(t *testing.T) {
|
func TestPrevRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".red")
|
sel := Doc().Find(".red")
|
||||||
sel2 := sel.Prev().End()
|
sel2 := sel.Prev().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrev2(t *testing.T) {
|
func TestPrev2(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".row-fluid").Prev()
|
sel := Doc().Find(".row-fluid").Prev()
|
||||||
AssertLength(t, sel.Nodes, 5)
|
AssertLength(t, sel.Nodes, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevNone(t *testing.T) {
|
func TestPrevNone(t *testing.T) {
|
||||||
sel := Doc().Root.Find("h2").Prev()
|
sel := Doc().Find("h2").Prev()
|
||||||
AssertLength(t, sel.Nodes, 0)
|
AssertLength(t, sel.Nodes, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevFiltered(t *testing.T) {
|
func TestPrevFiltered(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".row-fluid").PrevFiltered(".row-fluid")
|
sel := Doc().Find(".row-fluid").PrevFiltered(".row-fluid")
|
||||||
AssertLength(t, sel.Nodes, 5)
|
AssertLength(t, sel.Nodes, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevFilteredRollback(t *testing.T) {
|
func TestPrevFilteredRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".row-fluid")
|
sel := Doc().Find(".row-fluid")
|
||||||
sel2 := sel.PrevFiltered(".row-fluid").End()
|
sel2 := sel.PrevFiltered(".row-fluid").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextAll(t *testing.T) {
|
func TestNextAll(t *testing.T) {
|
||||||
sel := Doc().Root.Find("#cf2 div:nth-child(1)").NextAll()
|
sel := Doc().Find("#cf2 div:nth-child(1)").NextAll()
|
||||||
AssertLength(t, sel.Nodes, 3)
|
AssertLength(t, sel.Nodes, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextAllRollback(t *testing.T) {
|
func TestNextAllRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find("#cf2 div:nth-child(1)")
|
sel := Doc().Find("#cf2 div:nth-child(1)")
|
||||||
sel2 := sel.NextAll().End()
|
sel2 := sel.NextAll().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextAll2(t *testing.T) {
|
func TestNextAll2(t *testing.T) {
|
||||||
sel := Doc().Root.Find("div[ng-cloak]").NextAll()
|
sel := Doc().Find("div[ng-cloak]").NextAll()
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextAllNone(t *testing.T) {
|
func TestNextAllNone(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".footer").NextAll()
|
sel := Doc().Find(".footer").NextAll()
|
||||||
AssertLength(t, sel.Nodes, 0)
|
AssertLength(t, sel.Nodes, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextAllFiltered(t *testing.T) {
|
func TestNextAllFiltered(t *testing.T) {
|
||||||
sel := Doc().Root.Find("#cf2 .row-fluid").NextAllFiltered("[ng-cloak]")
|
sel := Doc().Find("#cf2 .row-fluid").NextAllFiltered("[ng-cloak]")
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextAllFilteredRollback(t *testing.T) {
|
func TestNextAllFilteredRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find("#cf2 .row-fluid")
|
sel := Doc().Find("#cf2 .row-fluid")
|
||||||
sel2 := sel.NextAllFiltered("[ng-cloak]").End()
|
sel2 := sel.NextAllFiltered("[ng-cloak]").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextAllFiltered2(t *testing.T) {
|
func TestNextAllFiltered2(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".close").NextAllFiltered("h4")
|
sel := Doc().Find(".close").NextAllFiltered("h4")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevAll(t *testing.T) {
|
func TestPrevAll(t *testing.T) {
|
||||||
sel := Doc().Root.Find("[ng-view]").PrevAll()
|
sel := Doc().Find("[ng-view]").PrevAll()
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevAllOrder(t *testing.T) {
|
func TestPrevAllOrder(t *testing.T) {
|
||||||
sel := Doc().Root.Find("[ng-view]").PrevAll()
|
sel := Doc().Find("[ng-view]").PrevAll()
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
AssertSelectionIs(t, sel, "#cf4", "#cf3")
|
AssertSelectionIs(t, sel, "#cf4", "#cf3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevAllRollback(t *testing.T) {
|
func TestPrevAllRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find("[ng-view]")
|
sel := Doc().Find("[ng-view]")
|
||||||
sel2 := sel.PrevAll().End()
|
sel2 := sel.PrevAll().End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevAll2(t *testing.T) {
|
func TestPrevAll2(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-gutter").PrevAll()
|
sel := Doc().Find(".pvk-gutter").PrevAll()
|
||||||
AssertLength(t, sel.Nodes, 6)
|
AssertLength(t, sel.Nodes, 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevAllFiltered(t *testing.T) {
|
func TestPrevAllFiltered(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-gutter").PrevAllFiltered(".pvk-content")
|
sel := Doc().Find(".pvk-gutter").PrevAllFiltered(".pvk-content")
|
||||||
AssertLength(t, sel.Nodes, 3)
|
AssertLength(t, sel.Nodes, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevAllFilteredRollback(t *testing.T) {
|
func TestPrevAllFilteredRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".pvk-gutter")
|
sel := Doc().Find(".pvk-gutter")
|
||||||
sel2 := sel.PrevAllFiltered(".pvk-content").End()
|
sel2 := sel.PrevAllFiltered(".pvk-content").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextUntil(t *testing.T) {
|
func TestNextUntil(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".alert a").NextUntil("p")
|
sel := Doc().Find(".alert a").NextUntil("p")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
AssertSelectionIs(t, sel, "h4")
|
AssertSelectionIs(t, sel, "h4")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextUntil2(t *testing.T) {
|
func TestNextUntil2(t *testing.T) {
|
||||||
sel := Doc().Root.Find("#cf2-1").NextUntil("[ng-cloak]")
|
sel := Doc().Find("#cf2-1").NextUntil("[ng-cloak]")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
AssertSelectionIs(t, sel, "#cf2-2")
|
AssertSelectionIs(t, sel, "#cf2-2")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextUntilOrder(t *testing.T) {
|
func TestNextUntilOrder(t *testing.T) {
|
||||||
sel := Doc().Root.Find("#cf2-1").NextUntil("#cf2-4")
|
sel := Doc().Find("#cf2-1").NextUntil("#cf2-4")
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
AssertSelectionIs(t, sel, "#cf2-2", "#cf2-3")
|
AssertSelectionIs(t, sel, "#cf2-2", "#cf2-3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextUntilRollback(t *testing.T) {
|
func TestNextUntilRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find("#cf2-1")
|
sel := Doc().Find("#cf2-1")
|
||||||
sel2 := sel.PrevUntil("#cf2-4").End()
|
sel2 := sel.PrevUntil("#cf2-4").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextUntilSelection(t *testing.T) {
|
func TestNextUntilSelection(t *testing.T) {
|
||||||
sel := Doc2().Root.Find("#n2")
|
sel := Doc2().Find("#n2")
|
||||||
sel2 := Doc2().Root.Find("#n4")
|
sel2 := Doc2().Find("#n4")
|
||||||
sel2 = sel.NextUntilSelection(sel2)
|
sel2 = sel.NextUntilSelection(sel2)
|
||||||
AssertLength(t, sel2.Nodes, 1)
|
AssertLength(t, sel2.Nodes, 1)
|
||||||
AssertSelectionIs(t, sel2, "#n3")
|
AssertSelectionIs(t, sel2, "#n3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextUntilSelectionRollback(t *testing.T) {
|
func TestNextUntilSelectionRollback(t *testing.T) {
|
||||||
sel := Doc2().Root.Find("#n2")
|
sel := Doc2().Find("#n2")
|
||||||
sel2 := Doc2().Root.Find("#n4")
|
sel2 := Doc2().Find("#n4")
|
||||||
sel2 = sel.NextUntilSelection(sel2).End()
|
sel2 = sel.NextUntilSelection(sel2).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextUntilNodes(t *testing.T) {
|
func TestNextUntilNodes(t *testing.T) {
|
||||||
sel := Doc2().Root.Find("#n2")
|
sel := Doc2().Find("#n2")
|
||||||
sel2 := Doc2().Root.Find("#n5")
|
sel2 := Doc2().Find("#n5")
|
||||||
sel2 = sel.NextUntilNodes(sel2.Nodes...)
|
sel2 = sel.NextUntilNodes(sel2.Nodes...)
|
||||||
AssertLength(t, sel2.Nodes, 2)
|
AssertLength(t, sel2.Nodes, 2)
|
||||||
AssertSelectionIs(t, sel2, "#n3", "#n4")
|
AssertSelectionIs(t, sel2, "#n3", "#n4")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextUntilNodesRollback(t *testing.T) {
|
func TestNextUntilNodesRollback(t *testing.T) {
|
||||||
sel := Doc2().Root.Find("#n2")
|
sel := Doc2().Find("#n2")
|
||||||
sel2 := Doc2().Root.Find("#n5")
|
sel2 := Doc2().Find("#n5")
|
||||||
sel2 = sel.NextUntilNodes(sel2.Nodes...).End()
|
sel2 = sel.NextUntilNodes(sel2.Nodes...).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevUntil(t *testing.T) {
|
func TestPrevUntil(t *testing.T) {
|
||||||
sel := Doc().Root.Find(".alert p").PrevUntil("a")
|
sel := Doc().Find(".alert p").PrevUntil("a")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
AssertSelectionIs(t, sel, "h4")
|
AssertSelectionIs(t, sel, "h4")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevUntil2(t *testing.T) {
|
func TestPrevUntil2(t *testing.T) {
|
||||||
sel := Doc().Root.Find("[ng-cloak]").PrevUntil(":not([ng-cloak])")
|
sel := Doc().Find("[ng-cloak]").PrevUntil(":not([ng-cloak])")
|
||||||
AssertLength(t, sel.Nodes, 1)
|
AssertLength(t, sel.Nodes, 1)
|
||||||
AssertSelectionIs(t, sel, "[ng-cloak]")
|
AssertSelectionIs(t, sel, "[ng-cloak]")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevUntilOrder(t *testing.T) {
|
func TestPrevUntilOrder(t *testing.T) {
|
||||||
sel := Doc().Root.Find("#cf2-4").PrevUntil("#cf2-1")
|
sel := Doc().Find("#cf2-4").PrevUntil("#cf2-1")
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
AssertSelectionIs(t, sel, "#cf2-3", "#cf2-2")
|
AssertSelectionIs(t, sel, "#cf2-3", "#cf2-2")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevUntilRollback(t *testing.T) {
|
func TestPrevUntilRollback(t *testing.T) {
|
||||||
sel := Doc().Root.Find("#cf2-4")
|
sel := Doc().Find("#cf2-4")
|
||||||
sel2 := sel.PrevUntil("#cf2-1").End()
|
sel2 := sel.PrevUntil("#cf2-1").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevUntilSelection(t *testing.T) {
|
func TestPrevUntilSelection(t *testing.T) {
|
||||||
sel := Doc2().Root.Find("#n4")
|
sel := Doc2().Find("#n4")
|
||||||
sel2 := Doc2().Root.Find("#n2")
|
sel2 := Doc2().Find("#n2")
|
||||||
sel2 = sel.PrevUntilSelection(sel2)
|
sel2 = sel.PrevUntilSelection(sel2)
|
||||||
AssertLength(t, sel2.Nodes, 1)
|
AssertLength(t, sel2.Nodes, 1)
|
||||||
AssertSelectionIs(t, sel2, "#n3")
|
AssertSelectionIs(t, sel2, "#n3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevUntilSelectionRollback(t *testing.T) {
|
func TestPrevUntilSelectionRollback(t *testing.T) {
|
||||||
sel := Doc2().Root.Find("#n4")
|
sel := Doc2().Find("#n4")
|
||||||
sel2 := Doc2().Root.Find("#n2")
|
sel2 := Doc2().Find("#n2")
|
||||||
sel2 = sel.PrevUntilSelection(sel2).End()
|
sel2 = sel.PrevUntilSelection(sel2).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevUntilNodes(t *testing.T) {
|
func TestPrevUntilNodes(t *testing.T) {
|
||||||
sel := Doc2().Root.Find("#n5")
|
sel := Doc2().Find("#n5")
|
||||||
sel2 := Doc2().Root.Find("#n2")
|
sel2 := Doc2().Find("#n2")
|
||||||
sel2 = sel.PrevUntilNodes(sel2.Nodes...)
|
sel2 = sel.PrevUntilNodes(sel2.Nodes...)
|
||||||
AssertLength(t, sel2.Nodes, 2)
|
AssertLength(t, sel2.Nodes, 2)
|
||||||
AssertSelectionIs(t, sel2, "#n4", "#n3")
|
AssertSelectionIs(t, sel2, "#n4", "#n3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevUntilNodesRollback(t *testing.T) {
|
func TestPrevUntilNodesRollback(t *testing.T) {
|
||||||
sel := Doc2().Root.Find("#n5")
|
sel := Doc2().Find("#n5")
|
||||||
sel2 := Doc2().Root.Find("#n2")
|
sel2 := Doc2().Find("#n2")
|
||||||
sel2 = sel.PrevUntilNodes(sel2.Nodes...).End()
|
sel2 = sel.PrevUntilNodes(sel2.Nodes...).End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextFilteredUntil(t *testing.T) {
|
func TestNextFilteredUntil(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".two").NextFilteredUntil(".even", ".six")
|
sel := Doc2().Find(".two").NextFilteredUntil(".even", ".six")
|
||||||
AssertLength(t, sel.Nodes, 4)
|
AssertLength(t, sel.Nodes, 4)
|
||||||
AssertSelectionIs(t, sel, "#n3", "#n5", "#nf3", "#nf5")
|
AssertSelectionIs(t, sel, "#n3", "#n5", "#nf3", "#nf5")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextFilteredUntilRollback(t *testing.T) {
|
func TestNextFilteredUntilRollback(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".two")
|
sel := Doc2().Find(".two")
|
||||||
sel2 := sel.NextFilteredUntil(".even", ".six").End()
|
sel2 := sel.NextFilteredUntil(".even", ".six").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextFilteredUntilSelection(t *testing.T) {
|
func TestNextFilteredUntilSelection(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".even")
|
sel := Doc2().Find(".even")
|
||||||
sel2 := Doc2().Root.Find(".five")
|
sel2 := Doc2().Find(".five")
|
||||||
sel = sel.NextFilteredUntilSelection(".even", sel2)
|
sel = sel.NextFilteredUntilSelection(".even", sel2)
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
AssertSelectionIs(t, sel, "#n3", "#nf3")
|
AssertSelectionIs(t, sel, "#n3", "#nf3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextFilteredUntilSelectionRollback(t *testing.T) {
|
func TestNextFilteredUntilSelectionRollback(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".even")
|
sel := Doc2().Find(".even")
|
||||||
sel2 := Doc2().Root.Find(".five")
|
sel2 := Doc2().Find(".five")
|
||||||
sel3 := sel.NextFilteredUntilSelection(".even", sel2).End()
|
sel3 := sel.NextFilteredUntilSelection(".even", sel2).End()
|
||||||
AssertEqual(t, sel, sel3)
|
AssertEqual(t, sel, sel3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextFilteredUntilNodes(t *testing.T) {
|
func TestNextFilteredUntilNodes(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".even")
|
sel := Doc2().Find(".even")
|
||||||
sel2 := Doc2().Root.Find(".four")
|
sel2 := Doc2().Find(".four")
|
||||||
sel = sel.NextFilteredUntilNodes(".odd", sel2.Nodes...)
|
sel = sel.NextFilteredUntilNodes(".odd", sel2.Nodes...)
|
||||||
AssertLength(t, sel.Nodes, 4)
|
AssertLength(t, sel.Nodes, 4)
|
||||||
AssertSelectionIs(t, sel, "#n2", "#n6", "#nf2", "#nf6")
|
AssertSelectionIs(t, sel, "#n2", "#n6", "#nf2", "#nf6")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextFilteredUntilNodesRollback(t *testing.T) {
|
func TestNextFilteredUntilNodesRollback(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".even")
|
sel := Doc2().Find(".even")
|
||||||
sel2 := Doc2().Root.Find(".four")
|
sel2 := Doc2().Find(".four")
|
||||||
sel3 := sel.NextFilteredUntilNodes(".odd", sel2.Nodes...).End()
|
sel3 := sel.NextFilteredUntilNodes(".odd", sel2.Nodes...).End()
|
||||||
AssertEqual(t, sel, sel3)
|
AssertEqual(t, sel, sel3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevFilteredUntil(t *testing.T) {
|
func TestPrevFilteredUntil(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".five").PrevFilteredUntil(".odd", ".one")
|
sel := Doc2().Find(".five").PrevFilteredUntil(".odd", ".one")
|
||||||
AssertLength(t, sel.Nodes, 4)
|
AssertLength(t, sel.Nodes, 4)
|
||||||
AssertSelectionIs(t, sel, "#n4", "#n2", "#nf4", "#nf2")
|
AssertSelectionIs(t, sel, "#n4", "#n2", "#nf4", "#nf2")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevFilteredUntilRollback(t *testing.T) {
|
func TestPrevFilteredUntilRollback(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".four")
|
sel := Doc2().Find(".four")
|
||||||
sel2 := sel.PrevFilteredUntil(".odd", ".one").End()
|
sel2 := sel.PrevFilteredUntil(".odd", ".one").End()
|
||||||
AssertEqual(t, sel, sel2)
|
AssertEqual(t, sel, sel2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevFilteredUntilSelection(t *testing.T) {
|
func TestPrevFilteredUntilSelection(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".odd")
|
sel := Doc2().Find(".odd")
|
||||||
sel2 := Doc2().Root.Find(".two")
|
sel2 := Doc2().Find(".two")
|
||||||
sel = sel.PrevFilteredUntilSelection(".odd", sel2)
|
sel = sel.PrevFilteredUntilSelection(".odd", sel2)
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
AssertSelectionIs(t, sel, "#n4", "#nf4")
|
AssertSelectionIs(t, sel, "#n4", "#nf4")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevFilteredUntilSelectionRollback(t *testing.T) {
|
func TestPrevFilteredUntilSelectionRollback(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".even")
|
sel := Doc2().Find(".even")
|
||||||
sel2 := Doc2().Root.Find(".five")
|
sel2 := Doc2().Find(".five")
|
||||||
sel3 := sel.PrevFilteredUntilSelection(".even", sel2).End()
|
sel3 := sel.PrevFilteredUntilSelection(".even", sel2).End()
|
||||||
AssertEqual(t, sel, sel3)
|
AssertEqual(t, sel, sel3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevFilteredUntilNodes(t *testing.T) {
|
func TestPrevFilteredUntilNodes(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".even")
|
sel := Doc2().Find(".even")
|
||||||
sel2 := Doc2().Root.Find(".four")
|
sel2 := Doc2().Find(".four")
|
||||||
sel = sel.PrevFilteredUntilNodes(".odd", sel2.Nodes...)
|
sel = sel.PrevFilteredUntilNodes(".odd", sel2.Nodes...)
|
||||||
AssertLength(t, sel.Nodes, 2)
|
AssertLength(t, sel.Nodes, 2)
|
||||||
AssertSelectionIs(t, sel, "#n2", "#nf2")
|
AssertSelectionIs(t, sel, "#n2", "#nf2")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrevFilteredUntilNodesRollback(t *testing.T) {
|
func TestPrevFilteredUntilNodesRollback(t *testing.T) {
|
||||||
sel := Doc2().Root.Find(".even")
|
sel := Doc2().Find(".even")
|
||||||
sel2 := Doc2().Root.Find(".four")
|
sel2 := Doc2().Find(".four")
|
||||||
sel3 := sel.PrevFilteredUntilNodes(".odd", sel2.Nodes...).End()
|
sel3 := sel.PrevFilteredUntilNodes(".odd", sel2.Nodes...).End()
|
||||||
AssertEqual(t, sel, sel3)
|
AssertEqual(t, sel, sel3)
|
||||||
}
|
}
|
||||||
|
4
type.go
4
type.go
@@ -12,7 +12,7 @@ import (
|
|||||||
// to be told, and that's what the Document class is for. It holds the root
|
// to be told, and that's what the Document class is for. It holds the root
|
||||||
// document node to manipulate, and can make selections on this document.
|
// document node to manipulate, and can make selections on this document.
|
||||||
type Document struct {
|
type Document struct {
|
||||||
Root *Selection
|
*Selection
|
||||||
Url *url.URL
|
Url *url.URL
|
||||||
rootNode *html.Node
|
rootNode *html.Node
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ func NewDocument(url string) (d *Document, e error) {
|
|||||||
func newDocument(root *html.Node, url *url.URL) (d *Document) {
|
func newDocument(root *html.Node, url *url.URL) (d *Document) {
|
||||||
// Create and fill the document
|
// Create and fill the document
|
||||||
d = &Document{nil, url, root}
|
d = &Document{nil, url, root}
|
||||||
d.Root = newSingleSelection(root, d)
|
d.Selection = newSingleSelection(root, d)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user