mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #5811 from spineki/fix-printf-hex-alternate-zero
Printf: Fix printf hex alternate zero
This commit is contained in:
commit
3bd9f0ec65
2 changed files with 36 additions and 2 deletions
|
@ -156,13 +156,21 @@ impl Formatter for UnsignedInt {
|
||||||
format!("{x:x}")
|
format!("{x:x}")
|
||||||
}
|
}
|
||||||
UnsignedIntVariant::Hexadecimal(Case::Lowercase, Prefix::Yes) => {
|
UnsignedIntVariant::Hexadecimal(Case::Lowercase, Prefix::Yes) => {
|
||||||
format!("{x:#x}")
|
if x == 0 {
|
||||||
|
"0".to_string()
|
||||||
|
} else {
|
||||||
|
format!("{x:#x}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
UnsignedIntVariant::Hexadecimal(Case::Uppercase, Prefix::No) => {
|
UnsignedIntVariant::Hexadecimal(Case::Uppercase, Prefix::No) => {
|
||||||
format!("{x:X}")
|
format!("{x:X}")
|
||||||
}
|
}
|
||||||
UnsignedIntVariant::Hexadecimal(Case::Uppercase, Prefix::Yes) => {
|
UnsignedIntVariant::Hexadecimal(Case::Uppercase, Prefix::Yes) => {
|
||||||
format!("{x:#X}")
|
if x == 0 {
|
||||||
|
"0".to_string()
|
||||||
|
} else {
|
||||||
|
format!("{x:#X}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -645,6 +645,32 @@ fn partial_char() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sub_alternative_lower_hex_0() {
|
||||||
|
new_ucmd!().args(&["%#x", "0"]).succeeds().stdout_only("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sub_alternative_lower_hex() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["%#x", "42"])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only("0x2a");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sub_alternative_upper_hex_0() {
|
||||||
|
new_ucmd!().args(&["%#X", "0"]).succeeds().stdout_only("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sub_alternative_upper_hex() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["%#X", "42"])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only("0x2A");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn char_as_byte() {
|
fn char_as_byte() {
|
||||||
new_ucmd!().args(&["%c", "🙃"]).succeeds().stdout_only("ð");
|
new_ucmd!().args(&["%c", "🙃"]).succeeds().stdout_only("ð");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue