2015-11-16 05:25:01 +00:00
|
|
|
use common::util::*;
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_default() {
|
2016-08-11 18:59:10 +00:00
|
|
|
//CmdResult.stdout_only(...) trims trailing newlines
|
2016-08-23 11:52:43 +00:00
|
|
|
assert_eq!("hi\n", new_ucmd!().arg("hi").succeeds().no_stderr().stdout);
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_no_trailing_newline() {
|
2016-08-11 18:59:10 +00:00
|
|
|
//CmdResult.stdout_only(...) trims trailing newlines
|
2016-08-23 11:52:43 +00:00
|
|
|
assert_eq!("hi", new_ucmd!().arg("-n").arg("hi").succeeds().no_stderr().stdout);
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-08-11 18:59:10 +00:00
|
|
|
fn test_escape_alert() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\a"]).succeeds().stdout_only("\x07\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_backslash() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\\\"]).succeeds().stdout_only("\\\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_backspace() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\b"]).succeeds().stdout_only("\x08\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_carriage_return() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\r"]).succeeds().stdout_only("\r\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_escape() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\e"]).succeeds().stdout_only("\x1B\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_form_feed() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\f"]).succeeds().stdout_only("\x0C\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_hex() {
|
2019-02-07 20:54:48 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\x41"]).succeeds().stdout_only("A\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 22:55:48 +00:00
|
|
|
#[test]
|
|
|
|
fn test_escape_short_hex() {
|
|
|
|
new_ucmd!().args(&["-e", "foo\\xa bar"]).succeeds().stdout_only("foo\n bar");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_no_hex() {
|
|
|
|
new_ucmd!().args(&["-e", "foo\\x bar"]).succeeds().stdout_only("foo\\x bar");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_one_slash() {
|
|
|
|
new_ucmd!().args(&["-e", "foo\\ bar"]).succeeds().stdout_only("foo\\ bar");
|
|
|
|
}
|
|
|
|
|
2016-08-11 18:59:10 +00:00
|
|
|
#[test]
|
|
|
|
fn test_escape_newline() {
|
2019-02-07 20:54:48 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\na"]).succeeds().stdout_only("\na\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_no_further_output() {
|
2019-04-05 22:55:48 +00:00
|
|
|
new_ucmd!().args(&["-e", "a\\cb", "c"]).succeeds().stdout_only("a\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_octal() {
|
2019-02-07 20:54:48 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\0100"]).succeeds().stdout_only("@\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 22:55:48 +00:00
|
|
|
#[test]
|
|
|
|
fn test_escape_short_octal() {
|
|
|
|
new_ucmd!().args(&["-e", "foo\\040bar"]).succeeds().stdout_only("foo bar");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_no_octal() {
|
|
|
|
new_ucmd!().args(&["-e", "foo\\0 bar"]).succeeds().stdout_only("foo\\0 bar");
|
|
|
|
}
|
|
|
|
|
2016-08-11 18:59:10 +00:00
|
|
|
#[test]
|
|
|
|
fn test_escape_tab() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\t"]).succeeds().stdout_only("\t\n");
|
2016-08-11 18:59:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_escape_vertical_tab() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().args(&["-e", "\\v"]).succeeds().stdout_only("\x0B\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_disable_escapes() {
|
2016-08-11 18:59:10 +00:00
|
|
|
let input_str = "\\a \\\\ \\b \\r \\e \\f \\x41 \\n a\\cb \\u0100 \\t \\v";
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.arg("-E")
|
2016-08-11 18:59:10 +00:00
|
|
|
.arg(input_str)
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only(format!("{}\n", input_str));
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|