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

Function TestExtendStdlibFunction

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

Source from the content-addressed store, hash-verified

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