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

Function TestCharData

parse_test.go:397–422  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

395}
396
397func TestCharData(t *testing.T) {
398 s := `
399<?xml version="1.0"?>
400<rss version="2.0" xmlns="http://www.example.com/" xmlns:dc="https://purl.org/dc/elements/1.1/">
401<dc:creator><![CDATA[Richard Lawler]]></dc:creator>
402</rss>
403 `
404 doc, err := Parse(strings.NewReader(s))
405 if err != nil {
406 t.Fatal(err)
407 }
408 top := FindOne(doc, "//rss")
409 if top == nil {
410 t.Fatal("rss feed invalid")
411 }
412 node := FindOne(top, "dc:creator")
413 if node.Prefix != "dc" {
414 t.Fatalf("expected node prefix name is dc but is=%s", node.Prefix)
415 }
416 cdata := node.FirstChild
417 if cdata == nil || cdata.Type != CharDataNode {
418 t.Fatalf("expected cdata child, received %d", cdata.Type)
419 }
420
421 testValue(t, cdata.InnerText(), "Richard Lawler")
422}
423
424func TestStreamParser_InvalidXPath(t *testing.T) {
425 sp, err := CreateStreamParser(strings.NewReader(""), "[invalid")

Callers

nothing calls this directly

Calls 4

ParseFunction · 0.85
FindOneFunction · 0.85
testValueFunction · 0.85
InnerTextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…