package docxlib import ( "encoding/xml" "testing" ) const decoded_doc_1 = `testtest font sizetest colorNew style 1New style 2test font size and colorgoogle` const decoded_doc_2 = `Table of Contents TOC \h \z \t "Heading 1,2,S6,1,S0,1,S1,1,S2,1,S3,1,S4,1,S5,1" Holy Grail [xref:bRJduW6hNR] PAGEREF _Toc420414504 \h 21.What is your name? [xref:TH7u7QDqhD] PAGEREF _Toc420414505 \h 22.What is your quest? [xref:bC62HkFATC] PAGEREF _Toc420414506 \h 23.What is your favourite colour? [xref:I3TphuHX6N] PAGEREF _Toc420414507 \h 2Holy Grail [ FORMTEXT xref:bRJduW6hNR]What is your name? [ FORMTEXT xref:TH7u7QDqhD]My name is Sir Launcelot of Camelot.What is your quest? [ FORMTEXT xref:bC62HkFATC]To seek the Holy Grail[or a grail shaped beacon]. What is your favourite colour? [ FORMTEXT xref:I3TphuHX6N]Blue.How many paragraphs here then?` func TestUnmarshalPlainStructure(t *testing.T) { testCases := []struct { content string numParagraphs int }{ {decoded_doc_1, 5}, {decoded_doc_2, 14}, } for _, tc := range testCases { doc := Document{ XMLW: XMLNS_W, XMLR: XMLNS_R, XMLWP: XMLNS_WP, XMLName: xml.Name{Space: XMLNS_W, Local: "document"}} err := xml.Unmarshal(StringToBytes(tc.content), &doc) if err != nil { t.Fatal(err) } if len(doc.Body.Paragraphs) != tc.numParagraphs { t.Fatalf("We expected %d paragraphs, we got %d", tc.numParagraphs, len(doc.Body.Paragraphs)) } for i, p := range doc.Body.Paragraphs { if len(p.Children) == 0 { t.Fatalf("We were not able to parse paragraph %d", i) } for _, child := range p.Children { if child == nil { t.Fatalf("There are Paragraph children with all fields nil") } if o, ok := child.(*Hyperlink); ok && o.ID == "" { t.Fatalf("We have a link without ID") } } } } }