46 lines
755 B
Go
46 lines
755 B
Go
package template
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"text/template"
|
|
|
|
"github.com/remogatto/prettytest"
|
|
)
|
|
|
|
var funcMap = template.FuncMap{
|
|
"toUpper": toUpper,
|
|
}
|
|
|
|
type testSuite struct {
|
|
prettytest.Suite
|
|
}
|
|
|
|
func toUpper(s string) string {
|
|
return strings.ToUpper(s)
|
|
}
|
|
|
|
func TestRunner(t *testing.T) {
|
|
prettytest.Run(
|
|
t,
|
|
new(testSuite),
|
|
)
|
|
}
|
|
|
|
func (t *testSuite) TestLoadTXTTemplate() {
|
|
tpl, err := LoadTextTemplate("testdata/test.tpl")
|
|
t.Nil(err)
|
|
t.Not(t.Nil(tpl))
|
|
}
|
|
|
|
func (t *testSuite) TestLoadTXTTemplateWithFuncs() {
|
|
tpl, err := LoadTextTemplate("testdata/test.tpl", funcMap)
|
|
t.Nil(err)
|
|
t.Not(t.Nil(tpl))
|
|
}
|
|
|
|
func (t *testSuite) TestLoadTemplateFromString() {
|
|
tpl, err := LoadTextTemplateFromString("{{.}}")
|
|
t.Nil(err)
|
|
t.Not(t.Nil(tpl))
|
|
}
|