2015-12-24 06:11:00 +00:00
|
|
|
#[macro_use]
|
|
|
|
mod common;
|
|
|
|
|
|
|
|
use common::util::*;
|
|
|
|
|
|
|
|
static UTIL_NAME: &'static str = "printf";
|
|
|
|
|
|
|
|
fn expect_stdout(input: Vec<&str>, expected: &str) {
|
|
|
|
let (_, mut ucmd) = testing(UTIL_NAME);
|
|
|
|
let results = ucmd.args(&input).run();
|
2016-02-15 05:47:02 +00:00
|
|
|
// assert_empty_stderr!(result);
|
|
|
|
// assert!(result.success);
|
|
|
|
assert_eq!(expected, results.stdout);
|
2015-12-24 06:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn basic_literal() {
|
|
|
|
expect_stdout(vec!["hello world"], "hello world");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn escaped_tab() {
|
|
|
|
expect_stdout(vec!["hello\\t world"], "hello\t world");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn escaped_newline() {
|
|
|
|
expect_stdout(vec!["hello\\n world"], "hello\n world");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn escaped_slash() {
|
|
|
|
expect_stdout(vec!["hello\\\\ world"], "hello\\ world");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn escaped_hex() {
|
|
|
|
expect_stdout(vec!["\\x41"], "A");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn escaped_octal() {
|
|
|
|
expect_stdout(vec!["\\101"], "A");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn escaped_unicode_fourdigit() {
|
|
|
|
expect_stdout(vec!["\\u0125"], "ĥ");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn escaped_unicode_eightdigit() {
|
|
|
|
expect_stdout(vec!["\\U00000125"], "ĥ");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn escaped_percent_sign() {
|
|
|
|
expect_stdout(vec!["hello%% world"], "hello% world");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn escaped_unrecognized() {
|
|
|
|
expect_stdout(vec!["c\\d"], "c\\d");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_string() {
|
|
|
|
expect_stdout(vec!["hello %s", "world"], "hello world");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_multifield() {
|
|
|
|
expect_stdout(vec!["%s %s", "hello", "world"], "hello world");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_repeat_formatstr() {
|
|
|
|
expect_stdout(vec!["%s.", "hello", "world"], "hello.world.");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_string_ignore_escapes() {
|
|
|
|
expect_stdout(vec!["hello %s", "\\tworld"], "hello \\tworld");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_bstring_handle_escapes() {
|
|
|
|
expect_stdout(vec!["hello %b", "\\tworld"], "hello \tworld");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_bstring_ignore_subs() {
|
|
|
|
expect_stdout(vec!["hello %b", "world %% %i"], "hello world %% %i");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_char() {
|
|
|
|
expect_stdout(vec!["the letter %c", "A"], "the letter A");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_int() {
|
|
|
|
expect_stdout(vec!["twenty is %i", "20"], "twenty is 20");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_int_minwidth() {
|
|
|
|
expect_stdout(vec!["twenty is %1i", "20"], "twenty is 20");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_int_neg() {
|
|
|
|
expect_stdout(vec!["neg. twenty is %i", "-20"], "neg. twenty is -20");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_int_oct_in() {
|
|
|
|
expect_stdout(vec!["twenty is %i", "024"], "twenty is 20");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_int_oct_in_neg() {
|
|
|
|
expect_stdout(vec!["neg. twenty is %i", "-024"], "neg. twenty is -20");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_int_hex_in() {
|
|
|
|
expect_stdout(vec!["twenty is %i", "0x14"], "twenty is 20");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_int_hex_in_neg() {
|
|
|
|
expect_stdout(vec!["neg. twenty is %i", "-0x14"], "neg. twenty is -20");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_int_charconst_in() {
|
|
|
|
expect_stdout(vec!["ninetyseven is %i", "'a"], "ninetyseven is 97");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_uint() {
|
|
|
|
expect_stdout(vec!["twenty is %u", "20"], "twenty is 20");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_octal() {
|
|
|
|
expect_stdout(vec!["twenty in octal is %o", "20"], "twenty in octal is 24");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_hex_lower() {
|
|
|
|
expect_stdout(vec!["thirty in hex is %x", "30"], "thirty in hex is 1e");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_hex_upper() {
|
|
|
|
expect_stdout(vec!["thirty in hex is %X", "30"], "thirty in hex is 1E");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_float() {
|
|
|
|
expect_stdout(vec!["twenty is %f", "20"], "twenty is 20.000000");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_float_round() {
|
|
|
|
expect_stdout(vec!["two is %f", "1.9999995"], "two is 2.000000");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_sci_lower() {
|
|
|
|
expect_stdout(vec!["twenty is %e", "20"], "twenty is 2.000000e+01");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_sci_upper() {
|
|
|
|
expect_stdout(vec!["twenty is %E", "20"], "twenty is 2.000000E+01");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_sci_trunc() {
|
|
|
|
expect_stdout(vec!["pi is ~ %e", "3.1415926535"], "pi is ~ 3.141593e+00");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_num_dec_trunc() {
|
|
|
|
expect_stdout(vec!["pi is ~ %g", "3.1415926535"], "pi is ~ 3.141593");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
2016-02-15 23:08:37 +00:00
|
|
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
|
|
|
#[test]
|
|
|
|
fn sub_num_hex_float_lower() {
|
|
|
|
expect_stdout(vec!["%a", ".875"], "0xep-4");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
|
|
|
#[test]
|
|
|
|
fn sub_num_hex_float_upper() {
|
|
|
|
expect_stdout(vec!["%A", ".875"], "0XEP-4");
|
|
|
|
}
|
|
|
|
|
2015-12-24 06:11:00 +00:00
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_minwidth() {
|
|
|
|
expect_stdout(vec!["hello %7s", "world"], "hello world");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_minwidth_negative() {
|
|
|
|
expect_stdout(vec!["hello %-7s", "world"], "hello world ");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_str_max_chars_input() {
|
|
|
|
expect_stdout(vec!["hello %7.2s", "world"], "hello wo");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_int_decimal() {
|
|
|
|
expect_stdout(vec!["%0.i", "11"], "11");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_int_leading_zeroes() {
|
|
|
|
expect_stdout(vec!["%.4i", "11"], "0011");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_int_leading_zeroes_prio() {
|
|
|
|
expect_stdout(vec!["%5.4i", "11"], " 0011");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_float_dec_places() {
|
|
|
|
expect_stdout(vec!["pi is ~ %.11f", "3.1415926535"],
|
|
|
|
"pi is ~ 3.14159265350");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_float_hex_in() {
|
|
|
|
expect_stdout(vec!["%f", "0xF1.1F"], "241.121094");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_float_no_octal_in() {
|
|
|
|
expect_stdout(vec!["%f", "077"], "77.000000");
|
|
|
|
}
|
2015-12-24 06:11:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_any_asterisk_firstparam() {
|
|
|
|
expect_stdout(vec!["%*i", "3", "11", "4", "12"], " 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() {
|
|
|
|
expect_stdout(vec!["%.*i", "3", "11", "4", "12"], "0110012");
|
2015-12-24 06:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_any_asterisk_both_params() {
|
|
|
|
expect_stdout(vec!["%*.*i", "4", "3", "11", "5", "4", "12"], " 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() {
|
|
|
|
expect_stdout(vec!["%.*i", "011", "12345678"], "012345678");
|
2015-12-24 06:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_any_asterisk_hex_arg() {
|
|
|
|
expect_stdout(vec!["%.*i", "0xA", "123456789"], "0123456789");
|
2015-12-24 06:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_any_specifiers_no_params() {
|
|
|
|
expect_stdout(vec!["%ztlhLji", "3"], "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() {
|
|
|
|
expect_stdout(vec!["%0ztlhLji", "3"], "3");
|
2015-12-24 06:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-02-15 05:47:02 +00:00
|
|
|
fn sub_any_specifiers_after_period() {
|
|
|
|
expect_stdout(vec!["%0.ztlhLji", "3"], "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() {
|
|
|
|
expect_stdout(vec!["%0.0ztlhLji", "3"], "3");
|
2015-12-24 06:11:00 +00:00
|
|
|
}
|