MCPcopy Create free account
hub / github.com/antchfx/xmlquery / TestSelectElement

Function TestSelectElement

node_test.go:379–413  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

377}
378
379func TestSelectElement(t *testing.T) {
380 s := `<?xml version="1.0" encoding="UTF-8"?>
381 <AAA>
382 <BBB id="1"/>
383 <CCC id="2">
384 <DDD/>
385 </CCC>
386 <CCC id="3">
387 <DDD/>
388 </CCC>
389 </AAA>`
390 root, err := Parse(strings.NewReader(s))
391 if err != nil {
392 t.Error(err)
393 }
394 version := root.FirstChild.SelectAttr("version")
395 if version != "1.0" {
396 t.Fatal("version!=1.0")
397 }
398 aaa := findNode(root, "AAA")
399 var n *Node
400 n = aaa.SelectElement("BBB")
401 if n == nil {
402 t.Fatalf("n is nil")
403 }
404 n = aaa.SelectElement("CCC")
405 if n == nil {
406 t.Fatalf("n is nil")
407 }
408
409 ns := aaa.SelectElements("CCC")
410 if len(ns) != 2 {
411 t.Fatalf("len(ns)!=2")
412 }
413}
414
415func TestEscapeOutputValue(t *testing.T) {
416 data := `<AAA>&lt;*&gt;</AAA>`

Callers

nothing calls this directly

Calls 5

ParseFunction · 0.85
findNodeFunction · 0.85
SelectAttrMethod · 0.80
SelectElementMethod · 0.80
SelectElementsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…