From 5d74a6e002e49eaed5c550a5d5ce9764906930c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20P=C3=A9ron?= Date: Thu, 29 Feb 2024 00:43:47 +0100 Subject: [PATCH] tests/printf: Fix char_as_byte test, add char and string padding tests --- tests/by-util/test_printf.rs | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_printf.rs b/tests/by-util/test_printf.rs index 46340c28e..531e527bc 100644 --- a/tests/by-util/test_printf.rs +++ b/tests/by-util/test_printf.rs @@ -673,7 +673,11 @@ fn sub_alternative_upper_hex() { #[test] fn char_as_byte() { - new_ucmd!().args(&["%c", "🙃"]).succeeds().stdout_only("ð"); + new_ucmd!() + .args(&["%c", "🙃"]) + .succeeds() + .no_stderr() + .stdout_is_bytes(b"\xf0"); } #[test] @@ -736,3 +740,34 @@ fn pad_unsigned_three() { .stdout_only(expected); } } + +#[test] +fn pad_char() { + for (format, expected) in [ + ("%3c", " X"), + ("%1c", "X"), + ("%-1c", "X"), + ("%-3c", "X "), + ] { + new_ucmd!() + .args(&[format, "X"]) + .succeeds() + .stdout_only(expected); + } +} + + +#[test] +fn pad_string() { + for (format, expected) in [ + ("%8s", " bottle"), + ("%-8s", "bottle "), + ("%6s", "bottle"), + ("%-6s", "bottle"), + ] { + new_ucmd!() + .args(&[format, "bottle"]) + .succeeds() + .stdout_only(expected); + } +} \ No newline at end of file