package docxlib import ( "encoding/xml" "testing" ) const decoded_doc = `testtest font sizetest colorNew style 1New style 2test font size and colorgoogle` const NUM_PARAGRAPHS = 5 func TestStructure(t *testing.T) { doc := Document{ XMLW: XMLNS_W, XMLR: XMLNS_R, XMLName: xml.Name{Space: XMLNS_W, Local: "document"}} err := xml.Unmarshal([]byte(decoded_doc), &doc) if err != nil { t.Errorf("We expected to be able to decode %s but we didn't", decoded_doc) } if len(doc.Body.Paragraphs) != NUM_PARAGRAPHS { t.Errorf("We expected %d paragraphs, we got %d", NUM_PARAGRAPHS, len(doc.Body.Paragraphs)) } for _, p := range doc.Body.Paragraphs { if len(p.Children()) == 0 { t.Errorf("We were not able to parse paragraph %v", p) } for _, child := range p.Children() { if child.Link == nil && child.Properties == nil && child.Run == nil { t.Errorf("There are children with all fields nil") } if child.Run != nil && child.Run.Text == nil { t.Errorf("We have a run with no text") } } } }