2017-06-26 16:15:01 +02:00
|
|
|
package liquid
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2017-07-04 22:48:38 +02:00
|
|
|
var emptyBindings = map[string]interface{}{}
|
|
|
|
|
2017-06-30 14:45:22 +02:00
|
|
|
// There's a lot more tests in the filters and tags sub-packages.
|
|
|
|
// This collects a minimal set for testing end-to-end.
|
2017-06-26 16:15:01 +02:00
|
|
|
var liquidTests = []struct{ in, expected string }{
|
2017-06-30 14:45:22 +02:00
|
|
|
{`{{ page.title }}`, "Introduction"},
|
2017-06-30 22:13:18 +02:00
|
|
|
{`{% if x %}true{% endif %}`, "true"},
|
|
|
|
{`{{ "upper" | upcase }}`, "UPPER"},
|
2017-06-26 16:15:01 +02:00
|
|
|
}
|
|
|
|
|
2017-07-03 03:17:04 +02:00
|
|
|
var testBindings = map[string]interface{}{
|
2017-06-26 16:15:01 +02:00
|
|
|
"x": 123,
|
|
|
|
"ar": []string{"first", "second", "third"},
|
|
|
|
"page": map[string]interface{}{
|
|
|
|
"title": "Introduction",
|
|
|
|
},
|
2017-07-03 03:17:04 +02:00
|
|
|
}
|
2017-06-26 16:15:01 +02:00
|
|
|
|
2017-07-04 22:48:38 +02:00
|
|
|
func TestEngine_ParseAndRenderString(t *testing.T) {
|
2017-06-26 16:15:01 +02:00
|
|
|
engine := NewEngine()
|
|
|
|
for i, test := range liquidTests {
|
2017-06-30 22:13:18 +02:00
|
|
|
t.Run(fmt.Sprint(i+1), func(t *testing.T) {
|
2017-07-03 03:17:04 +02:00
|
|
|
out, err := engine.ParseAndRenderString(test.in, testBindings)
|
2017-06-26 16:15:01 +02:00
|
|
|
require.NoErrorf(t, err, test.in)
|
2017-06-26 16:36:53 +02:00
|
|
|
require.Equalf(t, test.expected, out, test.in)
|
2017-06-26 16:15:01 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|