[PATCH v2 2/2] selftests/nolibc: add tests for printf left alignment and zero padding

licheng.li posted 2 patches 1 week, 4 days ago
[PATCH v2 2/2] selftests/nolibc: add tests for printf left alignment and zero padding
Posted by licheng.li 1 week, 4 days ago
From: Cheng Li <im.lechain@gmail.com>

This patch adds validation for the recently added left-alignment ('-')
and zero-padding ('0') flags in printf().

It ensures that:
 - Fields are correctly padded with spaces on the right when the '-'
   flag is used.
 - Integers are correctly padded with zeroes on the left when the '0'
   flag is used.

Signed-off-by: Cheng Li <im.lechain@gmail.com>
---
v2 changes:
 - Added test cases for zero padding (%08d)
---
 tools/testing/selftests/nolibc/nolibc-test.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 3c5a226dad3a..47b20ecf5242 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1723,6 +1723,8 @@ static int run_printf(int min, int max)
 		CASE_TEST(truncation);   EXPECT_VFPRINTF(25, "01234567890123456789", "%s", "0123456789012345678901234"); break;
 		CASE_TEST(string_width); EXPECT_VFPRINTF(10, "         1", "%10s", "1"); break;
 		CASE_TEST(number_width); EXPECT_VFPRINTF(10, "         1", "%10d", 1); break;
+		CASE_TEST(leading_zero); EXPECT_VFPRINTF(10, "|00000001|", "|%08d|", 1); break;
+		CASE_TEST(left_align);   EXPECT_VFPRINTF(10, "|foo     |", "|%-8s|", "foo"); break;
 		CASE_TEST(width_trunc);  EXPECT_VFPRINTF(25, "                    ", "%25d", 1); break;
 		CASE_TEST(scanf);        EXPECT_ZR(1, test_scanf()); break;
 		CASE_TEST(strerror);     EXPECT_ZR(1, test_strerror()); break;
-- 
2.52.0