Skip to content

Commit

Permalink
document: add Clear method to Run
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaliance committed Oct 10, 2017
1 parent acb6173 commit c38bb81
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions document/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func (r Run) newIC() *wml.EG_RunInnerContent {
return ic
}

// Clear removes all of the content from within a run.
func (r Run) Clear() {
r.x.EG_RunInnerContent = nil
}

// AddTab adds tab to a run and can be used with the the Paragraph's tab stops.
func (r Run) AddTab() {
ic := r.newIC()
Expand Down
37 changes: 37 additions & 0 deletions document/run_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2017 Baliance. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased by contacting [email protected].

package document_test

import (
"testing"

"baliance.com/gooxml/document"
)

func TestRunClear(t *testing.T) {
doc := document.New()
para := doc.AddParagraph()
run := para.AddRun()
if len(run.X().EG_RunInnerContent) != 0 {
t.Errorf("expected inner content of length zero, had %d", len(run.X().EG_RunInnerContent))
}
for i := 0; i < 5; i++ {
if i%2 == 0 {
run.AddText("test")
} else {
run.AddTab()
}
if len(run.X().EG_RunInnerContent) != i+1 {
t.Errorf("expected inner content of length %d, had %d", i+1, len(run.X().EG_RunInnerContent))
}
}
run.Clear()
if len(run.X().EG_RunInnerContent) != 0 {
t.Errorf("expected inner content of length zero, had %d", len(run.X().EG_RunInnerContent))
}
}

0 comments on commit c38bb81

Please sign in to comment.