2023-08-21 08:49:27 +00:00
|
|
|
// This file is part of the uutils coreutils package.
|
|
|
|
//
|
|
|
|
// For the full copyright and license information, please view the LICENSE
|
|
|
|
// file that was distributed with this source code.
|
2024-02-23 02:12:30 +00:00
|
|
|
// spell-checker:ignore aabbaa aabbcc aabc abbb abbbcddd abcc abcdefabcdef abcdefghijk abcdefghijklmn abcdefghijklmnop ABCDEFGHIJKLMNOPQRS abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFZZ abcxyz ABCXYZ abcxyzabcxyz ABCXYZABCXYZ acbdef alnum amzamz AMZXAMZ bbbd cclass cefgm cntrl compl dabcdef dncase Gzabcdefg PQRST upcase wxyzz xdigit XXXYYY xycde xyyye xyyz xyzzzzxyzzzz ZABCDEF Zamz Cdefghijkl Cdefghijklmn
|
2023-03-20 13:51:19 +00:00
|
|
|
use crate::common::util::TestScenario;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2022-09-10 16:38:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_invalid_arg() {
|
|
|
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
|
|
|
}
|
|
|
|
|
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]
|
2023-12-11 12:35:17 +00:00
|
|
|
fn test_invalid_unicode() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2023-12-11 12:35:17 +00:00
|
|
|
.args(&["-dc", "abc"])
|
|
|
|
.pipe_in([0o200, b'a', b'b', b'c'])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abc");
|
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");
|
|
|
|
}
|
|
|
|
|
2024-02-23 01:15:53 +00:00
|
|
|
#[test]
|
|
|
|
fn test_complement_afterwards_is_not_flag() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["a", "X", "-c"])
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("extra operand '-c'");
|
|
|
|
}
|
|
|
|
|
2021-05-01 16:46:13 +00:00
|
|
|
#[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]
|
|
|
|
fn test_complement5() {
|
2021-07-21 12:07:55 +00:00
|
|
|
// $ echo -n '0x1y2z3' | tr -c '\0-@' '*-~'
|
2021-05-02 10:15:16 +00:00
|
|
|
// 0a1b2c3
|
2021-05-02 16:35:52 +00:00
|
|
|
new_ucmd!()
|
2021-08-01 02:43:28 +00:00
|
|
|
.args(&["-c", r"\0-@", "*-~"])
|
2021-05-02 16:35:52 +00:00
|
|
|
.pipe_in("0x1y2z3")
|
|
|
|
.run()
|
|
|
|
.stdout_is("0a1b2c3");
|
2021-05-02 10:15:16 +00:00
|
|
|
}
|
|
|
|
|
2024-02-23 01:13:21 +00:00
|
|
|
#[test]
|
|
|
|
fn test_complement_multi_early() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "-c", "a", "X"])
|
|
|
|
.pipe_in("ab")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("aX");
|
|
|
|
}
|
|
|
|
|
2024-02-23 01:15:53 +00:00
|
|
|
#[test]
|
|
|
|
fn test_complement_multi_middle() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "a", "-c", "X"])
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("tr: extra operand 'X'");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_complement_multi_late() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "a", "X", "-c"])
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("tr: extra operand '-c'");
|
|
|
|
}
|
|
|
|
|
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-07-09 20:55:00 +00:00
|
|
|
#[test]
|
|
|
|
fn test_squeeze_complement_two_sets() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-sc", "a", "_"])
|
|
|
|
.pipe_in("test a aa with 3 ___ spaaaces +++") // spell-checker:disable-line
|
|
|
|
.run()
|
|
|
|
.stdout_is("_a_aa_aaa_");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-02-23 01:59:32 +00:00
|
|
|
#[test]
|
|
|
|
fn test_delete_and_squeeze_one_set() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-ds", "a-z"])
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("missing operand after 'a-z'")
|
|
|
|
.stderr_contains("Two strings must be given when deleting and squeezing.");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2024-02-23 02:12:30 +00:00
|
|
|
#[test]
|
|
|
|
fn test_delete_and_squeeze_complement_squeeze_set2() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-dsc", "abX", "XYZ"])
|
|
|
|
.pipe_in("abbbcdddXXXYYY")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abbbX");
|
|
|
|
}
|
|
|
|
|
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() {
|
2021-07-24 14:06:27 +00:00
|
|
|
// echo -n "abcde" | tr -t "abc" "xy"
|
2017-10-05 22:20:41 +00:00
|
|
|
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("\\");
|
|
|
|
}
|
2021-07-09 15:51:37 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_more_than_2_sets() {
|
2022-01-19 21:27:34 +00:00
|
|
|
new_ucmd!().args(&["'abcdef'", "'a'", "'b'"]).fails();
|
2021-07-09 15:51:37 +00:00
|
|
|
}
|
2021-07-14 16:04:43 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-07-20 07:55:58 +00:00
|
|
|
fn basic_translation_works() {
|
|
|
|
// echo -n "abcdefabcdef" | tr "dabcdef" "xyz"
|
2021-07-14 16:04:43 +00:00
|
|
|
new_ucmd!()
|
2021-07-20 07:55:58 +00:00
|
|
|
.args(&["abcdef", "xyz"])
|
2021-07-14 16:04:43 +00:00
|
|
|
.pipe_in("abcdefabcdef")
|
|
|
|
.succeeds()
|
2021-07-20 07:55:58 +00:00
|
|
|
.stdout_is("xyzzzzxyzzzz");
|
2021-07-14 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-07-20 07:55:58 +00:00
|
|
|
fn alnum_overrides_translation_to_fallback_1() {
|
|
|
|
// echo -n "abcdefghijklmnopqrstuvwxyz" | tr "abc[:alpha:]" "xyz"
|
2021-07-14 16:04:43 +00:00
|
|
|
new_ucmd!()
|
2021-07-20 07:55:58 +00:00
|
|
|
.args(&["abc[:alpha:]", "xyz"])
|
|
|
|
.pipe_in("abcdefghijklmnopqrstuvwxyz")
|
2021-07-14 16:04:43 +00:00
|
|
|
.succeeds()
|
2021-07-20 07:55:58 +00:00
|
|
|
.stdout_is("zzzzzzzzzzzzzzzzzzzzzzzzzz");
|
2021-07-14 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-07-20 07:55:58 +00:00
|
|
|
fn alnum_overrides_translation_to_fallback_2() {
|
|
|
|
// echo -n "abcdefghijklmnopqrstuvwxyz" | tr "[:alpha:]abc" "xyz"
|
2021-07-14 16:04:43 +00:00
|
|
|
new_ucmd!()
|
2021-07-20 07:55:58 +00:00
|
|
|
.args(&["[:alpha:]abc", "xyz"])
|
|
|
|
.pipe_in("abcdefghijklmnopqrstuvwxyz")
|
2021-07-14 16:04:43 +00:00
|
|
|
.succeeds()
|
2021-07-20 07:55:58 +00:00
|
|
|
.stdout_is("zzzzzzzzzzzzzzzzzzzzzzzzzz");
|
2021-07-14 16:04:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-07-20 07:55:58 +00:00
|
|
|
fn overrides_translation_pair_if_repeats() {
|
|
|
|
// echo -n 'aaa' | tr "aaa" "xyz"
|
2021-07-14 16:04:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["aaa", "xyz"])
|
|
|
|
.pipe_in("aaa")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("zzz");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-07-20 07:55:58 +00:00
|
|
|
fn uppercase_conversion_works_1() {
|
|
|
|
// echo -n 'abcdefghijklmnopqrstuvwxyz' | tr "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
2021-07-14 16:04:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"])
|
|
|
|
.pipe_in("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
2021-07-20 07:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn uppercase_conversion_works_2() {
|
|
|
|
// echo -n 'abcdefghijklmnopqrstuvwxyz' | tr "a-z" "A-Z"
|
2021-07-14 16:04:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["a-z", "A-Z"])
|
|
|
|
.pipe_in("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
2021-07-20 07:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn uppercase_conversion_works_3() {
|
|
|
|
// echo -n 'abcdefghijklmnopqrstuvwxyz' | tr "[:lower:]" "[:upper:]"
|
2021-07-14 16:04:43 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[:lower:]", "[:upper:]"])
|
|
|
|
.pipe_in("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
|
|
|
}
|
2021-07-20 07:55:58 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn translate_complement_set_in_order() {
|
|
|
|
// echo -n '01234' | tr -c '@-~' ' -^'
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "@-~", " -^"])
|
|
|
|
.pipe_in("01234")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("PQRST");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn alpha_expands_uppercase_lowercase() {
|
|
|
|
// echo -n "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | tr "[:alpha:]" " -_"
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[:alpha:]", " -_"])
|
|
|
|
.pipe_in("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(r##" !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRS"##);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn alnum_expands_number_uppercase_lowercase() {
|
|
|
|
// echo -n "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | tr "[:alnum:]" " -_"
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[:alnum:]", " -_"])
|
|
|
|
.pipe_in("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(r##" !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]"##);
|
|
|
|
}
|
2021-07-21 12:07:55 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['1', qw(abcd '[]*]'), {IN=>'abcd'}, {OUT=>']]]]'}],
|
2021-07-21 12:07:55 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["abcd", "[]*]"])
|
|
|
|
.pipe_in("abcd")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("]]]]");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_2() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['2', qw(abc '[%*]xyz'), {IN=>'abc'}, {OUT=>'xyz'}],
|
2021-07-21 12:07:55 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["abc", "[%*]xyz"])
|
|
|
|
.pipe_in("abc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("xyz");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_3() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['3', qw('' '[.*]'), {IN=>'abc'}, {OUT=>'abc'}],
|
2021-07-21 12:07:55 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["", "[.*]"])
|
|
|
|
.pipe_in("abc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abc");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_4() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # Test --truncate-set1 behavior when string1 is longer than string2
|
|
|
|
// ['4', qw(-t abcd xy), {IN=>'abcde'}, {OUT=>'xycde'}],
|
2021-07-21 12:07:55 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-t", "abcd", "xy"])
|
|
|
|
.pipe_in("abcde")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("xycde");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_5() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # Test bsd behavior (the default) when string1 is longer than string2
|
|
|
|
// ['5', qw(abcd xy), {IN=>'abcde'}, {OUT=>'xyyye'}],
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["abcd", "xy"])
|
|
|
|
.pipe_in("abcde")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("xyyye");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_6() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # Do it the posix way
|
|
|
|
// ['6', qw(abcd 'x[y*]'), {IN=>'abcde'}, {OUT=>'xyyye'}],
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["abcd", "x[y*]"])
|
|
|
|
.pipe_in("abcde")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("xyyye");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_7() {
|
|
|
|
// ['7', qw(-s a-p '%[.*]$'), {IN=>'abcdefghijklmnop'}, {OUT=>'%.$'}],
|
2021-07-21 14:36:18 +00:00
|
|
|
new_ucmd!()
|
2021-07-25 23:59:35 +00:00
|
|
|
.args(&["-s", "a-p", "%[.*]$"])
|
2021-07-21 14:36:18 +00:00
|
|
|
.pipe_in("abcdefghijklmnop")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("%.$");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_8() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['8', qw(-s a-p '[.*]$'), {IN=>'abcdefghijklmnop'}, {OUT=>'.$'}],
|
|
|
|
new_ucmd!()
|
2021-07-22 15:27:15 +00:00
|
|
|
.args(&["-s", "a-p", "[.*]$"])
|
2021-07-21 14:36:18 +00:00
|
|
|
.pipe_in("abcdefghijklmnop")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(".$");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_9() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['9', qw(-s a-p '%[.*]'), {IN=>'abcdefghijklmnop'}, {OUT=>'%.'}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-s", "a-p", "%[.*]"])
|
|
|
|
.pipe_in("abcdefghijklmnop")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("%.");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_a() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['a', qw(-s '[a-z]'), {IN=>'aabbcc'}, {OUT=>'abc'}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-s", "[a-z]"])
|
|
|
|
.pipe_in("aabbcc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abc");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_b() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['b', qw(-s '[a-c]'), {IN=>'aabbcc'}, {OUT=>'abc'}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-s", "[a-c]"])
|
|
|
|
.pipe_in("aabbcc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abc");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_c() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['c', qw(-s '[a-b]'), {IN=>'aabbcc'}, {OUT=>'abcc'}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-s", "[a-b]"])
|
|
|
|
.pipe_in("aabbcc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abcc");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_d() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['d', qw(-s '[b-c]'), {IN=>'aabbcc'}, {OUT=>'aabc'}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-s", "[b-c]"])
|
|
|
|
.pipe_in("aabbcc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("aabc");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-01 04:33:07 +00:00
|
|
|
#[ignore = "I cannot tell if this means that tr preserve the octal representation?"]
|
2021-07-25 23:59:35 +00:00
|
|
|
fn check_against_gnu_tr_tests_e() {
|
2021-07-22 15:27:15 +00:00
|
|
|
// ['e', qw(-s '[\0-\5]'), {IN=>"\0\0a\1\1b\2\2\2c\3\3\3d\4\4\4\4e\5\5"}, {OUT=>"\0a\1b\2c\3d\4e\5"}],
|
|
|
|
new_ucmd!()
|
2021-08-01 04:33:07 +00:00
|
|
|
.args(&["-s", r"[\0-\5]"])
|
2021-08-01 02:43:28 +00:00
|
|
|
.pipe_in(
|
|
|
|
"\u{0}\u{0}a\u{1}\u{1}b\u{2}\u{2}\u{2}c\u{3}\u{3}\u{3}d\u{4}\u{4}\u{4}\u{4}e\u{5}\u{5}",
|
|
|
|
)
|
2021-07-22 15:27:15 +00:00
|
|
|
.succeeds()
|
2021-08-01 02:43:28 +00:00
|
|
|
.stdout_is("\u{0}a\u{1}b\u{2}c\u{3}d\u{4}e\u{5}");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_f() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # tests of delete
|
|
|
|
// ['f', qw(-d '[=[=]'), {IN=>'[[[[[[[]]]]]]]]'}, {OUT=>']]]]]]]]'}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "[=[=]"])
|
|
|
|
.pipe_in("[[[[[[[]]]]]]]]")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("]]]]]]]]");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_g() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['g', qw(-d '[=]=]'), {IN=>'[[[[[[[]]]]]]]]'}, {OUT=>'[[[[[[['}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "[=]=]"])
|
|
|
|
.pipe_in("[[[[[[[]]]]]]]]")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("[[[[[[[");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_h() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['h', qw(-d '[:xdigit:]'), {IN=>'0123456789acbdefABCDEF'}, {OUT=>''}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "[:xdigit:]"])
|
|
|
|
.pipe_in("0123456789acbdefABCDEF")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_i() {
|
2021-07-22 15:27:15 +00:00
|
|
|
// ['i', qw(-d '[:xdigit:]'), {IN=>'w0x1y2z3456789acbdefABCDEFz'}, {OUT=>'wxyzz'}],
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "[:xdigit:]"])
|
|
|
|
.pipe_in("w0x1y2z3456789acbdefABCDEFz")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("wxyzz");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_j() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['j', qw(-d '[:digit:]'), {IN=>'0123456789'}, {OUT=>''}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
2021-08-01 02:43:28 +00:00
|
|
|
.args(&["-d", "[:digit:]"])
|
|
|
|
.pipe_in("0123456789")
|
2021-07-22 15:27:15 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_k() {
|
2021-07-22 15:27:15 +00:00
|
|
|
// ['k', qw(-d '[:digit:]'), {IN=>'a0b1c2d3e4f5g6h7i8j9k'}, {OUT=>'abcdefghijk'}],
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "[:digit:]"])
|
|
|
|
.pipe_in("a0b1c2d3e4f5g6h7i8j9k")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abcdefghijk");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_l() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['l', qw(-d '[:lower:]'), {IN=>'abcdefghijklmnopqrstuvwxyz'}, {OUT=>''}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "[:lower:]"])
|
|
|
|
.pipe_in("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_m() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['m', qw(-d '[:upper:]'), {IN=>'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}, {OUT=>''}],
|
2021-07-22 15:27:15 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "[:upper:]"])
|
|
|
|
.pipe_in("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_n() {
|
2021-07-22 15:27:15 +00:00
|
|
|
// ['n', qw(-d '[:lower:][:upper:]'), {IN=>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'}, {OUT=>''}],
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "[:lower:][:upper:]"])
|
|
|
|
.pipe_in("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_o() {
|
2021-07-22 15:27:15 +00:00
|
|
|
// ['o', qw(-d '[:alpha:]'), {IN=>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'}, {OUT=>''}],
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "[:alpha:]"])
|
|
|
|
.pipe_in("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_p() {
|
2021-07-22 15:27:15 +00:00
|
|
|
// ['p', qw(-d '[:alnum:]'), {IN=>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'}, {OUT=>''}],
|
|
|
|
new_ucmd!()
|
2021-07-29 13:06:40 +00:00
|
|
|
.args(&["-d", "[:alnum:]"])
|
2021-07-22 15:27:15 +00:00
|
|
|
.pipe_in("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
2021-07-25 23:59:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_q() {
|
2021-07-22 15:27:15 +00:00
|
|
|
// ['q', qw(-d '[:alnum:]'), {IN=>'.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.'}, {OUT=>'..'}],
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "[:alnum:]"])
|
|
|
|
.pipe_in(".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("..");
|
2021-08-01 02:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_r() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['r', qw(-ds '[:alnum:]' .),
|
|
|
|
// {IN=>'.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.'},
|
|
|
|
// {OUT=>'.'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-ds", "[:alnum:]", "."])
|
|
|
|
.pipe_in(".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(".");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_s() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # The classic example, with string2 BSD-style
|
|
|
|
// ['s', qw(-cs '[:alnum:]' '\n'),
|
|
|
|
// {IN=>'The big black fox jumped over the fence.'},
|
|
|
|
// {OUT=>"The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n"}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-cs", "[:alnum:]", "\n"])
|
|
|
|
.pipe_in("The big black fox jumped over the fence.")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_t() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # The classic example, POSIX-style
|
|
|
|
// ['t', qw(-cs '[:alnum:]' '[\n*]'),
|
|
|
|
// {IN=>'The big black fox jumped over the fence.'},
|
|
|
|
// {OUT=>"The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n"}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-cs", "[:alnum:]", "[\n*]"])
|
|
|
|
.pipe_in("The big black fox jumped over the fence.")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_u() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['u', qw(-ds b a), {IN=>'aabbaa'}, {OUT=>'a'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-ds", "b", "a"])
|
|
|
|
.pipe_in("aabbaa")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("a");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_v() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['v', qw(-ds '[:xdigit:]' Z), {IN=>'ZZ0123456789acbdefABCDEFZZ'}, {OUT=>'Z'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-ds", "[:xdigit:]", "Z"])
|
|
|
|
.pipe_in("ZZ0123456789acbdefABCDEFZZ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("Z");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_w() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # Try some data with 8th bit set in case something is mistakenly
|
|
|
|
// # sign-extended.
|
|
|
|
// ['w', qw(-ds '\350' '\345'),
|
|
|
|
// {IN=>"\300\301\377\345\345\350\345"},
|
|
|
|
// {OUT=>"\300\301\377\345"}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
2023-12-11 12:35:17 +00:00
|
|
|
.arg("-ds")
|
|
|
|
.args(&["\\350", "\\345"])
|
|
|
|
.pipe_in([0o300, 0o301, 0o377, 0o345, 0o345, 0o350, 0o345])
|
2021-08-01 02:43:28 +00:00
|
|
|
.succeeds()
|
2023-12-11 12:35:17 +00:00
|
|
|
.stdout_is_bytes([0o300, 0o301, 0o377, 0o345]);
|
2021-08-01 02:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_x() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['x', qw(-s abcdefghijklmn '[:*016]'),
|
|
|
|
// {IN=>'abcdefghijklmnop'}, {OUT=>':op'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-s", "abcdefghijklmn", "[:*016]"])
|
|
|
|
.pipe_in("abcdefghijklmnop")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(":op");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_y() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['y', qw(-d a-z), {IN=>'abc $code'}, {OUT=>' $'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-d", "a-z"])
|
|
|
|
.pipe_in("abc $code")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(" $");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_z() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['z', qw(-ds a-z '$.'), {IN=>'a.b.c $$$$code\\'}, {OUT=>'. $\\'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-ds", "a-z", "$."])
|
|
|
|
.pipe_in("a.b.c $$$$code\\")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(". $\\");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_range_a_a() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # Make sure that a-a is accepted.
|
|
|
|
// ['range-a-a', qw(a-a z), {IN=>'abc'}, {OUT=>'zbc'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["a-a", "z"])
|
|
|
|
.pipe_in("abc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("zbc");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_null() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['null', qw(a ''), {IN=>''}, {OUT=>''}, {EXIT=>1},
|
|
|
|
// {ERR=>"$prog: when not truncating set1, string2 must be non-empty\n"}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["a", ""])
|
|
|
|
.pipe_in("")
|
|
|
|
.fails()
|
|
|
|
.stderr_is("tr: when not truncating set1, string2 must be non-empty\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_upcase() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['upcase', qw('[:lower:]' '[:upper:]'),
|
|
|
|
// {IN=>'abcxyzABCXYZ'},
|
|
|
|
// {OUT=>'ABCXYZABCXYZ'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[:lower:]", "[:upper:]"])
|
|
|
|
.pipe_in("abcxyzABCXYZ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("ABCXYZABCXYZ");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_dncase() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['dncase', qw('[:upper:]' '[:lower:]'),
|
|
|
|
// {IN=>'abcxyzABCXYZ'},
|
|
|
|
// {OUT=>'abcxyzabcxyz'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[:upper:]", "[:lower:]"])
|
|
|
|
.pipe_in("abcxyzABCXYZ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abcxyzabcxyz");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_rep_cclass() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['rep-cclass', qw('a[=*2][=c=]' xyyz), {IN=>'a=c'}, {OUT=>'xyz'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["a[=*2][=c=]", "xyyz"])
|
|
|
|
.pipe_in("a=c")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("xyz");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_rep_1() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['rep-1', qw('[:*3][:digit:]' a-m), {IN=>':1239'}, {OUT=>'cefgm'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[:*3][:digit:]", "a-m"])
|
|
|
|
.pipe_in(":1239")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("cefgm");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_rep_2() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['rep-2', qw('a[b*512]c' '1[x*]2'), {IN=>'abc'}, {OUT=>'1x2'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["a[b*512]c", "1[x*]2"])
|
|
|
|
.pipe_in("abc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("1x2");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_rep_3() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['rep-3', qw('a[b*513]c' '1[x*]2'), {IN=>'abc'}, {OUT=>'1x2'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["a[b*513]c", "1[x*]2"])
|
|
|
|
.pipe_in("abc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("1x2");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_o_rep_1() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # Another couple octal repeat count tests.
|
|
|
|
// ['o-rep-1', qw('[b*08]' '[x*]'), {IN=>''}, {OUT=>''}, {EXIT=>1},
|
|
|
|
// {ERR=>"$prog: invalid repeat count '08' in [c*n] construct\n"}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[b*08]", "[x*]"])
|
|
|
|
.pipe_in("")
|
|
|
|
.fails()
|
|
|
|
.stderr_is("tr: invalid repeat count '08' in [c*n] construct\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_o_rep_2() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['o-rep-2', qw('[b*010]cd' '[a*7]BC[x*]'), {IN=>'bcd'}, {OUT=>'BCx'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[b*010]cd", "[a*7]BC[x*]"])
|
|
|
|
.pipe_in("bcd")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("BCx");
|
|
|
|
}
|
|
|
|
|
2022-02-25 11:11:53 +00:00
|
|
|
#[test]
|
|
|
|
fn octal_repeat_count_test() {
|
|
|
|
//below will result in 8'x' and 4'y' as octal 010 = decimal 8
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["ABCdefghijkl", "[x*010]Y"])
|
|
|
|
.pipe_in("ABCdefghijklmn12")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("xxxxxxxxYYYYmn12");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn non_octal_repeat_count_test() {
|
|
|
|
//below will result in 10'x' and 2'y' as the 10 does not have 0 prefix
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["ABCdefghijkl", "[x*10]Y"])
|
|
|
|
.pipe_in("ABCdefghijklmn12")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("xxxxxxxxxxYYmn12");
|
|
|
|
}
|
|
|
|
|
2021-08-01 02:43:28 +00:00
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_esc() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['esc', qw('a\-z' A-Z), {IN=>'abc-z'}, {OUT=>'AbcBC'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&[r"a\-z", "A-Z"])
|
|
|
|
.pipe_in("abc-z")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("AbcBC");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_bs_055() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['bs-055', qw('a\055b' def), {IN=>"a\055b"}, {OUT=>'def'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["a\u{055}b", "def"])
|
|
|
|
.pipe_in("a\u{055}b")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("def");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-14 11:10:17 +00:00
|
|
|
#[ignore = "Failing in Windows because it will not separate '\' and 'x' as separate arguments"]
|
2021-08-01 02:43:28 +00:00
|
|
|
fn check_against_gnu_tr_tests_bs_at_end() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['bs-at-end', qw('\\' x), {IN=>"\\"}, {OUT=>'x'},
|
|
|
|
// {ERR=>"$prog: warning: an unescaped backslash at end of "
|
|
|
|
// . "string is not portable\n"}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&[r"\", "x"])
|
|
|
|
.pipe_in(r"\")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("x")
|
2023-01-05 20:09:15 +00:00
|
|
|
.stderr_is("tr: warning: an unescaped backslash at end of string is not portable\n");
|
2021-08-01 02:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore = "not sure why GNU bails here. `[Y*]` should be able to generate all the mapping"]
|
|
|
|
fn check_against_gnu_tr_tests_ross_0a() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # From Ross
|
|
|
|
// ['ross-0a', qw(-cs '[:upper:]' 'X[Y*]'), {IN=>''}, {OUT=>''}, {EXIT=>1},
|
|
|
|
// {ERR=>$map_all_to_1}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-cs", "[:upper:]", "X[Y*]"])
|
|
|
|
.pipe_in("")
|
|
|
|
.fails()
|
2023-01-05 20:09:15 +00:00
|
|
|
.stderr_is("tr: when translating with complemented character classes,\nstring2 must map all characters in the domain to one\n");
|
2021-08-01 02:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore = "not sure why GNU bails here. `[Y*]` should be able to generate all the mapping"]
|
|
|
|
fn check_against_gnu_tr_tests_ross_0b() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['ross-0b', qw(-cs '[:cntrl:]' 'X[Y*]'), {IN=>''}, {OUT=>''}, {EXIT=>1},
|
|
|
|
// {ERR=>$map_all_to_1}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-cs", "[:cntrl:]", "X[Y*]"])
|
|
|
|
.pipe_in("")
|
|
|
|
.fails()
|
|
|
|
.stderr_is("tr: when translating with complemented character classes,\nstring2 must map all characters in the domain to one");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_ross_1a() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['ross-1a', qw(-cs '[:upper:]' '[X*]'),
|
|
|
|
// {IN=>'AMZamz123.-+AMZ'}, {OUT=>'AMZXAMZ'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-cs", "[:upper:]", "[X*]"])
|
|
|
|
.pipe_in("AMZamz123.-+AMZ")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("AMZXAMZ");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_ross_1b() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['ross-1b', qw(-cs '[:upper:][:digit:]' '[Z*]'), {IN=>''}, {OUT=>''}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-cs", "[:upper:][:digit:]", "[Z*]"])
|
|
|
|
.pipe_in("")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_ross_2() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['ross-2', qw(-dcs '[:lower:]' n-rs-z),
|
|
|
|
// {IN=>'amzAMZ123.-+amz'}, {OUT=>'amzamz'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-dcs", "[:lower:]", "n-rs-z"])
|
|
|
|
.pipe_in("amzAMZ123.-+amz")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("amzamz");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_ross_3() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['ross-3', qw(-ds '[:xdigit:]' '[:alnum:]'),
|
|
|
|
// {IN=>'.ZABCDEFGzabcdefg.0123456788899.GG'}, {OUT=>'.ZGzg..G'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-ds", "[:xdigit:]", "[:alnum:]"])
|
|
|
|
.pipe_in(".ZABCDEFGzabcdefg.0123456788899.GG")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is(".ZGzg..G");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_ross_4() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['ross-4', qw(-dcs '[:alnum:]' '[:digit:]'), {IN=>''}, {OUT=>''}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-dcs", "[:alnum:]", "[:digit:]"])
|
|
|
|
.pipe_in("")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_ross_5() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['ross-5', qw(-dc '[:lower:]'), {IN=>''}, {OUT=>''}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-dc", "[:lower:]"])
|
|
|
|
.pipe_in("")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_ross_6() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['ross-6', qw(-dc '[:upper:]'), {IN=>''}, {OUT=>''}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-dc", "[:upper:]"])
|
|
|
|
.pipe_in("")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_empty_eq() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # Ensure that these fail.
|
|
|
|
// # Prior to 2.0.20, each would evoke a failed assertion.
|
|
|
|
// ['empty-eq', qw('[==]' x), {IN=>''}, {OUT=>''}, {EXIT=>1},
|
|
|
|
// {ERR=>"$prog: missing equivalence class character '[==]'\n"}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[==]", "x"])
|
|
|
|
.pipe_in("")
|
|
|
|
.fails()
|
|
|
|
.stderr_is("tr: missing equivalence class character '[==]'\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_empty_cc() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['empty-cc', qw('[::]' x), {IN=>''}, {OUT=>''}, {EXIT=>1},
|
|
|
|
// {ERR=>"$prog: missing character class name '[::]'\n"}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[::]", "x"])
|
|
|
|
.pipe_in("")
|
|
|
|
.fails()
|
|
|
|
.stderr_is("tr: missing character class name '[::]'\n");
|
|
|
|
}
|
|
|
|
|
2023-02-10 14:16:07 +00:00
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_repeat_set1() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["[a*]", "a"])
|
|
|
|
.pipe_in("")
|
|
|
|
.fails()
|
|
|
|
.stderr_is("tr: the [c*] repeat construct may not appear in string1\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_repeat_set2() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["a", "[a*][a*]"])
|
|
|
|
.pipe_in("")
|
|
|
|
.fails()
|
|
|
|
.stderr_is("tr: only one [c*] repeat construct may appear in string2\n");
|
|
|
|
}
|
|
|
|
|
2021-08-01 02:43:28 +00:00
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_repeat_bs_9() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # Weird repeat counts.
|
|
|
|
// ['repeat-bs-9', qw(abc '[b*\9]'), {IN=>'abcd'}, {OUT=>'[b*d'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["abc", r"[b*\9]"])
|
|
|
|
.pipe_in("abcd")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("[b*d");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_repeat_0() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['repeat-0', qw(abc '[b*0]'), {IN=>'abcd'}, {OUT=>'bbbd'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["abc", "[b*0]"])
|
|
|
|
.pipe_in("abcd")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("bbbd");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_repeat_zeros() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['repeat-zeros', qw(abc '[b*00000000000000000000]'),
|
|
|
|
// {IN=>'abcd'}, {OUT=>'bbbd'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["abc", "[b*00000000000000000000]"])
|
|
|
|
.pipe_in("abcd")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("bbbd");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_repeat_compl() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['repeat-compl', qw(-c '[a*65536]\n' '[b*]'), {IN=>'abcd'}, {OUT=>'abbb'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "[a*65536]\n", "[b*]"])
|
|
|
|
.pipe_in("abcd")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abbb");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_repeat_x_c() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// ['repeat-xC', qw(-C '[a*65536]\n' '[b*]'), {IN=>'abcd'}, {OUT=>'abbb'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-C", "[a*65536]\n", "[b*]"])
|
|
|
|
.pipe_in("abcd")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abbb");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore = "I think either clap-rs or uutils is parsing the '-H' as an argument..."]
|
|
|
|
fn check_against_gnu_tr_tests_fowler_1() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # From Glenn Fowler.
|
|
|
|
// ['fowler-1', qw(ah -H), {IN=>'aha'}, {OUT=>'-H-'}],
|
2021-08-01 02:43:28 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["ah", "-H"])
|
|
|
|
.pipe_in("aha")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("-H-");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_against_gnu_tr_tests_no_abort_1() {
|
2021-07-21 14:36:18 +00:00
|
|
|
// # Up to coreutils-6.9, this would provoke a failed assertion.
|
|
|
|
// ['no-abort-1', qw(-c a '[b*256]'), {IN=>'abc'}, {OUT=>'abb'}],
|
2021-07-31 22:43:35 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "a", "[b*256]"])
|
|
|
|
.pipe_in("abc")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is("abb");
|
2021-07-21 12:07:55 +00:00
|
|
|
}
|
2024-02-06 15:42:08 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_delete_flag_takes_only_one_operand() {
|
|
|
|
// gnu tr -d fails with more than 1 argument
|
2024-02-08 06:22:39 +00:00
|
|
|
new_ucmd!().args(&["-d", "a", "p"]).fails().stderr_contains(
|
2024-02-06 15:42:08 +00:00
|
|
|
"extra operand 'p'\nOnly one string may be given when deleting without squeezing repeats.",
|
|
|
|
);
|
|
|
|
}
|
2024-02-13 14:30:15 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_truncate_flag_fails_with_more_than_two_operand() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-t", "a", "b", "c"])
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("extra operand 'c'");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_squeeze_flag_fails_with_more_than_two_operand() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-s", "a", "b", "c"])
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("extra operand 'c'");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_complement_flag_fails_with_more_than_two_operand() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["-c", "a", "b", "c"])
|
|
|
|
.fails()
|
|
|
|
.stderr_contains("extra operand 'c'");
|
|
|
|
}
|