| 97 | } |
| 98 | |
| 99 | TEST(StringFormatLimitsTest, MaxPrecisionOption) { |
| 100 | google::protobuf::Arena arena; |
| 101 | const RuntimeOptions options; |
| 102 | StringsExtensionFormatOptions format_options; |
| 103 | format_options.max_precision = 99; |
| 104 | ASSERT_OK_AND_ASSIGN(auto builder, |
| 105 | CreateStandardRuntimeBuilder( |
| 106 | internal::GetTestingDescriptorPool(), options)); |
| 107 | ASSERT_THAT(RegisterStringFormattingFunctions(builder.function_registry(), |
| 108 | options, format_options), |
| 109 | IsOk()); |
| 110 | |
| 111 | ASSERT_OK_AND_ASSIGN(auto runtime, std::move(builder).Build()); |
| 112 | |
| 113 | ASSERT_OK_AND_ASSIGN(ParsedExpr expr, Parse("'%.100f'.format([1.123])", |
| 114 | "<input>", ParserOptions{})); |
| 115 | ASSERT_OK_AND_ASSIGN(std::unique_ptr<Program> program, |
| 116 | ProtobufRuntimeAdapter::CreateProgram(*runtime, expr)); |
| 117 | Activation activation; |
| 118 | |
| 119 | ASSERT_OK_AND_ASSIGN(Value value, program->Evaluate(&arena, activation)); |
| 120 | ASSERT_TRUE(value.Is<ErrorValue>()); |
| 121 | EXPECT_THAT(value.GetError().ToStatus().message(), |
| 122 | HasSubstr("precision specifier exceeds maximum of 99")); |
| 123 | } |
| 124 | |
| 125 | INSTANTIATE_TEST_SUITE_P(StringFormatLimitsTest, StringFormatLimitsTest, |
| 126 | ValuesIn<std::string>({ |
nothing calls this directly
no test coverage detected