aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/PuerkitoBio/goquery/query_test.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2017-11-19 21:10:04 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2017-11-19 22:01:46 -0800
commit8ffb773f43c8dc54801ca1d111854e7e881c93c9 (patch)
tree38133a2fc612597a75fed1d13e5b4042f58a2b7e /vendor/github.com/PuerkitoBio/goquery/query_test.go
First commit
Diffstat (limited to 'vendor/github.com/PuerkitoBio/goquery/query_test.go')
-rw-r--r--vendor/github.com/PuerkitoBio/goquery/query_test.go103
1 files changed, 103 insertions, 0 deletions
diff --git a/vendor/github.com/PuerkitoBio/goquery/query_test.go b/vendor/github.com/PuerkitoBio/goquery/query_test.go
new file mode 100644
index 0000000..54b2a2e
--- /dev/null
+++ b/vendor/github.com/PuerkitoBio/goquery/query_test.go
@@ -0,0 +1,103 @@
+package goquery
+
+import (
+ "testing"
+)
+
+func TestIs(t *testing.T) {
+ sel := Doc().Find(".footer p:nth-child(1)")
+ if !sel.Is("p") {
+ t.Error("Expected .footer p:nth-child(1) to be p.")
+ }
+}
+
+func TestIsInvalid(t *testing.T) {
+ sel := Doc().Find(".footer p:nth-child(1)")
+ if sel.Is("") {
+ t.Error("Is should not succeed with invalid selector string")
+ }
+}
+
+func TestIsPositional(t *testing.T) {
+ sel := Doc().Find(".footer 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).")
+ }
+}
+
+func TestIsPositionalNot(t *testing.T) {
+ sel := Doc().Find(".footer p:nth-child(1)")
+ if sel.Is("p:nth-child(2)") {
+ t.Error("Expected .footer p:nth-child(1) NOT to be p:nth-child(2).")
+ }
+}
+
+func TestIsFunction(t *testing.T) {
+ ok := Doc().Find("div").IsFunction(func(i int, s *Selection) bool {
+ return s.HasClass("container-fluid")
+ })
+
+ if !ok {
+ t.Error("Expected some div to have a container-fluid class.")
+ }
+}
+
+func TestIsFunctionRollback(t *testing.T) {
+ ok := Doc().Find("div").IsFunction(func(i int, s *Selection) bool {
+ return s.HasClass("container-fluid")
+ })
+
+ if !ok {
+ t.Error("Expected some div to have a container-fluid class.")
+ }
+}
+
+func TestIsSelection(t *testing.T) {
+ sel := Doc().Find("div")
+ sel2 := Doc().Find(".pvk-gutter")
+
+ if !sel.IsSelection(sel2) {
+ t.Error("Expected some div to have a pvk-gutter class.")
+ }
+}
+
+func TestIsSelectionNot(t *testing.T) {
+ sel := Doc().Find("div")
+ sel2 := Doc().Find("a")
+
+ if sel.IsSelection(sel2) {
+ t.Error("Expected some div NOT to be an anchor.")
+ }
+}
+
+func TestIsNodes(t *testing.T) {
+ sel := Doc().Find("div")
+ sel2 := Doc().Find(".footer")
+
+ if !sel.IsNodes(sel2.Nodes[0]) {
+ t.Error("Expected some div to have a footer class.")
+ }
+}
+
+func TestDocContains(t *testing.T) {
+ sel := Doc().Find("h1")
+ if !Doc().Contains(sel.Nodes[0]) {
+ t.Error("Expected document to contain H1 tag.")
+ }
+}
+
+func TestSelContains(t *testing.T) {
+ sel := Doc().Find(".row-fluid")
+ sel2 := Doc().Find("a[ng-click]")
+ if !sel.Contains(sel2.Nodes[0]) {
+ t.Error("Expected .row-fluid to contain a[ng-click] tag.")
+ }
+}
+
+func TestSelNotContains(t *testing.T) {
+ sel := Doc().Find("a.link")
+ sel2 := Doc().Find("span")
+ if sel.Contains(sel2.Nodes[0]) {
+ t.Error("Expected a.link to NOT contain span tag.")
+ }
+}