Reworked the tests just a bit
This commit is contained in:
parent
ecf8264ac7
commit
72c0afcf93
31
xmlx_test.go
31
xmlx_test.go
|
@ -28,10 +28,9 @@ func TestWildcard(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
list := doc.SelectNodesRecursive("ns", "*")
|
||||
|
||||
if len(list) != 7 {
|
||||
t.Errorf("Wrong number of child elements. Expected 7, got %d.", len(list))
|
||||
list := doc.SelectNode("", "xml").SelectNodes("ns", "*")
|
||||
if len(list) != 1 {
|
||||
t.Errorf("Wrong number of child elements. Expected 1, got %d.", len(list))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -99,27 +98,19 @@ func TestNodeSearch(t *testing.T) {
|
|||
t.Errorf("SelectNodes(): no nodes found.")
|
||||
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")
|
||||
|
||||
topLevelLinks := ch.SelectNodes("", "link")
|
||||
if len(topLevelLinks) != 1 {
|
||||
t.Errorf("SelectNodes(): Expected 1, Got %d", len(topLevelLinks))
|
||||
// Test that SelectNodes doesn't accidentally do recursive
|
||||
links := ch.SelectNodes("", "link")
|
||||
if len(links) != 1 {
|
||||
t.Errorf("SelectNodes(): Expected 1, Got %d", len(links))
|
||||
return
|
||||
}
|
||||
|
||||
allLinks := ch.SelectNodesRecursive("", "link")
|
||||
if len(allLinks) != 8 {
|
||||
t.Errorf("SelectNodes(): Expected 8, Got %d", len(allLinks))
|
||||
// Test SelectNodesRecursive does indeed get all of them
|
||||
links = ch.SelectNodesRecursive("", "link")
|
||||
if len(links) != 8 {
|
||||
t.Errorf("SelectNodesRecursive(): Expected 8, Got %d", len(links))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue