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

printf - Update %g formatting to match GNU

This commit is contained in:
Eli Youngs 2022-02-06 14:26:59 -08:00 committed by Sylvestre Ledru
parent ebd0c09549
commit 2afa9cd1a0
2 changed files with 156 additions and 33 deletions

View file

@ -289,7 +289,7 @@ fn sub_num_dec_trunc() {
new_ucmd!()
.args(&["pi is ~ %g", "3.1415926535"])
.succeeds()
.stdout_only("pi is ~ 3.141593");
.stdout_only("pi is ~ 3.14159");
}
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
@ -469,3 +469,67 @@ fn sub_float_leading_zeroes() {
.succeeds()
.stdout_only("001.000000");
}
#[test]
fn sub_general_float() {
new_ucmd!()
.args(&["%g", "1.1"])
.succeeds()
.stdout_only("1.1");
}
#[test]
fn sub_general_truncate_to_integer() {
new_ucmd!()
.args(&["%g", "1.0"])
.succeeds()
.stdout_only("1");
}
#[test]
fn sub_general_prefix_with_spaces() {
new_ucmd!()
.args(&["%5g", "1.1"])
.succeeds()
.stdout_only(" 1.1");
}
#[test]
fn sub_general_large_integer() {
new_ucmd!()
.args(&["%g", "1000000"])
.succeeds()
.stdout_only("1e+06");
}
#[test]
fn sub_general_round_scientific_notation() {
new_ucmd!()
.args(&["%g", "123456789"])
.succeeds()
.stdout_only("1.23457e+08");
}
#[test]
fn sub_general_scientific_leading_zeroes() {
new_ucmd!()
.args(&["%g", "1000010"])
.succeeds()
.stdout_only("1.00001e+06");
}
#[test]
fn sub_general_round_float() {
new_ucmd!()
.args(&["%g", "12345.6789"])
.succeeds()
.stdout_only("12345.7");
}
#[test]
fn sub_general_round_float_to_integer() {
new_ucmd!()
.args(&["%g", "123456.7"])
.succeeds()
.stdout_only("123457");
}