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

Function TestRefValToExprValue

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

Source from the content-addressed store, hash-verified

195}
196
197func TestRefValToExprValue(t *testing.T) {
198 tests := []struct {
199 name string
200 refVal ref.Val
201 expectError bool
202 }{
203 {
204 name: "unknown value",
205 refVal: types.NewUnknown(1, nil),
206 expectError: false,
207 },
208 {
209 name: "error value",
210 refVal: types.NewErr("test error"),
211 expectError: false,
212 },
213 {
214 name: "bool value",
215 refVal: types.Bool(true),
216 expectError: false,
217 },
218 {
219 name: "string value",
220 refVal: types.String("test"),
221 expectError: false,
222 },
223 {
224 name: "int value",
225 refVal: types.Int(1),
226 expectError: false,
227 },
228 }
229 for _, tst := range tests {
230 tc := tst
231 t.Run(tc.name, func(t *testing.T) {
232 exprVal, err := ExprValueAsProto(tc.refVal)
233 if tc.expectError {
234 if err == nil {
235 t.Errorf("RefValToExprValue(%v) expected error, got %v", tc.refVal, exprVal)
236 }
237 } else {
238 if err != nil {
239 t.Errorf("RefValToExprValue(%v) failed with error: %v", tc.refVal, err)
240 }
241 if exprVal == nil {
242 t.Errorf("RefValToExprValue(%v) expected value, got nil", tc.refVal)
243 }
244 }
245 })
246 }
247}
248
249func TestAstToStringNil(t *testing.T) {
250 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