1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 08:18:59 +01:00
liquid/evaluator/call_test.go

37 lines
840 B
Go
Raw Normal View History

package evaluator
import (
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func TestCall(t *testing.T) {
fn := func(a, b string) string {
return a + "," + b + "."
}
value, err := Call(reflect.ValueOf(fn), []interface{}{5, 10})
require.NoError(t, err)
require.Equal(t, "5,10.", value)
// extra arguments
value, err = Call(reflect.ValueOf(fn), []interface{}{5, 10, 20})
require.NoError(t, err)
require.Equal(t, "5,10.", value)
}
func TestCall_optional(t *testing.T) {
fn := func(a string, b func(string) string) string {
return a + "," + b("default") + "."
}
value, err := Call(reflect.ValueOf(fn), []interface{}{5})
require.NoError(t, err)
require.Equal(t, "5,default.", value)
value, err = Call(reflect.ValueOf(fn), []interface{}{5, 10})
require.NoError(t, err)
require.Equal(t, "5,10.", value)
}