1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-27 10:44:38 +01:00
liquid/render/compiler_test.go
2017-07-06 09:35:12 -04:00

35 lines
863 B
Go

package render
import (
"fmt"
"io"
"testing"
"github.com/stretchr/testify/require"
)
func addCompilerTestTags(s Config) {
s.AddBlock("block").Parser(func(c BlockNode) (func(io.Writer, Context) error, error) {
return nil, fmt.Errorf("block compiler error")
})
}
var compilerErrorTests = []struct{ in, expected string }{
{"{% unknown_tag %}", "unknown tag"},
{`{% block %}{% endblock %}`, "block compiler error"},
// {`{% tag %}`, "tag compiler error"},
// {"{%for syntax error%}{%endfor%}", "parse error"},
}
func TestCompileErrors(t *testing.T) {
settings := NewConfig()
addCompilerTestTags(settings)
for i, test := range compilerErrorTests {
t.Run(fmt.Sprintf("%02d", i+1), func(t *testing.T) {
_, err := settings.Compile(test.in)
require.Errorf(t, err, test.in)
require.Containsf(t, err.Error(), test.expected, test.in)
})
}
}