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

Function TestStreamParser_Success1

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

Source from the content-addressed store, hash-verified

446}
447
448func TestStreamParser_Success1(t *testing.T) {
449 s := `
450 <ROOT>
451 <AAA>
452 <CCC>c1</CCC>
453 <BBB>b1</BBB>
454 <DDD>d1</DDD>
455 <BBB>b2<ZZZ z="1">z1</ZZZ></BBB>
456 <BBB>b3</BBB>
457 </AAA>
458 <ZZZ>
459 <BBB>b4</BBB>
460 <BBB>b5</BBB>
461 <CCC>c3</CCC>
462 </ZZZ>
463 </ROOT>`
464
465 sp, err := CreateStreamParser(strings.NewReader(s), "/ROOT/*/BBB", "/ROOT/*/BBB[. != 'b3']")
466 if err != nil {
467 t.Fatal(err.Error())
468 }
469
470 // First `<BBB>` read
471 n, err := sp.Read()
472 if err != nil {
473 t.Fatal(err.Error())
474 }
475 testOutputXML(t, "first call result", `<BBB>b1</BBB>`, n)
476 testOutputXML(t, "doc after first call",
477 `<?xml version="1.0"?><ROOT><AAA><CCC>c1</CCC><BBB>b1</BBB></AAA></ROOT>`, findRoot(n))
478
479 // Second `<BBB>` read
480 n, err = sp.Read()
481 if err != nil {
482 t.Fatal(err.Error())
483 }
484 testOutputXML(t, "second call result", `<BBB>b2<ZZZ z="1">z1</ZZZ></BBB>`, n)
485 testOutputXML(t, "doc after second call",
486 `<?xml version="1.0"?><ROOT><AAA><DDD>d1</DDD><BBB>b2<ZZZ z="1">z1</ZZZ></BBB></AAA></ROOT>`, findRoot(n))
487
488 // Third `<BBB>` read (Note we will skip 'b3' since the streamElementFilter excludes it)
489 n, err = sp.Read()
490 if err != nil {
491 t.Fatal(err.Error())
492 }
493 testOutputXML(t, "third call result", `<BBB>b4</BBB>`, n)
494 // Note the inclusion of `<BBB>b3</BBB>` in the document? This is because `<BBB>b3</BBB>` has
495 // been filtered out and is not our target node, thus it is considered just like any other
496 // non target nodes such as `<CCC>`` or `<DDD>`
497 testOutputXML(t, "doc after third call",
498 `<?xml version="1.0"?><ROOT><AAA></AAA><ZZZ><BBB>b4</BBB></ZZZ></ROOT>`,
499 findRoot(n))
500
501 // Fourth `<BBB>` read
502 n, err = sp.Read()
503 if err != nil {
504 t.Fatal(err.Error())
505 }

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…