add Add() and AndSelf(), with tests

This commit is contained in:
Martin Angers
2012-08-31 10:27:45 -04:00
parent 7a69490818
commit f1e54e5311
7 changed files with 135 additions and 59 deletions

View File

@@ -5,18 +5,53 @@ import (
)
func TestAdd(t *testing.T) {
var cnt int
EnsureDocLoaded()
sel := Doc().Find("div.row-fluid")
cnt = len(sel.Nodes)
sel2 := sel.Add("a")
if sel != sel2 {
t.Error("Expected returned Selection from Add() to be same as 'this'.")
sel := Doc().Find("div.row-fluid").Add("a")
if len(sel.Nodes) != 19 {
t.Errorf("Expected 19 nodes, found %v.", len(sel.Nodes))
}
}
func TestAddSelection(t *testing.T) {
sel := Doc().Find("div.row-fluid")
sel2 := Doc().Find("a")
sel = sel.AddSelection(sel2)
if len(sel.Nodes) != 19 {
t.Errorf("Expected 19 nodes, found %v.", len(sel.Nodes))
}
}
func TestAddSelectionNil(t *testing.T) {
sel := Doc().Find("div.row-fluid")
if len(sel.Nodes) != 9 {
t.Errorf("Expected div.row-fluid to have 9 nodes, found %v.",
len(sel.Nodes))
}
sel = sel.AddSelection(nil)
if len(sel.Nodes) != 9 {
t.Errorf("Expected add nil to keep it to 9 nodes, found %v.",
len(sel.Nodes))
}
}
func TestAddNodes(t *testing.T) {
sel := Doc().Find("div.pvk-gutter")
sel2 := Doc().Find(".pvk-content")
sel = sel.AddNodes(sel2.Nodes...)
if len(sel.Nodes) != 9 {
t.Errorf("Expected 9 nodes, found %v.", len(sel.Nodes))
}
}
func TestAddNodesNone(t *testing.T) {
sel := Doc().Find("div.pvk-gutter").AddNodes()
if len(sel.Nodes) != 6 {
t.Errorf("Expected 6 nodes, found %v.", len(sel.Nodes))
}
}
func TestAndSelf(t *testing.T) {
sel := Doc().Find(".span12").Last().AndSelf()
if len(sel.Nodes) != 2 {
t.Errorf("Expected 2 nodes, found %v.", len(sel.Nodes))
}
if len(sel.Nodes) <= cnt {
t.Error("Expected nodes to be added to Selection.")
}
t.Logf("%v nodes after div.row-fluid and a were added.", len(sel.Nodes))
}