Reworked the tests just a bit

This commit is contained in:
Shaun Duncan 2013-10-25 17:31:10 -04:00
parent ecf8264ac7
commit 72c0afcf93
1 changed files with 11 additions and 20 deletions

View File

@ -28,10 +28,9 @@ func TestWildcard(t *testing.T) {
return return
} }
list := doc.SelectNodesRecursive("ns", "*") list := doc.SelectNode("", "xml").SelectNodes("ns", "*")
if len(list) != 1 {
if len(list) != 7 { t.Errorf("Wrong number of child elements. Expected 1, got %d.", len(list))
t.Errorf("Wrong number of child elements. Expected 7, got %d.", len(list))
return return
} }
} }
@ -99,27 +98,19 @@ func TestNodeSearch(t *testing.T) {
t.Errorf("SelectNodes(): no nodes found.") t.Errorf("SelectNodes(): no nodes found.")
return return
} }
}
func TestSelectNodes(t *testing.T) {
doc := New()
if err := doc.LoadFile("test1.xml", nil); err != nil {
t.Errorf("LoadFile(): %s", err)
return
}
ch := doc.SelectNode("", "channel") ch := doc.SelectNode("", "channel")
// Test that SelectNodes doesn't accidentally do recursive
topLevelLinks := ch.SelectNodes("", "link") links := ch.SelectNodes("", "link")
if len(topLevelLinks) != 1 { if len(links) != 1 {
t.Errorf("SelectNodes(): Expected 1, Got %d", len(topLevelLinks)) t.Errorf("SelectNodes(): Expected 1, Got %d", len(links))
return return
} }
allLinks := ch.SelectNodesRecursive("", "link") // Test SelectNodesRecursive does indeed get all of them
if len(allLinks) != 8 { links = ch.SelectNodesRecursive("", "link")
t.Errorf("SelectNodes(): Expected 8, Got %d", len(allLinks)) if len(links) != 8 {
t.Errorf("SelectNodesRecursive(): Expected 8, Got %d", len(links))
return return
} }
} }