2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-05-30 05:10:54 +00:00
|
|
|
fn test_to_upper() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["a-z", "A-Z"])
|
|
|
|
.pipe_in("!abcd!")
|
|
|
|
.run()
|
|
|
|
.stdout_is("!ABCD!");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_small_set2() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["0-9", "X"])
|
|
|
|
.pipe_in("@0123456789")
|
|
|
|
.run()
|
|
|
|
.stdout_is("@XXXXXXXXXX");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unicode() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&[", ┬─┬", "╯︵┻━┻"])
|
2020-04-13 18:36:03 +00:00
|
|
|
.pipe_in("(,°□°), ┬─┬")
|
|
|
|
.run()
|
2016-08-13 21:59:21 +00:00
|
|
|
.stdout_is("(╯°□°)╯︵┻━┻");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_delete() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-d", "a-z"])
|
|
|
|
.pipe_in("aBcD")
|
|
|
|
.run()
|
|
|
|
.stdout_is("BD");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_delete_complement() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-d", "-c", "a-z"])
|
|
|
|
.pipe_in("aBcD")
|
|
|
|
.run()
|
|
|
|
.stdout_is("ac");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
2017-08-26 12:26:24 +00:00
|
|
|
|
2021-04-30 18:19:43 +00:00
|
|
|
#[test]
|
|
|
|
fn test_delete_complement_2() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "-C", "0-9"])
|
|
|
|
.pipe_in("Phone: 01234 567890")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("01234567890");
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "--complement", "0-9"])
|
|
|
|
.pipe_in("Phone: 01234 567890")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("01234567890");
|
|
|
|
}
|
|
|
|
|
2021-05-01 16:46:13 +00:00
|
|
|
#[test]
|
|
|
|
fn test_complement1() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "a", "X"])
|
|
|
|
.pipe_in("ab")
|
|
|
|
.run()
|
|
|
|
.stdout_is("aX");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_complement2() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "0-9", "x"])
|
|
|
|
.pipe_in("Phone: 01234 567890")
|
|
|
|
.run()
|
|
|
|
.stdout_is("xxxxxxx01234x567890");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_complement3() {
|
|
|
|
new_ucmd!()
|
2021-05-30 05:10:54 +00:00
|
|
|
.args(&["-c", "abcdefgh", "123"]) // spell-checker:disable-line
|
2021-05-01 16:46:13 +00:00
|
|
|
.pipe_in("the cat and the bat")
|
|
|
|
.run()
|
2021-05-30 05:10:54 +00:00
|
|
|
.stdout_is("3he3ca33a3d33he3ba3"); // spell-checker:disable-line
|
2021-05-01 16:46:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 10:15:16 +00:00
|
|
|
#[test]
|
|
|
|
fn test_complement4() {
|
|
|
|
// $ echo -n '0x1y2z3' | tr -c '0-@' '*-~'
|
|
|
|
// 0~1~2~3
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "0-@", "*-~"])
|
|
|
|
.pipe_in("0x1y2z3")
|
|
|
|
.run()
|
|
|
|
.stdout_is("0~1~2~3");
|
2021-05-02 16:35:52 +00:00
|
|
|
}
|
2021-05-02 10:15:16 +00:00
|
|
|
|
2021-05-02 16:35:52 +00:00
|
|
|
#[test]
|
|
|
|
#[ignore = "fixme: GNU tr returns '0a1b2c3' instead of '0~1~2~3', see #2158"]
|
|
|
|
fn test_complement5() {
|
2021-05-02 10:15:16 +00:00
|
|
|
// $ echo '0x1y2z3' | tr -c '\0-@' '*-~'
|
|
|
|
// 0a1b2c3
|
2021-05-02 16:35:52 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "\\0-@", "*-~"])
|
|
|
|
.pipe_in("0x1y2z3")
|
|
|
|
.run()
|
|
|
|
.stdout_is("0a1b2c3");
|
2021-05-02 10:15:16 +00:00
|
|
|
}
|
|
|
|
|
2017-08-26 12:26:24 +00:00
|
|
|
#[test]
|
|
|
|
fn test_squeeze() {
|
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-s", "a-z"])
|
|
|
|
.pipe_in("aaBBcDcc")
|
|
|
|
.run()
|
|
|
|
.stdout_is("aBBcDc");
|
2017-08-26 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_squeeze_complement() {
|
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-sc", "a-z"])
|
|
|
|
.pipe_in("aaBBcDcc")
|
|
|
|
.run()
|
|
|
|
.stdout_is("aaBcDcc");
|
2017-08-26 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-30 03:13:20 +00:00
|
|
|
#[test]
|
|
|
|
fn test_translate_and_squeeze() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-s", "x", "y"])
|
|
|
|
.pipe_in("xx")
|
|
|
|
.run()
|
|
|
|
.stdout_is("y");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_translate_and_squeeze_multiple_lines() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-s", "x", "y"])
|
2021-05-31 03:55:28 +00:00
|
|
|
.pipe_in("xxaax\nxaaxx") // spell-checker:disable-line
|
2021-04-30 03:13:20 +00:00
|
|
|
.run()
|
2021-05-31 03:55:28 +00:00
|
|
|
.stdout_is("yaay\nyaay"); // spell-checker:disable-line
|
2021-04-30 03:13:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-26 12:26:24 +00:00
|
|
|
#[test]
|
|
|
|
fn test_delete_and_squeeze() {
|
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-ds", "a-z", "A-Z"])
|
|
|
|
.pipe_in("abBcB")
|
|
|
|
.run()
|
|
|
|
.stdout_is("B");
|
2017-08-26 12:26:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_delete_and_squeeze_complement() {
|
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-dsc", "a-z", "A-Z"])
|
|
|
|
.pipe_in("abBcB")
|
|
|
|
.run()
|
|
|
|
.stdout_is("abc");
|
2017-08-26 12:26:24 +00:00
|
|
|
}
|
2017-10-05 22:20:41 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_set1_longer_than_set2() {
|
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["abc", "xy"])
|
|
|
|
.pipe_in("abcde")
|
|
|
|
.run()
|
2021-05-31 03:55:28 +00:00
|
|
|
.stdout_is("xyyde"); // spell-checker:disable-line
|
2017-10-05 22:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_set1_shorter_than_set2() {
|
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["ab", "xyz"])
|
|
|
|
.pipe_in("abcde")
|
|
|
|
.run()
|
2021-05-31 03:55:28 +00:00
|
|
|
.stdout_is("xycde"); // spell-checker:disable-line
|
2017-10-05 22:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_truncate() {
|
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-t", "abc", "xy"])
|
|
|
|
.pipe_in("abcde")
|
|
|
|
.run()
|
2021-05-31 03:55:28 +00:00
|
|
|
.stdout_is("xycde"); // spell-checker:disable-line
|
2017-10-05 22:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_truncate_with_set1_shorter_than_set2() {
|
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-t", "ab", "xyz"])
|
|
|
|
.pipe_in("abcde")
|
|
|
|
.run()
|
2021-05-31 03:55:28 +00:00
|
|
|
.stdout_is("xycde"); // spell-checker:disable-line
|
2017-10-05 22:20:41 +00:00
|
|
|
}
|
2020-10-02 20:43:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn missing_args_fails() {
|
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.fails().stderr_contains("missing operand");
|
2020-10-02 20:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn missing_required_second_arg_fails() {
|
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
2021-04-22 20:37:44 +00:00
|
|
|
ucmd.args(&["foo"])
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("missing operand after");
|
2020-10-02 20:43:57 +00:00
|
|
|
}
|
2021-03-16 13:42:06 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_interpret_backslash_escapes() {
|
|
|
|
new_ucmd!()
|
2021-05-31 03:55:28 +00:00
|
|
|
.args(&["abfnrtv", r"\a\b\f\n\r\t\v"]) // spell-checker:disable-line
|
|
|
|
.pipe_in("abfnrtv") // spell-checker:disable-line
|
2021-03-16 13:42:06 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\u{7}\u{8}\u{c}\n\r\t\u{b}");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_interpret_unrecognized_backslash_escape_as_character() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["qcz+=~-", r"\q\c\z\+\=\~\-"])
|
|
|
|
.pipe_in("qcz+=~-")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("qcz+=~-");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_interpret_single_octal_escape() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["X", r"\015"])
|
|
|
|
.pipe_in("X")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\r");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_interpret_one_and_two_digit_octal_escape() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["XYZ", r"\0\11\77"])
|
|
|
|
.pipe_in("XYZ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\0\t?");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_octal_escape_is_at_most_three_digits() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["XY", r"\0156"])
|
|
|
|
.pipe_in("XY")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\r6");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_non_octal_digit_ends_escape() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["rust", r"\08\11956"])
|
|
|
|
.pipe_in("rust")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\08\t9");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_interpret_backslash_at_eol_literally() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["X", r"\"])
|
|
|
|
.pipe_in("X")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("\\");
|
|
|
|
}
|