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

Function TestOptionalMacroError

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

Source from the content-addressed store, hash-verified

4114}
4115
4116func TestOptionalMacroError(t *testing.T) {
4117 env := testEnv(t,
4118 OptionalTypes(),
4119 // Test variables.
4120 Variable("x", OptionalType(IntType)),
4121 )
4122 _, iss := env.Compile("x.optMap(y.z, y.z + 1)")
4123 if iss.Err() == nil || !strings.Contains(iss.Err().Error(), "variable name must be a simple identifier") {
4124 t.Errorf("optMap() got an unexpected result: %v", iss.Err())
4125 }
4126 _, iss = env.Compile("x.optFlatMap(y.z, y.z + 1)")
4127 if iss.Err() == nil || !strings.Contains(iss.Err().Error(), "variable name must be a simple identifier") {
4128 t.Errorf("optFlatMap() got an unexpected result: %v", iss.Err())
4129 }
4130 env = testEnv(t,
4131 OptionalTypes(OptionalTypesVersion(0)),
4132 // Test variables.
4133 Variable("x", OptionalType(IntType)),
4134 )
4135 _, iss = env.Compile("x.optFlatMap(y, y.z + 1)")
4136 if iss.Err() == nil || !strings.Contains(iss.Err().Error(), "undeclared reference to 'optFlatMap'") {
4137 t.Errorf("optFlatMap() got an unexpected result: %v", iss.Err())
4138 }
4139}
4140
4141// TestOptionalHasValueCost verifies that the cost of comparing the optional's value against the
4142// input argument is tracked rather than being charged as a flat function call cost.

Callers

nothing calls this directly

Calls 8

OptionalTypesFunction · 0.85
OptionalTypesVersionFunction · 0.85
ErrMethod · 0.80
testEnvFunction · 0.70
VariableFunction · 0.70
CompileMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected