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

Function TestRefValToExprValue

cel/io_test.go:238–288  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

236}
237
238func TestRefValToExprValue(t *testing.T) {
239 tests := []struct {
240 name string
241 refVal ref.Val
242 expectError bool
243 }{
244 {
245 name: "unknown value",
246 refVal: types.NewUnknown(1, nil),
247 expectError: false,
248 },
249 {
250 name: "error value",
251 refVal: types.NewErr("test error"),
252 expectError: false,
253 },
254 {
255 name: "bool value",
256 refVal: types.Bool(true),
257 expectError: false,
258 },
259 {
260 name: "string value",
261 refVal: types.String("test"),
262 expectError: false,
263 },
264 {
265 name: "int value",
266 refVal: types.Int(1),
267 expectError: false,
268 },
269 }
270 for _, tst := range tests {
271 tc := tst
272 t.Run(tc.name, func(t *testing.T) {
273 exprVal, err := ExprValueAsProto(tc.refVal)
274 if tc.expectError {
275 if err == nil {
276 t.Errorf("RefValToExprValue(%v) expected error, got %v", tc.refVal, exprVal)
277 }
278 } else {
279 if err != nil {
280 t.Errorf("RefValToExprValue(%v) failed with error: %v", tc.refVal, err)
281 }
282 if exprVal == nil {
283 t.Errorf("RefValToExprValue(%v) expected value, got nil", tc.refVal)
284 }
285 }
286 })
287 }
288}
289
290func TestAstToStringNil(t *testing.T) {
291 expr, err := AstToString(nil)

Callers

nothing calls this directly

Calls 6

NewUnknownFunction · 0.92
NewErrFunction · 0.92
BoolTypeAlias · 0.92
StringTypeAlias · 0.92
IntTypeAlias · 0.92
ExprValueAsProtoFunction · 0.85

Tested by

no test coverage detected