MCPcopy Create free account
hub / github.com/antchfx/xpath / TestNamespacePrefixQuery

Function TestNamespacePrefixQuery

xpath_test.go:197–229  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

195}
196
197func TestNamespacePrefixQuery(t *testing.T) {
198 /*
199 <?xml version="1.0" encoding="UTF-8"?>
200 <books>
201 <book>book1</book>
202 <b:book xmlns:b="ns">book2</b:book>
203 <c:book xmlns:c="ns">book3</c:book>
204 </books>
205 */
206 doc := createNode("", RootNode)
207 books := doc.createChildNode("books", ElementNode)
208 books.lines = 2
209 book1 := books.createChildNode("book", ElementNode)
210 book1.lines = 3
211 book1.createChildNode("book1", TextNode)
212 book2 := books.createChildNode("b:book", ElementNode)
213 book2.lines = 4
214 book2.addAttribute("xmlns:b", "ns")
215 book2.createChildNode("book2", TextNode)
216 book3 := books.createChildNode("c:book", ElementNode)
217 book3.lines = 5
218 book3.addAttribute("xmlns:c", "ns")
219 book3.createChildNode("book3", TextNode)
220
221 test_xpath_elements(t, doc, `//b:book`, 4) // expected [4 , 5]
222
223 // With namespace bindings:
224 exp, _ := CompileWithNS("//x:book", map[string]string{"x": "ns"})
225 nodes := iterateNodes(exp.Select(createNavigator(doc)))
226 assertEqual(t, 2, len(nodes))
227 assertEqual(t, "book2", nodes[0].Value())
228 assertEqual(t, "book3", nodes[1].Value())
229}
230
231func TestMustCompile(t *testing.T) {
232 expr := MustCompile("//")

Callers

nothing calls this directly

Calls 10

createNodeFunction · 0.85
test_xpath_elementsFunction · 0.85
CompileWithNSFunction · 0.85
iterateNodesFunction · 0.85
createNavigatorFunction · 0.85
assertEqualFunction · 0.85
createChildNodeMethod · 0.80
addAttributeMethod · 0.80
SelectMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…