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

Function TestOptionalOperatorsLegacyEval

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

Source from the content-addressed store, hash-verified

5380}
5381
5382func TestOptionalOperatorsLegacyEval(t *testing.T) {
5383 tests := []struct {
5384 name string
5385 expr interpreter.Interpretable
5386 want ref.Val
5387 }{
5388 {
5389 name: "optional or",
5390 expr: &evalOptionalOr{
5391 id: 1,
5392 lhs: interpreter.NewConstValue(2, types.OptionalOf(types.True)),
5393 rhs: interpreter.NewConstValue(3, types.False),
5394 },
5395 want: types.OptionalOf(types.True),
5396 },
5397 {
5398 name: "optional or value mismatch",
5399 expr: &evalOptionalOrValue{
5400 id: 4,
5401 lhs: interpreter.NewConstValue(5, types.True),
5402 rhs: interpreter.NewConstValue(6, types.False),
5403 },
5404 want: types.NoSuchOverloadErr(),
5405 },
5406 }
5407 for _, tc := range tests {
5408 t.Run(tc.name, func(t *testing.T) {
5409 got := tc.expr.Eval(NoVars())
5410 if got.Equal(tc.want) != types.True && !types.IsError(got) {
5411 t.Errorf("Eval() = %v, wanted %v", got, tc.want)
5412 }
5413 if types.IsError(got) && got.(*types.Err).Error() != tc.want.(*types.Err).Error() {
5414 t.Errorf("Eval() = %v, wanted %v", got, tc.want)
5415 }
5416 })
5417 }
5418}
5419
5420func TestNativeTypeForAndAlias(t *testing.T) {
5421 type CustomAccount struct {

Callers

nothing calls this directly

Calls 8

NewConstValueFunction · 0.92
OptionalOfFunction · 0.92
NoSuchOverloadErrFunction · 0.92
IsErrorFunction · 0.92
NoVarsFunction · 0.85
EvalMethod · 0.65
EqualMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected