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

Function TestNavigableMapExpr

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

Source from the content-addressed store, hash-verified

479}
480
481func TestNavigableMapExpr(t *testing.T) {
482 checked := mustTypeCheck(t, `{'hello': 1}`)
483 expr := ast.NavigateAST(checked)
484 if expr.Kind() != ast.MapKind {
485 t.Errorf("Kind() got %v, wanted MapKind", expr.Kind())
486 }
487 m := expr.AsMap()
488 if m.Size() != 1 {
489 t.Errorf("Size() got %d, wanted 1", m.Size())
490 }
491 if len(m.Entries()) != 1 {
492 t.Errorf("Entries() returned %v, wanted 1", m.Entries())
493 }
494 e := m.Entries()[0]
495 entry := e.AsMapEntry()
496 if entry.IsOptional() {
497 t.Error("IsOptional() returned true, wanted false")
498 }
499 if entry.Key().AsLiteral().Equal(types.String("hello")) != types.True {
500 t.Errorf("Key() returned %v, wanted 'hello'", entry.Key().AsLiteral())
501 }
502 if entry.Value().AsLiteral().Equal(types.Int(1)) != types.True {
503 t.Errorf("Value() returned %v, wanted 1", entry.Value().AsLiteral())
504 }
505 descendants := ast.MatchDescendants(expr, ast.AllMatcher())
506 if len(descendants) != 3 {
507 t.Errorf("ast.MatchDescendants() returned %v, wanted 3", descendants)
508 }
509 literals := ast.MatchSubset(descendants, ast.KindMatcher(ast.LiteralKind))
510 if len(literals) != 2 {
511 t.Errorf("ast.MatchSubset() literals returned %v, wanted 2", literals)
512 }
513}
514
515func TestNavigableStructExpr(t *testing.T) {
516 checked := mustTypeCheck(t, `google.expr.proto3.test.TestAllTypes{single_int32: 1}`)

Callers

nothing calls this directly

Calls 15

NavigateASTFunction · 0.92
StringTypeAlias · 0.92
IntTypeAlias · 0.92
MatchDescendantsFunction · 0.92
AllMatcherFunction · 0.92
MatchSubsetFunction · 0.92
KindMatcherFunction · 0.92
mustTypeCheckFunction · 0.85
KindMethod · 0.65
AsMapMethod · 0.65
SizeMethod · 0.65
EntriesMethod · 0.65

Tested by

no test coverage detected