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

Function TestNavigableStructExpr

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

Source from the content-addressed store, hash-verified

513}
514
515func TestNavigableStructExpr(t *testing.T) {
516 checked := mustTypeCheck(t, `google.expr.proto3.test.TestAllTypes{single_int32: 1}`)
517 expr := ast.NavigateAST(checked)
518 if expr.Kind() != ast.StructKind {
519 t.Errorf("Kind() got %v, wanted StructKind", expr.Kind())
520 }
521 s := expr.AsStruct()
522 if s.TypeName() != "google.expr.proto3.test.TestAllTypes" {
523 t.Errorf("TypeName() got %s, wanted TestAllTypes", s.TypeName())
524 }
525 if len(s.Fields()) != 1 {
526 t.Errorf("Fields() returned %v, wanted 1", s.Fields())
527 }
528 f := s.Fields()[0]
529 field := f.AsStructField()
530 if field.IsOptional() {
531 t.Error("IsOptional() returned true, wanted false")
532 }
533 if field.Name() != "single_int32" {
534 t.Errorf("Name() returned %s, wanted 'single_int32'", field.Name())
535 }
536 if field.Value().AsLiteral().Equal(types.Int(1)) != types.True {
537 t.Errorf("Value() returned %v, wanted 1", field.Value().AsLiteral())
538 }
539 descendants := ast.MatchDescendants(expr, ast.AllMatcher())
540 if len(descendants) != 2 {
541 t.Errorf("ast.MatchDescendants() returned %v, wanted 2", descendants)
542 }
543 literals := ast.MatchSubset(descendants, ast.KindMatcher(ast.LiteralKind))
544 if len(literals) != 1 {
545 t.Errorf("ast.MatchSubset() literals returned %v, wanted 1", literals)
546 }
547 if literals[0].AsLiteral().Equal(types.Int(1)) != types.True {
548 t.Errorf("Value().AsLiteral() got %v, wanted 1", literals[0].AsLiteral())
549 }
550}
551
552func TestNavigableComprehensionExpr(t *testing.T) {
553 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