1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-27 03:34:44 +01:00
liquid/template_test.go
2017-07-04 16:48:38 -04:00

31 lines
803 B
Go

package liquid
import (
"testing"
"github.com/osteele/liquid/render"
"github.com/stretchr/testify/require"
)
func TestTemplate_RenderString(t *testing.T) {
engine := NewEngine()
tpl, err := engine.ParseTemplate([]byte(`{{ "hello world" | capitalize }}`))
require.NoError(t, err)
out, err := tpl.RenderString(testBindings)
require.NoError(t, err)
require.Equal(t, "Hello world", out)
}
func TestTemplate_SetSourcePath(t *testing.T) {
engine := NewEngine()
engine.RegisterTag("sourcepath", func(c render.Context) (string, error) {
return c.SourceFile(), nil
})
tpl, err := engine.ParseTemplate([]byte(`{% sourcepath %}`))
require.NoError(t, err)
tpl.SetSourcePath("source.md")
out, err := tpl.RenderString(testBindings)
require.NoError(t, err)
require.Equal(t, "source.md", out)
}