summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authordzwdz2022-09-15 22:36:43 +0200
committerdzwdz2022-09-15 22:36:43 +0200
commit9cf3079b95ad7e995880ec5553372191c73efb0e (patch)
treebf3438188bfc6644812939c4c900d3be67000d0b /src/user
parent15ab70762e4b0a78e6b0186771c726da38629b21 (diff)
shared/printf: properly implement number precision
Diffstat (limited to 'src/user')
-rw-r--r--src/user/app/tests/shared/printf.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/user/app/tests/shared/printf.c b/src/user/app/tests/shared/printf.c
index 4e5ffb8..37b9679 100644
--- a/src/user/app/tests/shared/printf.c
+++ b/src/user/app/tests/shared/printf.c
@@ -23,16 +23,26 @@ static void test_printf(void) {
snprintf(buf, sizeof buf, "%s%%%s", "ab", "cd");
test(!strcmp(buf, "ab%cd"));
- snprintf(buf, sizeof buf, "%05u %05u", 1234, 56789);
- test(!strcmp(buf, "01234 56789"));
-
- snprintf(buf, sizeof buf, "%5d %5d", 123, 4567);
- test(!strcmp(buf, " 123 4567"));
- snprintf(buf, sizeof buf, "%5d %5d", -123, -4567);
- test(!strcmp(buf, " -123 -4567"));
-
- snprintf(buf, sizeof buf, "%u %d %x", 0, 0, 0);
- test(!strcmp(buf, "0 0 0"));
+ snprintf(buf, sizeof buf, "%05u,%05u", 1234, 56789);
+ test(!strcmp(buf, "01234,56789"));
+
+ snprintf(buf, sizeof buf, "%5d,%5d", 123, 4567);
+ test(!strcmp(buf, " 123, 4567"));
+ snprintf(buf, sizeof buf, "%5d,%5d", -123, -4567);
+ test(!strcmp(buf, " -123,-4567"));
+
+ snprintf(buf, sizeof buf, "%u,%d,%x", 0, 0, 0);
+ test(!strcmp(buf, "0,0,0"));
+
+ /* precision */
+ snprintf(buf, sizeof buf, "%5.2u,%5.2d,%5.2x", 0, 0, 0);
+ test(!strcmp(buf, " 00, 00, 00"));
+ snprintf(buf, sizeof buf, "%5.2u,%5.2d,%5.2x", 10, -10, 0x10);
+ test(!strcmp(buf, " 10, -10, 10"));
+ snprintf(buf, sizeof buf, "%5.3d", -1);
+ test(!strcmp(buf, " -001"));
+ snprintf(buf, sizeof buf, "%.5d", 123);
+ test(!strcmp(buf, "00123"));
}
void r_s_printf(void) {