1
0
mirror of https://github.com/danog/liquid.git synced 2025-01-23 02:01:11 +01:00
liquid/chunks/parser_test.go
Oliver Steele af95c44a25 simplify
2017-06-30 16:51:39 -04:00

56 lines
1.5 KiB
Go

package chunks
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func addTestTags(s Settings) {
s.AddStartTag("case").Branch("when")
s.AddStartTag("comment")
s.AddStartTag("for").Governs([]string{"break"})
s.AddStartTag("if").Branch("else").Branch("elsif")
s.AddStartTag("raw")
}
var parseErrorTests = []struct{ in, expected string }{
{"{%unknown_tag%}", "unknown tag"},
{"{%if test%}", "unterminated if tag"},
// {"{%for syntax error%}{%endfor%}", "parse error"},
}
var parserTests = []struct{ in string }{
{`{% for item in list %}{% endfor %}`},
{`{% if test %}{% else %}{% endif %}`},
{`{% if test %}{% if test %}{% endif %}{% endif %}`},
{`{% for item in list %}{% if test %}{% else %}{% endif x %}{% endfor %}`},
{`{% if true %}{% raw %}{% endraw %}{% endif %}`},
}
func TestParseErrors(t *testing.T) {
settings := NewSettings()
addTestTags(settings)
for i, test := range parseErrorTests {
t.Run(fmt.Sprintf("%02d", i+1), func(t *testing.T) {
ast, err := settings.Parse(test.in)
require.Nilf(t, ast, test.in)
require.Errorf(t, err, test.in)
require.Containsf(t, err.Error(), test.expected, test.in)
})
}
}
func TestParser(t *testing.T) {
settings := NewSettings()
addTestTags(settings)
for i, test := range parserTests {
t.Run(fmt.Sprintf("%02d", i+1), func(t *testing.T) {
_, err := settings.Parse(test.in)
require.NoError(t, err, test.in)
// require.Containsf(t, err.Error(), test.expected, test.in)
})
}
}