| 695 | })pb"; |
| 696 | |
| 697 | TEST(UnknownsIterAttrTest, IterAttributeTrail) { |
| 698 | InterpreterOptions options; |
| 699 | Expr expr; |
| 700 | Activation activation; |
| 701 | Arena arena; |
| 702 | |
| 703 | protobuf::Value element; |
| 704 | protobuf::Value& value = |
| 705 | element.mutable_struct_value()->mutable_fields()->operator[]("elem1"); |
| 706 | value.set_number_value(1); |
| 707 | protobuf::ListValue list; |
| 708 | *list.add_values() = element; |
| 709 | *list.add_values() = element; |
| 710 | *list.add_values() = element; |
| 711 | |
| 712 | options.unknown_processing = UnknownProcessingOptions::kAttributeAndFunction; |
| 713 | auto builder = CreateCelExpressionBuilder(options); |
| 714 | ASSERT_THAT(RegisterBuiltinFunctions(builder->GetRegistry()), IsOk()); |
| 715 | ASSERT_THAT(builder->GetRegistry()->RegisterLazyFunction( |
| 716 | CreateDescriptor("Fn", CelValue::Type::kMap)), |
| 717 | IsOk()); |
| 718 | ASSERT_TRUE( |
| 719 | google::protobuf::TextFormat::ParseFromString(kListCompExistsWithAttrExpr, &expr)) |
| 720 | << "error parsing expr"; |
| 721 | |
| 722 | // var.exists(x, Fn(x)) |
| 723 | auto plan = builder->CreateExpression(&expr, nullptr).value(); |
| 724 | |
| 725 | activation.InsertValue("var", CelProtoWrapper::CreateMessage(&list, &arena)); |
| 726 | |
| 727 | // var[1]['elem1'] is unknown |
| 728 | activation.set_unknown_attribute_patterns({CelAttributePattern( |
| 729 | "var", { |
| 730 | CreateCelAttributeQualifierPattern(CelValue::CreateInt64(1)), |
| 731 | CreateCelAttributeQualifierPattern( |
| 732 | CelValue::CreateStringView("elem1")), |
| 733 | })}); |
| 734 | |
| 735 | ASSERT_THAT(activation.InsertFunction(std::make_unique<FunctionImpl>( |
| 736 | "Fn", FunctionResponse::kFalse, CelValue::Type::kMap)), |
| 737 | IsOk()); |
| 738 | |
| 739 | CelValue response = plan->Evaluate(activation, &arena).value(); |
| 740 | |
| 741 | ASSERT_TRUE(response.IsUnknownSet()) << CelValue::TypeName(response.type()); |
| 742 | ASSERT_EQ(response.UnknownSetOrDie()->unknown_attributes().size(), 1); |
| 743 | // 'var[1]' is partially unknown when we make the function call so we treat it |
| 744 | // as unknown. |
| 745 | ASSERT_EQ(response.UnknownSetOrDie() |
| 746 | ->unknown_attributes() |
| 747 | .begin() |
| 748 | ->qualifier_path() |
| 749 | .size(), |
| 750 | 1); |
| 751 | } |
| 752 | |
| 753 | TEST(UnknownsIterAttrTest, IterAttributeTrailMapKeyTypes) { |
| 754 | InterpreterOptions options; |
nothing calls this directly
no test coverage detected