Skip to content

Commit fce9f79

Browse files
committed
tests: printf: Add more cases around 0, missing digits, etc.
1 parent a4c56fb commit fce9f79

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

tests/by-util/test_printf.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,12 @@ fn partial_integer() {
826826
.fails_with_code(1)
827827
.stdout_is("42 is a lot")
828828
.stderr_is("printf: '42x23': value not completely converted\n");
829+
830+
new_ucmd!()
831+
.args(&["%d is not %s", "0xwa", "a lot"])
832+
.fails_with_code(1)
833+
.stdout_is("0 is not a lot")
834+
.stderr_is("printf: '0xwa': value not completely converted\n");
829835
}
830836

831837
#[test]
@@ -1280,6 +1286,80 @@ fn float_switch_switch_decimal_scientific() {
12801286
.stdout_only("1e-05");
12811287
}
12821288

1289+
#[test]
1290+
fn float_arg_zero() {
1291+
new_ucmd!()
1292+
.args(&["%f", "0."])
1293+
.succeeds()
1294+
.stdout_only("0.000000");
1295+
1296+
new_ucmd!()
1297+
.args(&["%f", ".0"])
1298+
.succeeds()
1299+
.stdout_only("0.000000");
1300+
1301+
new_ucmd!()
1302+
.args(&["%f", ".0e100000"])
1303+
.succeeds()
1304+
.stdout_only("0.000000");
1305+
}
1306+
1307+
#[test]
1308+
fn float_arg_invalid() {
1309+
// Just a dot fails.
1310+
new_ucmd!()
1311+
.args(&["%f", "."])
1312+
.fails()
1313+
.stdout_is("0.000000")
1314+
.stderr_contains("expected a numeric value");
1315+
1316+
new_ucmd!()
1317+
.args(&["%f", "-."])
1318+
.fails()
1319+
.stdout_is("0.000000")
1320+
.stderr_contains("expected a numeric value");
1321+
1322+
// Just an exponent indicator fails.
1323+
new_ucmd!()
1324+
.args(&["%f", "e"])
1325+
.fails()
1326+
.stdout_is("0.000000")
1327+
.stderr_contains("expected a numeric value");
1328+
1329+
// No digit but only exponent fails
1330+
new_ucmd!()
1331+
.args(&["%f", ".e12"])
1332+
.fails()
1333+
.stdout_is("0.000000")
1334+
.stderr_contains("expected a numeric value");
1335+
1336+
// No exponent partially fails
1337+
new_ucmd!()
1338+
.args(&["%f", "123e"])
1339+
.fails()
1340+
.stdout_is("123.000000")
1341+
.stderr_contains("value not completely converted");
1342+
1343+
// Nothing past `0x` parses as zero
1344+
new_ucmd!()
1345+
.args(&["%f", "0x"])
1346+
.fails()
1347+
.stdout_is("0.000000")
1348+
.stderr_contains("value not completely converted");
1349+
1350+
new_ucmd!()
1351+
.args(&["%f", "0x."])
1352+
.fails()
1353+
.stdout_is("0.000000")
1354+
.stderr_contains("value not completely converted");
1355+
1356+
new_ucmd!()
1357+
.args(&["%f", "0xp12"])
1358+
.fails()
1359+
.stdout_is("0.000000")
1360+
.stderr_contains("value not completely converted");
1361+
}
1362+
12831363
#[test]
12841364
fn float_arg_with_whitespace() {
12851365
new_ucmd!()

0 commit comments

Comments
 (0)