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

Function TestNavigableMapExpr

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

Source from the content-addressed store, hash-verified

402}
403
404func TestNavigableMapExpr(t *testing.T) {
405 checked := mustTypeCheck(t, `{'hello': 1}`)
406 expr := ast.NavigateAST(checked)
407 if expr.Kind() != ast.MapKind {
408 t.Errorf("Kind() got %v, wanted MapKind", expr.Kind())
409 }
410 m := expr.AsMap()
411 if m.Size() != 1 {
412 t.Errorf("Size() got %d, wanted 1", m.Size())
413 }
414 if len(m.Entries()) != 1 {
415 t.Errorf("Entries() returned %v, wanted 1", m.Entries())
416 }
417 e := m.Entries()[0]
418 entry := e.AsMapEntry()
419 if entry.IsOptional() {
420 t.Error("IsOptional() returned true, wanted false")
421 }
422 if entry.Key().AsLiteral().Equal(types.String("hello")) != types.True {
423 t.Errorf("Key() returned %v, wanted 'hello'", entry.Key().AsLiteral())
424 }
425 if entry.Value().AsLiteral().Equal(types.Int(1)) != types.True {
426 t.Errorf("Value() returned %v, wanted 1", entry.Value().AsLiteral())
427 }
428 descendants := ast.MatchDescendants(expr, ast.AllMatcher())
429 if len(descendants) != 3 {
430 t.Errorf("ast.MatchDescendants() returned %v, wanted 3", descendants)
431 }
432 literals := ast.MatchSubset(descendants, ast.KindMatcher(ast.LiteralKind))
433 if len(literals) != 2 {
434 t.Errorf("ast.MatchSubset() literals returned %v, wanted 2", literals)
435 }
436}
437
438func TestNavigableStructExpr(t *testing.T) {
439 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