(t *testing.T)
| 45 | var doc = loadXML(xmlDoc) |
| 46 | |
| 47 | func TestXPath(t *testing.T) { |
| 48 | if list := Find(doc, "//book"); len(list) != 3 { |
| 49 | t.Fatal("count(//book) != 3") |
| 50 | } |
| 51 | if node := FindOne(doc, "//book[@id='bk101']"); node == nil { |
| 52 | t.Fatal("//book[@id='bk101] is not found") |
| 53 | } |
| 54 | if node := FindOne(doc, "//book[price>=44.95]"); node == nil { |
| 55 | t.Fatal("//book/price>=44.95 is not found") |
| 56 | } |
| 57 | if list := Find(doc, "//book[genre='Fantasy']"); len(list) != 2 { |
| 58 | t.Fatal("//book[genre='Fantasy'] items count is not equal 2") |
| 59 | } |
| 60 | var c int |
| 61 | FindEach(doc, "//book", func(i int, n *Node) { |
| 62 | c++ |
| 63 | }) |
| 64 | l := len(Find(doc, "//book")) |
| 65 | if c != l { |
| 66 | t.Fatal("count(//book) != 3") |
| 67 | } |
| 68 | c = 0 |
| 69 | FindEachWithBreak(doc, "//book", func(i int, n *Node) bool { |
| 70 | if c == l-1 { |
| 71 | return false |
| 72 | } |
| 73 | c++ |
| 74 | return true |
| 75 | }) |
| 76 | if c != l-1 { |
| 77 | t.Fatal("FindEachWithBreak failed to stop.") |
| 78 | } |
| 79 | node := FindOne(doc, "//book[1]") |
| 80 | if node.SelectAttr("id") != "bk101" { |
| 81 | t.Fatal("//book[1]/@id != bk101") |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | func TestXPathCdUp(t *testing.T) { |
| 86 | doc := loadXML(`<a><b attr="1"/></a>`) |
nothing calls this directly
no test coverage detected
searching dependent graphs…