ucl/ucl/builtins/fns_test.go

34 lines
740 B
Go

package builtins_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"ucl.lmika.dev/ucl"
"ucl.lmika.dev/ucl/builtins"
)
func TestFns_Uni(t *testing.T) {
tests := []struct {
descr string
eval string
want any
}{
{descr: "uni 1", eval: `s = fns:uni add 2 ; $s 3`, want: 5},
{descr: "uni 2", eval: `s = fns:uni (proc { |x| add $x 1 }) ; $s 3`, want: 4},
{descr: "uni 3", eval: `s = fns:uni add 2 ; map [1 2 3] $s`, want: []any{3, 4, 5}},
}
for _, tt := range tests {
t.Run(tt.descr, func(t *testing.T) {
inst := ucl.New(
ucl.WithModule(builtins.Fns()),
)
res, err := inst.EvalString(context.Background(), tt.eval)
assert.NoError(t, err)
assert.Equal(t, tt.want, res)
})
}
}