1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

printf: fix padding and prefixes for unsigned ints

This commit is contained in:
Terts Diepraam 2024-02-07 16:14:12 +01:00 committed by Daniel Hofstetter
parent 4dae902429
commit 3126e5f8a1
2 changed files with 42 additions and 34 deletions

View file

@ -668,7 +668,7 @@ fn sub_alternative_upper_hex() {
new_ucmd!()
.args(&["%#X", "42"])
.succeeds()
.stdout_only("0x2A");
.stdout_only("0X2A");
}
#[test]
@ -708,3 +708,31 @@ fn pad_octal_with_prefix() {
.succeeds()
.stdout_only("> 0123456<");
}
#[test]
fn pad_unsigned_zeroes() {
for format in ["%.3u", "%.3x", "%.3X", "%.3o"] {
new_ucmd!()
.args(&[format, "0"])
.succeeds()
.stdout_only("000");
}
}
#[test]
fn pad_unsigned_three() {
for (format, expected) in [
("%.3u", "003"),
("%.3x", "003"),
("%.3X", "003"),
("%.3o", "003"),
("%#.3x", "0x003"),
("%#.3X", "0X003"),
("%#.3o", "003"),
] {
new_ucmd!()
.args(&[format, "3"])
.succeeds()
.stdout_only(expected);
}
}