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

Function TestLineNumbers

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

Source from the content-addressed store, hash-verified

667}
668
669func TestLineNumbers(t *testing.T) {
670 s := `<?xml version="1.0" encoding="UTF-8"?>
671<bookstore>
672<book id="1"
673 category="fiction"
674 available="true">
675 <title lang="en">Harry Potter</title>
676 <price>29.99</price>
677</book>
678</bookstore>`
679
680 doc, err := ParseWithOptions(strings.NewReader(s), ParserOptions{WithLineNumbers: true})
681 if err != nil {
682 t.Fatal(err)
683 }
684
685 // Test XML declaration line number
686 declaration := doc.FirstChild
687 if declaration.Type != DeclarationNode {
688 t.Fatal("first child should be declaration node")
689 }
690 if declaration.LineNumber != 1 {
691 t.Errorf("declaration should be on line 1, got line %d", declaration.LineNumber)
692 }
693
694 // Test root element line number
695 bookstore := doc.LastChild
696 if bookstore.Data != "bookstore" {
697 t.Fatal("root element should be bookstore")
698 }
699 if bookstore.LineNumber != 2 {
700 t.Errorf("bookstore should be on line 2, got line %d", bookstore.LineNumber)
701 }
702
703 // Test book element with multi-line attributes
704 book := FindOne(doc, "//book")
705 if book == nil {
706 t.Fatal("book element not found")
707 }
708 if book.LineNumber != 3 {
709 t.Errorf("book element should be on line 3, got line %d", book.LineNumber)
710 }
711
712 // Verify attributes are present
713 if len(book.Attr) != 3 {
714 t.Errorf("expected 3 attributes, got %d", len(book.Attr))
715 }
716
717 // Test title element
718 title := FindOne(book, "title")
719 if title == nil {
720 t.Fatal("title element not found")
721 }
722 if title.LineNumber != 6 {
723 t.Errorf("title should be on line 6, got line %d", title.LineNumber)
724 }
725}
726

Callers

nothing calls this directly

Calls 2

ParseWithOptionsFunction · 0.85
FindOneFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…