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

Function TestNavigableStructExpr

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

Source from the content-addressed store, hash-verified

436}
437
438func TestNavigableStructExpr(t *testing.T) {
439 checked := mustTypeCheck(t, `google.expr.proto3.test.TestAllTypes{single_int32: 1}`)
440 expr := ast.NavigateAST(checked)
441 if expr.Kind() != ast.StructKind {
442 t.Errorf("Kind() got %v, wanted StructKind", expr.Kind())
443 }
444 s := expr.AsStruct()
445 if s.TypeName() != "google.expr.proto3.test.TestAllTypes" {
446 t.Errorf("TypeName() got %s, wanted TestAllTypes", s.TypeName())
447 }
448 if len(s.Fields()) != 1 {
449 t.Errorf("Fields() returned %v, wanted 1", s.Fields())
450 }
451 f := s.Fields()[0]
452 field := f.AsStructField()
453 if field.IsOptional() {
454 t.Error("IsOptional() returned true, wanted false")
455 }
456 if field.Name() != "single_int32" {
457 t.Errorf("Name() returned %s, wanted 'single_int32'", field.Name())
458 }
459 if field.Value().AsLiteral().Equal(types.Int(1)) != types.True {
460 t.Errorf("Value() returned %v, wanted 1", field.Value().AsLiteral())
461 }
462 descendants := ast.MatchDescendants(expr, ast.AllMatcher())
463 if len(descendants) != 2 {
464 t.Errorf("ast.MatchDescendants() returned %v, wanted 2", descendants)
465 }
466 literals := ast.MatchSubset(descendants, ast.KindMatcher(ast.LiteralKind))
467 if len(literals) != 1 {
468 t.Errorf("ast.MatchSubset() literals returned %v, wanted 1", literals)
469 }
470 if literals[0].AsLiteral().Equal(types.Int(1)) != types.True {
471 t.Errorf("Value().AsLiteral() got %v, wanted 1", literals[0].AsLiteral())
472 }
473}
474
475func TestNavigableComprehensionExpr(t *testing.T) {
476 checked := mustTypeCheck(t, `[true].exists(i, i)`)

Callers

nothing calls this directly

Calls 15

NavigateASTFunction · 0.92
IntTypeAlias · 0.92
MatchDescendantsFunction · 0.92
AllMatcherFunction · 0.92
MatchSubsetFunction · 0.92
KindMatcherFunction · 0.92
mustTypeCheckFunction · 0.85
KindMethod · 0.65
AsStructMethod · 0.65
TypeNameMethod · 0.65
FieldsMethod · 0.65
AsStructFieldMethod · 0.65

Tested by

no test coverage detected