Check that formatted floating points are reversible.
| 63 | |
| 64 | // Check that formatted floating points are reversible. |
| 65 | TEST_P(StringFormatLimitsTest, FormatLimits) { |
| 66 | google::protobuf::Arena arena; |
| 67 | const RuntimeOptions options; |
| 68 | ASSERT_OK_AND_ASSIGN(auto builder, |
| 69 | CreateStandardRuntimeBuilder( |
| 70 | internal::GetTestingDescriptorPool(), options)); |
| 71 | ASSERT_THAT( |
| 72 | RegisterStringFormattingFunctions(builder.function_registry(), options), |
| 73 | IsOk()); |
| 74 | |
| 75 | ASSERT_OK_AND_ASSIGN(auto runtime, std::move(builder).Build()); |
| 76 | |
| 77 | ASSERT_OK_AND_ASSIGN(ParsedExpr expr, |
| 78 | Parse(GetParam(), "<input>", ParserOptions{})); |
| 79 | ASSERT_OK_AND_ASSIGN(std::unique_ptr<Program> program, |
| 80 | ProtobufRuntimeAdapter::CreateProgram(*runtime, expr)); |
| 81 | Activation activation; |
| 82 | |
| 83 | static_assert(std::numeric_limits<double>::min_exponent == -1021); |
| 84 | for (double x : { |
| 85 | 0x1p-1021, |
| 86 | 0x3p-1021, |
| 87 | std::numeric_limits<double>::epsilon() * 0x1p-3, |
| 88 | std::numeric_limits<double>::epsilon() * 0x7p-3, |
| 89 | 1.1 / 7.0 * 1e-101, |
| 90 | 1.2 / 7.0 * 1e-101, |
| 91 | }) { |
| 92 | activation.InsertOrAssignValue("x", DoubleValue(x)); |
| 93 | ASSERT_OK_AND_ASSIGN(Value value, program->Evaluate(&arena, activation)); |
| 94 | ASSERT_TRUE(value.Is<BoolValue>()); |
| 95 | EXPECT_TRUE(value.GetBool().NativeValue()); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | TEST(StringFormatLimitsTest, MaxPrecisionOption) { |
| 100 | google::protobuf::Arena arena; |
nothing calls this directly
no test coverage detected