Convert negative precision to zero in printf (#1127)

and remove redundant check in grisu2_prettify.
This commit is contained in:
Victor Zverovich
2019-04-21 07:39:41 -07:00
parent 5efb24dd2b
commit bd516e3429
3 changed files with 7 additions and 4 deletions

View File

@@ -520,6 +520,10 @@ TEST(PrintfTest, CheckFormatStringRegression) {
check_format_string_regression("%c%s", 'x', "");
}
TEST(PrintfTest, FixedLargeExponent) {
EXPECT_EQ("1000000000000000000000", fmt::sprintf("%.*f", -13, 1e21));
}
TEST(PrintfTest, VSPrintfMakeArgsExample) {
fmt::format_arg_store<fmt::printf_context, int, const char*> as{42,
"something"};
@@ -599,7 +603,7 @@ std::string custom_format(const char* format_str, const Args&... args) {
return custom_vformat(format_str, va);
}
TEST(CustomFormatterTest, Format) {
TEST(PrintfTest, CustomFormat) {
EXPECT_EQ("0.00", custom_format("%.2f", -.00001));
EXPECT_EQ("0.00", custom_format("%.2f", .00001));
EXPECT_EQ("1.00", custom_format("%.2f", 1.00001));