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

Function TestStreamParser_Success2

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

Source from the content-addressed store, hash-verified

515}
516
517func TestStreamParser_Success2(t *testing.T) {
518 s := `
519 <AAA>
520 <CCC>c1</CCC>
521 <BBB>b1</BBB>
522 <DDD>d1</DDD>
523 <BBB>b2</BBB>
524 <CCC>c2</CCC>
525 </AAA>`
526
527 sp, err := CreateStreamParser(strings.NewReader(s), "/AAA/CCC | /AAA/DDD")
528 if err != nil {
529 t.Fatal(err.Error())
530 }
531
532 // First Read() should return c1
533 n, err := sp.Read()
534 if err != nil {
535 t.Fatal(err.Error())
536 }
537 testOutputXML(t, "first call result", `<CCC>c1</CCC>`, n)
538 testOutputXML(t, "doc after first call", `<?xml version="1.0"?><AAA><CCC>c1</CCC></AAA>`, findRoot(n))
539
540 // Second Read() should return d1
541 n, err = sp.Read()
542 if err != nil {
543 t.Fatal(err.Error())
544 }
545 testOutputXML(t, "second call result", `<DDD>d1</DDD>`, n)
546 testOutputXML(t, "doc after second call",
547 `<?xml version="1.0"?><AAA><BBB>b1</BBB><DDD>d1</DDD></AAA>`, findRoot(n))
548
549 // Third call should return c2
550 n, err = sp.Read()
551 if err != nil {
552 t.Fatal(err.Error())
553 }
554 testOutputXML(t, "third call result", `<CCC>c2</CCC>`, n)
555 testOutputXML(t, "doc after third call",
556 `<?xml version="1.0"?><AAA><BBB>b2</BBB><CCC>c2</CCC></AAA>`, findRoot(n))
557
558 _, err = sp.Read()
559 if err != io.EOF {
560 t.Fatalf("io.EOF expected, but got %v", err)
561 }
562}
563
564func TestCDATA(t *testing.T) {
565 s := `

Callers

nothing calls this directly

Calls 4

CreateStreamParserFunction · 0.85
testOutputXMLFunction · 0.85
findRootFunction · 0.85
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…