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

Function TestNavigableASTNilSafety

common/ast/navigable_test.go:304–344  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

302}
303
304func TestNavigableASTNilSafety(t *testing.T) {
305 tests := []struct {
306 name string
307 e ast.NavigableExpr
308 }{
309 {
310 name: "nil expr",
311 e: ast.NavigateAST(ast.NewAST(nil, nil)),
312 },
313 }
314 for _, tst := range tests {
315 tc := tst
316 t.Run(tc.name, func(t *testing.T) {
317 e := tc.e
318 if e.ID() != 0 {
319 t.Errorf("ID() got %d, wanted 0", e.ID())
320 }
321 if e.Kind() != ast.UnspecifiedExprKind {
322 t.Errorf("Kind() got %v, wanted unspecified kind", e.Kind())
323 }
324 if e.Type() != types.DynType {
325 t.Errorf("Type() got %v, wanted types.DynType", e.Type())
326 }
327 if p, found := e.Parent(); found {
328 t.Errorf("Parent() got %v, wanted not found", p)
329 }
330 if len(e.Children()) != 0 {
331 t.Errorf("Children() got %v, wanted none", e.Children())
332 }
333 if e.AsLiteral() != nil {
334 t.Errorf("AsLiteral() got %v, wanted nil", e.AsLiteral())
335 }
336 if e.AsCall() == nil {
337 t.Errorf("AsCall() got nil, wanted non-nil for safe traversal")
338 }
339 if e.AsComprehension() == nil {
340 t.Errorf("AsComprehension() got nil, wanted non-nil for safe traversal")
341 }
342 })
343 }
344}
345
346func TestNavigableExpr(t *testing.T) {
347 checkedAST := mustTypeCheck(t, `'a' == 'b'`)

Callers

nothing calls this directly

Calls 10

NavigateASTFunction · 0.92
NewASTFunction · 0.92
IDMethod · 0.65
KindMethod · 0.65
TypeMethod · 0.65
ParentMethod · 0.65
ChildrenMethod · 0.65
AsLiteralMethod · 0.65
AsCallMethod · 0.65
AsComprehensionMethod · 0.65

Tested by

no test coverage detected