template_test.go 755 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package template
  2. import (
  3. "strings"
  4. "testing"
  5. "text/template"
  6. "github.com/remogatto/prettytest"
  7. )
  8. var funcMap = template.FuncMap{
  9. "toUpper": toUpper,
  10. }
  11. type testSuite struct {
  12. prettytest.Suite
  13. }
  14. func toUpper(s string) string {
  15. return strings.ToUpper(s)
  16. }
  17. func TestRunner(t *testing.T) {
  18. prettytest.Run(
  19. t,
  20. new(testSuite),
  21. )
  22. }
  23. func (t *testSuite) TestLoadTXTTemplate() {
  24. tpl, err := LoadTextTemplate("testdata/test.tpl")
  25. t.Nil(err)
  26. t.Not(t.Nil(tpl))
  27. }
  28. func (t *testSuite) TestLoadTXTTemplateWithFuncs() {
  29. tpl, err := LoadTextTemplate("testdata/test.tpl", funcMap)
  30. t.Nil(err)
  31. t.Not(t.Nil(tpl))
  32. }
  33. func (t *testSuite) TestLoadTemplateFromString() {
  34. tpl, err := LoadTextTemplateFromString("{{.}}")
  35. t.Nil(err)
  36. t.Not(t.Nil(tpl))
  37. }