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

Function TestFunctionZeroArityBinding

common/decls/decls_test.go:178–205  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

176}
177
178func TestFunctionZeroArityBinding(t *testing.T) {
179 now := types.DefaultTypeAdapter.NativeToValue(time.UnixMilli(1000))
180 nowFunc, err := NewFunction("now",
181 Overload("now", []*types.Type{}, types.TimestampType,
182 FunctionBinding(func(args ...ref.Val) ref.Val {
183 return now
184 })),
185 )
186 if err != nil {
187 t.Fatalf("NewFunction() failed: %v", err)
188 }
189 for _, od := range nowFunc.OverloadDecls() {
190 if !od.HasBinding() {
191 t.Errorf("Overload %s does not have binding, wanted function binding", od.ID())
192 }
193 }
194 bindings, err := nowFunc.Bindings()
195 if err != nil {
196 t.Fatalf("nowFunc.Bindings() produced an err: %v", err)
197 }
198 if len(bindings) != 1 {
199 t.Errorf("nowFunc.Bindings() produced %d bindings, wanted one", len(bindings))
200 }
201 out := bindings[0].Function()
202 if out != now {
203 t.Errorf("now() got %v, wanted %v", out, now)
204 }
205}
206
207func TestFunctionSingletonBinding(t *testing.T) {
208 size, err := NewFunction("size",

Callers

nothing calls this directly

Calls 9

OverloadDeclsMethod · 0.80
HasBindingMethod · 0.80
BindingsMethod · 0.80
NewFunctionFunction · 0.70
OverloadFunction · 0.70
FunctionBindingFunction · 0.70
NativeToValueMethod · 0.65
IDMethod · 0.65
FunctionMethod · 0.65

Tested by

no test coverage detected