mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
printf: simplify and dedup some tests
This commit is contained in:
parent
8ff0db1db9
commit
e5980d4d2a
1 changed files with 20 additions and 117 deletions
|
@ -16,40 +16,6 @@ fn basic_literal() {
|
||||||
.stdout_only("hello world");
|
.stdout_only("hello world");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn escaped_tab() {
|
|
||||||
new_ucmd!()
|
|
||||||
.args(&["hello\\t world"])
|
|
||||||
.succeeds()
|
|
||||||
.stdout_only("hello\t world");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn escaped_newline() {
|
|
||||||
new_ucmd!()
|
|
||||||
.args(&["hello\\n world"])
|
|
||||||
.succeeds()
|
|
||||||
.stdout_only("hello\n world");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn escaped_slash() {
|
|
||||||
new_ucmd!()
|
|
||||||
.args(&["hello\\\\ world"])
|
|
||||||
.succeeds()
|
|
||||||
.stdout_only("hello\\ world");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn unescaped_double_quote() {
|
|
||||||
new_ucmd!().args(&["\\\""]).succeeds().stdout_only("\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn escaped_hex() {
|
|
||||||
new_ucmd!().args(&["\\x41"]).succeeds().stdout_only("A");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_missing_escaped_hex_value() {
|
fn test_missing_escaped_hex_value() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
@ -58,17 +24,12 @@ fn test_missing_escaped_hex_value() {
|
||||||
.stderr_only("printf: missing hexadecimal number in escape\n");
|
.stderr_only("printf: missing hexadecimal number in escape\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn escaped_octal() {
|
|
||||||
new_ucmd!().args(&["\\101"]).succeeds().stdout_only("A");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn escaped_octal_and_newline() {
|
fn escaped_octal_and_newline() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["\\0377\\n"])
|
.args(&["\\101\\0377\\n"])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only("\x1F7\n");
|
.stdout_only("A\x1F7\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -145,38 +106,6 @@ fn escaped_unrecognized() {
|
||||||
new_ucmd!().args(&["c\\d"]).succeeds().stdout_only("c\\d");
|
new_ucmd!().args(&["c\\d"]).succeeds().stdout_only("c\\d");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sub_string() {
|
|
||||||
new_ucmd!()
|
|
||||||
.args(&["hello %s", "world"])
|
|
||||||
.succeeds()
|
|
||||||
.stdout_only("hello world");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sub_multi_field() {
|
|
||||||
new_ucmd!()
|
|
||||||
.args(&["%s %s", "hello", "world"])
|
|
||||||
.succeeds()
|
|
||||||
.stdout_only("hello world");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sub_repeat_format_str() {
|
|
||||||
new_ucmd!()
|
|
||||||
.args(&["%s.", "hello", "world"])
|
|
||||||
.succeeds()
|
|
||||||
.stdout_only("hello.world.");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sub_string_ignore_escapes() {
|
|
||||||
new_ucmd!()
|
|
||||||
.args(&["hello %s", "\\tworld"])
|
|
||||||
.succeeds()
|
|
||||||
.stdout_only("hello \\tworld");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sub_b_string_handle_escapes() {
|
fn sub_b_string_handle_escapes() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
@ -705,27 +634,11 @@ fn sub_any_asterisk_second_param_with_integer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sub_any_specifiers_no_params() {
|
fn sub_any_specifiers() {
|
||||||
new_ucmd!()
|
// spell-checker:disable-next-line
|
||||||
.args(&["%ztlhLji", "3"]) //spell-checker:disable-line
|
for format in ["%ztlhLji", "%0ztlhLji", "%0.ztlhLji"] {
|
||||||
.succeeds()
|
new_ucmd!().args(&[format, "3"]).succeeds().stdout_only("3");
|
||||||
.stdout_only("3");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sub_any_specifiers_after_first_param() {
|
|
||||||
new_ucmd!()
|
|
||||||
.args(&["%0ztlhLji", "3"]) //spell-checker:disable-line
|
|
||||||
.succeeds()
|
|
||||||
.stdout_only("3");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn sub_any_specifiers_after_period() {
|
|
||||||
new_ucmd!()
|
|
||||||
.args(&["%0.ztlhLji", "3"]) //spell-checker:disable-line
|
|
||||||
.succeeds()
|
|
||||||
.stdout_only("3");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1027,33 +940,23 @@ fn pad_string() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn format_spec_zero_char_fails() {
|
fn format_spec_zero_fails() {
|
||||||
// It is invalid to have the format spec '%0c'
|
// It is invalid to have the format spec
|
||||||
new_ucmd!().args(&["%0c", "3"]).fails_with_code(1);
|
for format in ["%0c", "%0s"] {
|
||||||
|
new_ucmd!().args(&[format, "3"]).fails_with_code(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn format_spec_zero_string_fails() {
|
fn invalid_precision_tests() {
|
||||||
// It is invalid to have the format spec '%0s'
|
|
||||||
new_ucmd!().args(&["%0s", "3"]).fails_with_code(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn invalid_precision_fails() {
|
|
||||||
// It is invalid to have length of output string greater than i32::MAX
|
// It is invalid to have length of output string greater than i32::MAX
|
||||||
|
for format in ["%.*d", "%.*f"] {
|
||||||
|
let expected_error = "printf: invalid precision: '2147483648'\n";
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["%.*d", "2147483648", "0"])
|
.args(&[format, "2147483648", "0"])
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_is("printf: invalid precision: '2147483648'\n");
|
.stderr_is(expected_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn float_invalid_precision_fails() {
|
|
||||||
// It is invalid to have length of output string greater than i32::MAX
|
|
||||||
new_ucmd!()
|
|
||||||
.args(&["%.*f", "2147483648", "0"])
|
|
||||||
.fails()
|
|
||||||
.stderr_is("printf: invalid precision: '2147483648'\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following padding-tests test for the cases in which flags in ['0', ' '] are given.
|
// The following padding-tests test for the cases in which flags in ['0', ' '] are given.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue