From 0552f5b809cbd09cf575c033bbf461be9ba64f19 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 23 Jun 2014 07:07:10 -0700 Subject: [PATCH] Test precision. --- test/printf-test.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/printf-test.cc b/test/printf-test.cc index 6b5df89f..60dc236f 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -227,7 +227,7 @@ TEST(PrintfTest, DynamicWidth) { "argument index is out of range in format"); } -TEST(PrintfTest, Precision) { +TEST(PrintfTest, IntPrecision) { EXPECT_PRINTF("00042", "%.5d", 42); EXPECT_PRINTF("-00042", "%.5d", -42); EXPECT_PRINTF("00042", "%.5x", 0x42); @@ -248,6 +248,21 @@ TEST(PrintfTest, Precision) { EXPECT_PRINTF("00042 ", "%-#10.5o", 042); } +TEST(PrintfTest, FloatPrecision) { + char buffer[BUFFER_SIZE]; + SPrintf(buffer, "%.3e", 1234.5678); + EXPECT_PRINTF(buffer, "%.3e", 1234.5678); + EXPECT_PRINTF("1234.568", "%.3f", 1234.5678); + SPrintf(buffer, "%.3g", 1234.5678); + EXPECT_PRINTF(buffer, "%.3g", 1234.5678); + SPrintf(buffer, "%.3a", 1234.5678); + EXPECT_PRINTF(buffer, "%.3a", 1234.5678); +} + +TEST(PrintfTest, IgnorePrecisionForNonNumericArg) { + EXPECT_PRINTF("abc", "%.5s", "abc"); +} + // TODO: test length and type specifier #endif