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

Function TestPartialVars

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

Source from the content-addressed store, hash-verified

2012}
2013
2014func TestPartialVars(t *testing.T) {
2015 env := testEnv(t,
2016 Variable("x", StringType),
2017 Variable("y", IntType),
2018 )
2019 ast, iss := env.Compile("x == string(y)")
2020 if iss.Err() != nil {
2021 t.Fatalf("env.Compile() failed: %v", iss.Err())
2022 }
2023 prg, err := env.Program(ast, EvalOptions(OptPartialEval))
2024 if err != nil {
2025 t.Fatalf("env.Program() failed: %v", err)
2026 }
2027
2028 tests := []struct {
2029 in map[string]any
2030 unk []*interpreter.AttributePattern
2031 out ref.Val
2032 partialOut ref.Val
2033 }{
2034 {
2035 in: map[string]any{},
2036 unk: []*interpreter.AttributePattern{
2037 interpreter.NewAttributePattern("x"),
2038 interpreter.NewAttributePattern("y"),
2039 },
2040 out: types.NewUnknown(1, types.NewAttributeTrail("x")),
2041 },
2042 {
2043 in: map[string]any{"x": "10"},
2044 unk: []*interpreter.AttributePattern{
2045 interpreter.NewAttributePattern("y"),
2046 },
2047 out: types.NewUnknown(4, types.NewAttributeTrail("y")),
2048 },
2049 {
2050 in: map[string]any{"y": 10},
2051 unk: []*interpreter.AttributePattern{
2052 interpreter.NewAttributePattern("x"),
2053 },
2054 out: types.NewUnknown(1, types.NewAttributeTrail("x")),
2055 },
2056 {
2057 in: map[string]any{"x": "10", "y": 10},
2058 unk: []*interpreter.AttributePattern{},
2059 out: types.True,
2060 },
2061 {
2062 in: map[string]any{"x": "10", "y": 9},
2063 unk: []*interpreter.AttributePattern{},
2064 out: types.False,
2065 },
2066 {
2067 in: map[string]any{"y": 10},
2068 unk: []*interpreter.AttributePattern{},
2069 out: types.NewErr("no such attribute: x"),
2070 partialOut: types.NewUnknown(1, types.NewAttributeTrail("x")),
2071 },

Callers

nothing calls this directly

Calls 15

NewAttributePatternFunction · 0.92
NewUnknownFunction · 0.92
NewAttributeTrailFunction · 0.92
NewErrFunction · 0.92
IsErrorFunction · 0.92
IsUnknownFunction · 0.92
EvalOptionsFunction · 0.85
PartialVarsFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
PartialVarsMethod · 0.80
testEnvFunction · 0.70

Tested by

no test coverage detected