Debian Codegraph @

execution/execute_func_test.go

raw symbols SCIP
1 package execution_test
2
3 import (
4 "context"
5 "testing"
6
7 "github.com/tomwright/dasel/v3/execution"
8 "github.com/tomwright/dasel/v3/model"
9 )
10
11 func TestFunc(t *testing.T) {
12 returnInputData := execution.NewFunc(
13 "returnInputData",
14 func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) {
15 return data, nil
16 },
17 execution.ValidateArgsExactly(0),
18 )
19
20 returnFirstArg := execution.NewFunc(
21 "returnFirstArg",
22 func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) {
23 return args[0], nil
24 },
25 execution.ValidateArgsExactly(1),
26 )
27
28 funcs := execution.NewFuncCollection(
29 returnInputData,
30 returnFirstArg,
31 )
32
33 opts := []execution.ExecuteOptionFn{
34 func(options *execution.Options) {
35 options.Funcs = funcs
36 },
37 }
38
39 t.Run("returnInputData", testCase{
40 s: `1.returnInputData()`,
41 out: model.NewIntValue(1),
42 opts: opts,
43 }.run)
44
45 t.Run("returnFirstArg", testCase{
46 s: `1.returnFirstArg(2)`,
47 out: model.NewIntValue(2),
48 opts: opts,
49 }.run)
50 }