From 7c62a60fc7b6c84c69041ac5ccf7c6b236117e17 Mon Sep 17 00:00:00 2001 From: Arthur Danskin Date: Mon, 3 Apr 2017 18:43:14 -0400 Subject: [PATCH] add tests for printf %f precision, fix spacing on %.f precision fix --- fmt/printf.h | 2 +- test/printf-test.cc | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/fmt/printf.h b/fmt/printf.h index 06c999a7..6ce752e7 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -440,7 +440,7 @@ void PrintfFormatter::format(BasicCStringRef format_str) { ++s; spec.precision_ = internal::PrecisionHandler().visit(get_arg(s)); } else { - spec.precision_ = 0; + spec.precision_ = 0; } } diff --git a/test/printf-test.cc b/test/printf-test.cc index 7d9e21dd..0d8b268a 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -401,6 +401,9 @@ TEST(PrintfTest, LongLong) { TEST(PrintfTest, Float) { EXPECT_PRINTF("392.650000", "%f", 392.65); + EXPECT_PRINTF("392.65", "%.2f", 392.65); + EXPECT_PRINTF("392.6", "%.1f", 392.65); + EXPECT_PRINTF("392", "%.f", 392.65); EXPECT_PRINTF("392.650000", "%F", 392.65); EXPECT_PRINTF("392.65", "%s", 392.65); char buffer[BUFFER_SIZE];