1
0
mirror of https://github.com/danog/liquid.git synced 2024-12-02 21:27:48 +01:00
liquid/render/compiler_test.go

35 lines
865 B
Go
Raw Normal View History

2017-07-06 14:59:10 +02:00
package render
import (
"fmt"
"io"
"testing"
"github.com/stretchr/testify/require"
)
func addCompilerTestTags(s Config) {
2017-07-06 15:38:18 +02:00
s.AddBlock("block").Compiler(func(c BlockNode) (func(io.Writer, Context) error, error) {
2017-07-06 14:59:10 +02:00
return nil, fmt.Errorf("block compiler error")
})
}
var compilerErrorTests = []struct{ in, expected string }{
2017-07-06 15:35:12 +02:00
{"{% unknown_tag %}", "unknown tag"},
2017-07-06 14:59:10 +02:00
{`{% block %}{% endblock %}`, "block compiler error"},
2017-07-06 15:35:12 +02:00
// {`{% tag %}`, "tag compiler error"},
2017-07-06 14:59:10 +02:00
// {"{%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)
})
}
}