2
0
Fork 0
mirror of https://github.com/uutils/coreutils synced 2024-12-22 11:03:12 +00:00
coreutils/tests/by-util/test_printf.rs

432 lines
8.1 KiB
Rust
Raw Normal View History

use crate::common::util::*;
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn basic_literal() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello world"])
.succeeds()
.stdout_only("hello world");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn escaped_tab() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello\\t world"])
.succeeds()
.stdout_only("hello\t world");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn escaped_newline() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello\\n world"])
.succeeds()
.stdout_only("hello\n world");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn escaped_slash() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello\\\\ world"])
.succeeds()
.stdout_only("hello\\ world");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn escaped_hex() {
new_ucmd!().args(&["\\x41"]).succeeds().stdout_only("A");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn escaped_octal() {
new_ucmd!().args(&["\\101"]).succeeds().stdout_only("A");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn escaped_unicode_fourdigit() {
new_ucmd!().args(&["\\u0125"]).succeeds().stdout_only("ĥ");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn escaped_unicode_eightdigit() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["\\U00000125"])
.succeeds()
.stdout_only("ĥ");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn escaped_percent_sign() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello%% world"])
.succeeds()
.stdout_only("hello% world");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn escaped_unrecognized() {
new_ucmd!().args(&["c\\d"]).succeeds().stdout_only("c\\d");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_string() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello %s", "world"])
.succeeds()
.stdout_only("hello world");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_multifield() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%s %s", "hello", "world"])
.succeeds()
.stdout_only("hello world");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_repeat_formatstr() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%s.", "hello", "world"])
.succeeds()
.stdout_only("hello.world.");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_string_ignore_escapes() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello %s", "\\tworld"])
.succeeds()
.stdout_only("hello \\tworld");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_bstring_handle_escapes() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello %b", "\\tworld"])
.succeeds()
.stdout_only("hello \tworld");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_bstring_ignore_subs() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello %b", "world %% %i"])
.succeeds()
.stdout_only("hello world %% %i");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_char() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["the letter %c", "A"])
.succeeds()
.stdout_only("the letter A");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_int() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["twenty is %i", "20"])
.succeeds()
.stdout_only("twenty is 20");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_int_minwidth() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["twenty is %1i", "20"])
.succeeds()
.stdout_only("twenty is 20");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_int_neg() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["neg. twenty is %i", "-20"])
.succeeds()
.stdout_only("neg. twenty is -20");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_int_oct_in() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["twenty is %i", "024"])
.succeeds()
.stdout_only("twenty is 20");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_int_oct_in_neg() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["neg. twenty is %i", "-024"])
.succeeds()
.stdout_only("neg. twenty is -20");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_int_hex_in() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["twenty is %i", "0x14"])
.succeeds()
.stdout_only("twenty is 20");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_int_hex_in_neg() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["neg. twenty is %i", "-0x14"])
.succeeds()
.stdout_only("neg. twenty is -20");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_int_charconst_in() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["ninetyseven is %i", "'a"])
.succeeds()
.stdout_only("ninetyseven is 97");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_uint() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["twenty is %u", "20"])
.succeeds()
.stdout_only("twenty is 20");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_octal() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["twenty in octal is %o", "20"])
.succeeds()
.stdout_only("twenty in octal is 24");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_hex_lower() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["thirty in hex is %x", "30"])
.succeeds()
.stdout_only("thirty in hex is 1e");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_hex_upper() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["thirty in hex is %X", "30"])
.succeeds()
.stdout_only("thirty in hex is 1E");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_float() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["twenty is %f", "20"])
.succeeds()
.stdout_only("twenty is 20.000000");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_float_round() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["two is %f", "1.9999995"])
.succeeds()
.stdout_only("two is 2.000000");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_sci_lower() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["twenty is %e", "20"])
.succeeds()
.stdout_only("twenty is 2.000000e+01");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_sci_upper() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["twenty is %E", "20"])
.succeeds()
.stdout_only("twenty is 2.000000E+01");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_sci_trunc() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["pi is ~ %e", "3.1415926535"])
.succeeds()
.stdout_only("pi is ~ 3.141593e+00");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_num_dec_trunc() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["pi is ~ %g", "3.1415926535"])
.succeeds()
.stdout_only("pi is ~ 3.141593");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
2020-04-13 18:36:03 +00:00
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn sub_num_hex_float_lower() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%a", ".875"])
.succeeds()
.stdout_only("0xep-4");
}
2020-04-13 18:36:03 +00:00
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test]
fn sub_num_hex_float_upper() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%A", ".875"])
.succeeds()
.stdout_only("0XEP-4");
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_minwidth() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello %7s", "world"])
.succeeds()
.stdout_only("hello world");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_minwidth_negative() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello %-7s", "world"])
.succeeds()
.stdout_only("hello world ");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_str_max_chars_input() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["hello %7.2s", "world"])
.succeeds()
.stdout_only("hello wo");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_int_decimal() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%0.i", "11"])
.succeeds()
.stdout_only("11");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_int_leading_zeroes() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%.4i", "11"])
.succeeds()
.stdout_only("0011");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_int_leading_zeroes_prio() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%5.4i", "11"])
.succeeds()
.stdout_only(" 0011");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_float_dec_places() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["pi is ~ %.11f", "3.1415926535"])
.succeeds()
.stdout_only("pi is ~ 3.14159265350");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_float_hex_in() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%f", "0xF1.1F"])
.succeeds()
.stdout_only("241.121094");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_float_no_octal_in() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%f", "077"])
.succeeds()
.stdout_only("77.000000");
2016-02-15 05:47:02 +00:00
}
2015-12-24 06:11:00 +00:00
#[test]
2016-02-15 05:47:02 +00:00
fn sub_any_asterisk_firstparam() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%*i", "3", "11", "4", "12"])
.succeeds()
.stdout_only(" 11 12");
2015-12-24 06:11:00 +00:00
}
#[test]
2016-02-15 05:47:02 +00:00
fn sub_any_asterisk_second_param() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%.*i", "3", "11", "4", "12"])
.succeeds()
.stdout_only("0110012");
2015-12-24 06:11:00 +00:00
}
#[test]
2016-02-15 05:47:02 +00:00
fn sub_any_asterisk_both_params() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%*.*i", "4", "3", "11", "5", "4", "12"])
.succeeds()
.stdout_only(" 011 0012");
2015-12-24 06:11:00 +00:00
}
#[test]
2016-02-15 05:47:02 +00:00
fn sub_any_asterisk_octal_arg() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%.*i", "011", "12345678"])
.succeeds()
.stdout_only("012345678");
2015-12-24 06:11:00 +00:00
}
#[test]
2016-02-15 05:47:02 +00:00
fn sub_any_asterisk_hex_arg() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%.*i", "0xA", "123456789"])
.succeeds()
.stdout_only("0123456789");
2015-12-24 06:11:00 +00:00
}
#[test]
2016-02-15 05:47:02 +00:00
fn sub_any_specifiers_no_params() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%ztlhLji", "3"])
.succeeds()
.stdout_only("3");
2015-12-24 06:11:00 +00:00
}
#[test]
2016-02-15 05:47:02 +00:00
fn sub_any_specifiers_after_first_param() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%0ztlhLji", "3"])
.succeeds()
.stdout_only("3");
2015-12-24 06:11:00 +00:00
}
#[test]
2016-02-15 05:47:02 +00:00
fn sub_any_specifiers_after_period() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%0.ztlhLji", "3"])
.succeeds()
.stdout_only("3");
2015-12-24 06:11:00 +00:00
}
#[test]
2016-02-15 05:47:02 +00:00
fn sub_any_specifiers_after_second_param() {
2020-04-13 18:36:03 +00:00
new_ucmd!()
.args(&["%0.0ztlhLji", "3"])
.succeeds()
.stdout_only("3");
2015-12-24 06:11:00 +00:00
}