From 6061b67601a076f34dc51497794889cbaeb1a7a6 Mon Sep 17 00:00:00 2001 From: Joseph Jon Booker Date: Thu, 3 Apr 2025 06:36:58 -0500 Subject: [PATCH] printf: add tests for different octal lengths --- tests/by-util/test_printf.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/by-util/test_printf.rs b/tests/by-util/test_printf.rs index 6d7352456..3f9bd8803 100644 --- a/tests/by-util/test_printf.rs +++ b/tests/by-util/test_printf.rs @@ -69,6 +69,21 @@ fn escaped_octal_and_newline() { .stdout_only("\x1F7\n"); } +#[test] +fn variable_sized_octal() { + for x in ["|\\5|", "|\\05|", "|\\005|"] { + new_ucmd!() + .arg(x) + .succeeds() + .stdout_only_bytes([b'|', 5u8, b'|']); + } + + new_ucmd!() + .arg("|\\0005|") + .succeeds() + .stdout_only_bytes([b'|', 0, b'5', b'|']); +} + #[test] fn escaped_unicode_four_digit() { new_ucmd!().args(&["\\u0125"]).succeeds().stdout_only("ĥ"); @@ -148,6 +163,21 @@ fn sub_b_string_handle_escapes() { .stdout_only("hello \tworld"); } +#[test] +fn sub_b_string_variable_size_unicode() { + for x in ["\\5|", "\\05|", "\\005|", "\\0005|"] { + new_ucmd!() + .args(&["|%b", x]) + .succeeds() + .stdout_only_bytes([b'|', 5u8, b'|']); + } + + new_ucmd!() + .args(&["|%b", "\\00005|"]) + .succeeds() + .stdout_only_bytes([b'|', 0, b'5', b'|']); +} + #[test] fn sub_b_string_validate_field_params() { new_ucmd!()