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

Function TestExtendStdlibFunction

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

Source from the content-addressed store, hash-verified

403}
404
405func TestExtendStdlibFunction(t *testing.T) {
406 env := testEnv(t,
407 Function(overloads.Contains,
408 MemberOverload("bytes_contains_bytes", []*Type{BytesType, BytesType}, BoolType,
409 BinaryBinding(func(bstr, bsub ref.Val) ref.Val {
410 return types.Bool(bytes.Contains([]byte(bstr.(types.Bytes)), []byte(bsub.(types.Bytes))))
411 }))),
412 )
413 prg := compile(t, env, `b'string'.contains(b'tri') && 'string'.contains('tri')`)
414 out, _, err := prg.Eval(NoVars())
415 if err != nil {
416 t.Fatalf("contains check errored: %v", err)
417 }
418 if out != types.True {
419 t.Errorf("contains check got %v, wanted true", out)
420 }
421}
422
423func TestSubsetStdLib(t *testing.T) {
424 env, err := NewCustomEnv(

Callers

nothing calls this directly

Calls 9

BoolTypeAlias · 0.92
NoVarsFunction · 0.85
testEnvFunction · 0.70
FunctionFunction · 0.70
MemberOverloadFunction · 0.70
BinaryBindingFunction · 0.70
compileFunction · 0.70
ContainsMethod · 0.65
EvalMethod · 0.65

Tested by

no test coverage detected