...
1 package goquery
2
3 import (
4 "testing"
5 )
6
7 func TestIs(t *testing.T) {
8 sel := Doc().Find(".footer p:nth-child(1)")
9 if !sel.Is("p") {
10 t.Error("Expected .footer p:nth-child(1) to be p.")
11 }
12 }
13
14 func TestIsInvalid(t *testing.T) {
15 sel := Doc().Find(".footer p:nth-child(1)")
16 if sel.Is("") {
17 t.Error("Is should not succeed with invalid selector string")
18 }
19 }
20
21 func TestIsPositional(t *testing.T) {
22 sel := Doc().Find(".footer p:nth-child(2)")
23 if !sel.Is("p:nth-child(2)") {
24 t.Error("Expected .footer p:nth-child(2) to be p:nth-child(2).")
25 }
26 }
27
28 func TestIsPositionalNot(t *testing.T) {
29 sel := Doc().Find(".footer p:nth-child(1)")
30 if sel.Is("p:nth-child(2)") {
31 t.Error("Expected .footer p:nth-child(1) NOT to be p:nth-child(2).")
32 }
33 }
34
35 func TestIsFunction(t *testing.T) {
36 ok := Doc().Find("div").IsFunction(func(i int, s *Selection) bool {
37 return s.HasClass("container-fluid")
38 })
39
40 if !ok {
41 t.Error("Expected some div to have a container-fluid class.")
42 }
43 }
44
45 func TestIsFunctionRollback(t *testing.T) {
46 ok := Doc().Find("div").IsFunction(func(i int, s *Selection) bool {
47 return s.HasClass("container-fluid")
48 })
49
50 if !ok {
51 t.Error("Expected some div to have a container-fluid class.")
52 }
53 }
54
55 func TestIsSelection(t *testing.T) {
56 sel := Doc().Find("div")
57 sel2 := Doc().Find(".pvk-gutter")
58
59 if !sel.IsSelection(sel2) {
60 t.Error("Expected some div to have a pvk-gutter class.")
61 }
62 }
63
64 func TestIsSelectionNot(t *testing.T) {
65 sel := Doc().Find("div")
66 sel2 := Doc().Find("a")
67
68 if sel.IsSelection(sel2) {
69 t.Error("Expected some div NOT to be an anchor.")
70 }
71 }
72
73 func TestIsNodes(t *testing.T) {
74 sel := Doc().Find("div")
75 sel2 := Doc().Find(".footer")
76
77 if !sel.IsNodes(sel2.Nodes[0]) {
78 t.Error("Expected some div to have a footer class.")
79 }
80 }
81
82 func TestDocContains(t *testing.T) {
83 sel := Doc().Find("h1")
84 if !Doc().Contains(sel.Nodes[0]) {
85 t.Error("Expected document to contain H1 tag.")
86 }
87 }
88
89 func TestSelContains(t *testing.T) {
90 sel := Doc().Find(".row-fluid")
91 sel2 := Doc().Find("a[ng-click]")
92 if !sel.Contains(sel2.Nodes[0]) {
93 t.Error("Expected .row-fluid to contain a[ng-click] tag.")
94 }
95 }
96
97 func TestSelNotContains(t *testing.T) {
98 sel := Doc().Find("a.link")
99 sel2 := Doc().Find("span")
100 if sel.Contains(sel2.Nodes[0]) {
101 t.Error("Expected a.link to NOT contain span tag.")
102 }
103 }
104
View as plain text