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

Function TestDynamicBlockEval

ext/bindings_test.go:889–916  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

887}
888
889func TestDynamicBlockEval(t *testing.T) {
890 db := &dynamicBlock{
891 expr: interpreter.NewConstValue(1, types.IntOne),
892 slotActivationPool: &sync.Pool{
893 New: func() any {
894 return &dynamicSlotActivation{}
895 },
896 },
897 }
898 res := db.Eval(cel.NoVars())
899 if res.Equal(types.IntOne) != types.True {
900 t.Errorf("db.Eval() = %v, wanted 1", res)
901 }
902
903 slot0 := interpreter.NewConstValue(1, types.IntOne)
904 pooled := newDynamicBlock([]interpreter.InterpretableV2{slot0}, slot0).(*dynamicBlock)
905 sa := pooled.slotActivationPool.Get().(*dynamicSlotActivation)
906 if allocs := testing.AllocsPerRun(100, func() {
907 sa.reset()
908 for i := 0; i < 2; i++ {
909 if val, found := sa.ResolveName("@index0"); !found || val != types.IntOne {
910 t.Fatalf("ResolveName(@index0) = (%v, %v), wanted (1, true)", val, found)
911 }
912 }
913 }); allocs != 0 {
914 t.Errorf("ResolveName allocated %v allocs/run, wanted 0", allocs)
915 }
916}
917
918func TestConstantBlockEval(t *testing.T) {
919 cb := &constantBlock{

Callers

nothing calls this directly

Calls 8

EvalMethod · 0.95
NewConstValueFunction · 0.92
NoVarsFunction · 0.92
newDynamicBlockFunction · 0.85
EqualMethod · 0.65
GetMethod · 0.65
ResolveNameMethod · 0.65
resetMethod · 0.45

Tested by

no test coverage detected