mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #7837 from sargas/add-indexing-to-printf
printf: Add indexing to format strings
This commit is contained in:
commit
606c0c1f57
6 changed files with 568 additions and 127 deletions
|
@ -1281,7 +1281,7 @@ fn float_arg_with_whitespace() {
|
|||
.fails()
|
||||
.stderr_contains("expected a numeric value");
|
||||
|
||||
// A input string with a whitespace special character that has
|
||||
// An input string with a whitespace special character that has
|
||||
// not already been expanded should fail.
|
||||
new_ucmd!()
|
||||
.args(&["%f", "\\t0.1"])
|
||||
|
@ -1313,3 +1313,47 @@ fn mb_input() {
|
|||
.stderr_is(format!("printf: warning: {expected}: character(s) following character constant have been ignored\n"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn positional_format_specifiers() {
|
||||
new_ucmd!()
|
||||
.args(&["%1$d%d-", "5", "10", "6", "20"])
|
||||
.succeeds()
|
||||
.stdout_only("55-1010-66-2020-");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["%2$d%d-", "5", "10", "6", "20"])
|
||||
.succeeds()
|
||||
.stdout_only("105-206-");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["%3$d%d-", "5", "10", "6", "20"])
|
||||
.succeeds()
|
||||
.stdout_only("65-020-");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["%4$d%d-", "5", "10", "6", "20"])
|
||||
.succeeds()
|
||||
.stdout_only("205-");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["%5$d%d-", "5", "10", "6", "20"])
|
||||
.succeeds()
|
||||
.stdout_only("05-");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&[
|
||||
"Octal: %6$o, Int: %1$d, Float: %4$f, String: %2$s, Hex: %7$x, Scientific: %5$e, Char: %9$c, Unsigned: %3$u, Integer: %8$i",
|
||||
"42", // 1$d - Int
|
||||
"hello", // 2$s - String
|
||||
"100", // 3$u - Unsigned
|
||||
"3.14159", // 4$f - Float
|
||||
"0.00001", // 5$e - Scientific
|
||||
"77", // 6$o - Octal
|
||||
"255", // 7$x - Hex
|
||||
"123", // 8$i - Integer
|
||||
"A", // 9$c - Char
|
||||
])
|
||||
.succeeds()
|
||||
.stdout_only("Octal: 115, Int: 42, Float: 3.141590, String: hello, Hex: ff, Scientific: 1.000000e-05, Char: A, Unsigned: 100, Integer: 123");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue