2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2016-02-29 05:37:16 +00:00
|
|
|
|
|
|
|
static INPUT: &'static str = "sorted.txt";
|
2020-11-21 08:52:40 +00:00
|
|
|
static OUTPUT: &'static str = "sorted-output.txt";
|
2016-02-29 05:37:16 +00:00
|
|
|
static SKIP_CHARS: &'static str = "skip-chars.txt";
|
|
|
|
static SKIP_FIELDS: &'static str = "skip-fields.txt";
|
2016-08-07 01:25:11 +00:00
|
|
|
static SORTED_ZERO_TERMINATED: &'static str = "sorted-zero-terminated.txt";
|
2016-02-29 05:37:16 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_default() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.pipe_in_fixture(INPUT)
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("sorted-simple.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_single_default() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.arg(INPUT)
|
2020-04-13 18:36:03 +00:00
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("sorted-simple.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 08:52:40 +00:00
|
|
|
#[test]
|
|
|
|
fn test_single_default_output() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let expected = at.read("sorted-simple.expected");
|
|
|
|
ucmd.args(&[INPUT, OUTPUT]).run();
|
|
|
|
let found = at.read(OUTPUT);
|
|
|
|
assert_eq!(found, expected);
|
|
|
|
}
|
|
|
|
|
2016-02-29 05:37:16 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_counts() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-c"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("sorted-counts.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_skip_1_char() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-s1"])
|
|
|
|
.pipe_in_fixture(SKIP_CHARS)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("skip-1-char.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_skip_5_chars() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-s5"])
|
|
|
|
.pipe_in_fixture(SKIP_CHARS)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("skip-5-chars.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_skip_and_check_2_chars() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-s3", "-w2"])
|
|
|
|
.pipe_in_fixture(SKIP_CHARS)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("skip-3-check-2-chars.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_skip_1_field() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-f2"])
|
|
|
|
.pipe_in_fixture(SKIP_FIELDS)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("skip-2-fields.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_all_repeated() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["--all-repeated"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("sorted-all-repeated.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_all_repeated_separate() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["--all-repeated=separate"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("sorted-all-repeated-separate.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_all_repeated_prepend() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["--all-repeated=prepend"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("sorted-all-repeated-prepend.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_unique_only() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-u"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("sorted-unique-only.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_repeated_only() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-d"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("sorted-repeated-only.expected");
|
2016-02-29 05:37:16 +00:00
|
|
|
}
|
2016-08-07 01:25:11 +00:00
|
|
|
|
2016-08-12 18:03:42 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_ignore_case() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-i"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("sorted-ignore-case.expected");
|
2016-08-12 18:03:42 +00:00
|
|
|
}
|
|
|
|
|
2016-08-07 01:25:11 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_zero_terminated() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2020-04-13 18:36:03 +00:00
|
|
|
.args(&["-z"])
|
|
|
|
.pipe_in_fixture(SORTED_ZERO_TERMINATED)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("sorted-zero-terminated.expected");
|
2016-08-12 18:03:42 +00:00
|
|
|
}
|
2021-03-15 08:38:14 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_invalid_utf8() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("not-utf8-sequence.txt")
|
|
|
|
.run()
|
|
|
|
.failure()
|
|
|
|
.stderr_only("uniq: error: invalid utf-8 sequence of 1 bytes from index 0");
|
|
|
|
}
|
2021-04-04 09:37:29 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_group() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--group"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("group.expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_group_prepend() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--group=prepend"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("group-prepend.expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_group_append() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--group=append"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("group-append.expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_group_both() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--group=both"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("group-both.expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_group_separate() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["--group=separate"])
|
|
|
|
.pipe_in_fixture(INPUT)
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("group.expected");
|
|
|
|
}
|