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

Function TestExtendStdlibFunction

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

Source from the content-addressed store, hash-verified

488}
489
490func TestExtendStdlibFunction(t *testing.T) {
491 env := testEnv(t,
492 Function(overloads.Contains,
493 MemberOverload("bytes_contains_bytes", []*Type{BytesType, BytesType}, BoolType,
494 BinaryBinding(func(bstr, bsub ref.Val) ref.Val {
495 return types.Bool(bytes.Contains([]byte(bstr.(types.Bytes)), []byte(bsub.(types.Bytes))))
496 }))),
497 )
498 prg := compile(t, env, `b'string'.contains(b'tri') && 'string'.contains('tri')`)
499 out, _, err := prg.Eval(NoVars())
500 if err != nil {
501 t.Fatalf("contains check errored: %v", err)
502 }
503 if out != types.True {
504 t.Errorf("contains check got %v, wanted true", out)
505 }
506}
507
508func TestSubsetStdLib(t *testing.T) {
509 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