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

Function TestSingletonUnaryBindingParameterized

cel/decls_test.go:265–291  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

263}
264
265func TestSingletonUnaryBindingParameterized(t *testing.T) {
266 // Test the case where the singleton unary impl is merged with the earlier declaration.
267 e, err := NewCustomEnv(
268 Variable("x", AnyType),
269 Function("isSorted", MemberOverload("list_int_is_sorted", []*Type{ListType(IntType)}, BoolType)),
270 Function("isSorted", MemberOverload("list_uint_is_sorted", []*Type{ListType(UintType)}, BoolType),
271 SingletonUnaryBinding(func(arg ref.Val) ref.Val { return types.True })),
272 )
273 if err != nil {
274 t.Errorf("NewCustomEnv() failed: %v", err)
275 }
276 ast, iss := e.Parse("x.isSorted()")
277 if iss.Err() != nil {
278 t.Fatalf("Parse('x.isSorted()') failed: %v", iss.Err())
279 }
280 prg, err := e.Program(ast)
281 if err != nil {
282 t.Fatalf("Program() failed: %v", err)
283 }
284 out, _, err := prg.Eval(map[string]any{"x": []int{1, 2, 3}})
285 if err != nil {
286 t.Errorf("prg.Eval(x=[1,2,3]) failed: %v", err)
287 }
288 if out != types.True {
289 t.Errorf("Eval got %v, wanted true", out)
290 }
291}
292
293func TestSingletonBinaryBinding(t *testing.T) {
294 _, err := NewCustomEnv(

Callers

nothing calls this directly

Calls 9

NewCustomEnvFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
VariableFunction · 0.70
FunctionFunction · 0.70
MemberOverloadFunction · 0.70
SingletonUnaryBindingFunction · 0.70
ParseMethod · 0.65
EvalMethod · 0.65

Tested by

no test coverage detected