Skip to content

Commit

Permalink
Merge pull request #3 from gochore/dev
Browse files Browse the repository at this point in the history
feat: support NewStringElement
  • Loading branch information
wolfogre authored Apr 8, 2020
2 parents 86d077e + e853030 commit f85e347
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ type Element interface {

type StringElement string

func NewStringElement(format string, a ...interface{}) StringElement {
return StringElement(fmt.Sprintf(format, a...))
}

func (e StringElement) Render(writer io.Writer, themes ...Theme) error {
return htmlRender(strings.NewReader(string(e)), writer, mergeThemes(themes))
}
Expand Down
29 changes: 29 additions & 0 deletions element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package emailt
import (
"bytes"
"testing"
"time"
)

func TestStringElement_Render(t *testing.T) {
Expand Down Expand Up @@ -118,3 +119,31 @@ func TestTemplateElement_Render(t *testing.T) {
})
}
}

func TestNewStringElement(t *testing.T) {
type args struct {
format string
a []interface{}
}
tests := []struct {
name string
args args
want StringElement
}{
{
name: "regular",
args: args{
format: "%v %v",
a: []interface{}{1, time.Minute},
},
want: "1 1m0s",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewStringElement(tt.args.format, tt.args.a...); got != tt.want {
t.Errorf("NewStringElement() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit f85e347

Please sign in to comment.