MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestLateBoundFunctionSignatureGuard

Function TestLateBoundFunctionSignatureGuard

cel/cel_test.go:6120–6212  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6118}
6119
6120func TestLateBoundFunctionSignatureGuard(t *testing.T) {
6121 env, err := NewEnv(
6122 Variable("dyn_val", DynType),
6123 Function("inc",
6124 Overload("inc_int", []*Type{IntType}, IntType, LateFunctionBinding()),
6125 ),
6126 )
6127 if err != nil {
6128 t.Fatalf("NewEnv() failed: %v", err)
6129 }
6130 tests := []struct {
6131 name string
6132 expr string
6133 parsed bool
6134 vars map[string]any
6135 want ref.Val
6136 wantErr string
6137 }{
6138 {
6139 name: "declared signature satisfied",
6140 expr: "inc(1)",
6141 want: types.Int(2),
6142 },
6143 {
6144 name: "dyn argument matching the declaration",
6145 expr: "inc(dyn_val)",
6146 vars: map[string]any{"dyn_val": 1},
6147 want: types.Int(2),
6148 },
6149 {
6150 name: "dyn argument violating the declaration",
6151 expr: "inc(dyn_val)",
6152 vars: map[string]any{"dyn_val": "not-an-int"},
6153 wantErr: "no such overload: inc",
6154 },
6155 {
6156 name: "unchecked argument violating the declaration",
6157 expr: "inc('not-an-int')",
6158 parsed: true,
6159 wantErr: "no such overload: inc",
6160 },
6161 {
6162 name: "unchecked arity mismatch",
6163 expr: "inc(1, 2)",
6164 parsed: true,
6165 wantErr: "no such overload: inc",
6166 },
6167 }
6168 for _, tc := range tests {
6169 t.Run(tc.name, func(t *testing.T) {
6170 var ast *Ast
6171 var iss *Issues
6172 if tc.parsed {
6173 ast, iss = env.Parse(tc.expr)
6174 } else {
6175 ast, iss = env.Compile(tc.expr)
6176 }
6177 if iss.Err() != nil {

Callers

nothing calls this directly

Calls 15

ParseMethod · 0.95
CompileMethod · 0.95
ErrMethod · 0.95
ProgramMethod · 0.95
IntTypeAlias · 0.92
FunctionVarsFunction · 0.85
NewEnvFunction · 0.70
VariableFunction · 0.70
FunctionFunction · 0.70
OverloadFunction · 0.70
LateFunctionBindingFunction · 0.70
EvalMethod · 0.65

Tested by

no test coverage detected