(t *testing.T)
| 436 | } |
| 437 | |
| 438 | func 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 | |
| 475 | func TestNavigableComprehensionExpr(t *testing.T) { |
| 476 | checked := mustTypeCheck(t, `[true].exists(i, i)`) |
nothing calls this directly
no test coverage detected