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

Function TestExtendStdlibFunction

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

Source from the content-addressed store, hash-verified

383}
384
385func TestExtendStdlibFunction(t *testing.T) {
386 env := testEnv(t,
387 Function(overloads.Contains,
388 MemberOverload("bytes_contains_bytes", []*Type{BytesType, BytesType}, BoolType,
389 BinaryBinding(func(bstr, bsub ref.Val) ref.Val {
390 return types.Bool(bytes.Contains([]byte(bstr.(types.Bytes)), []byte(bsub.(types.Bytes))))
391 }))),
392 )
393 prg := compile(t, env, `b'string'.contains(b'tri') && 'string'.contains('tri')`)
394 out, _, err := prg.Eval(NoVars())
395 if err != nil {
396 t.Fatalf("contains check errored: %v", err)
397 }
398 if out != types.True {
399 t.Errorf("contains check got %v, wanted true", out)
400 }
401}
402
403func TestSubsetStdLib(t *testing.T) {
404 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