mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
shuf: obey all headcount args, not just the last
This commit is contained in:
parent
07e8f4c7a5
commit
69f23c2521
2 changed files with 67 additions and 0 deletions
|
@ -145,6 +145,7 @@ pub fn uu_app() -> Command {
|
||||||
.short('n')
|
.short('n')
|
||||||
.long(options::HEAD_COUNT)
|
.long(options::HEAD_COUNT)
|
||||||
.value_name("COUNT")
|
.value_name("COUNT")
|
||||||
|
.action(clap::ArgAction::Append)
|
||||||
.help("output at most COUNT lines"),
|
.help("output at most COUNT lines"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
|
|
@ -131,6 +131,72 @@ fn test_head_count() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_head_count_multi_big_then_small() {
|
||||||
|
let repeat_limit = 5;
|
||||||
|
let input_seq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||||
|
let input = input_seq
|
||||||
|
.iter()
|
||||||
|
.map(ToString::to_string)
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
let result = new_ucmd!()
|
||||||
|
.arg("-n")
|
||||||
|
.arg(&(repeat_limit + 1).to_string())
|
||||||
|
.arg("-n")
|
||||||
|
.arg(&repeat_limit.to_string())
|
||||||
|
.pipe_in(input.as_bytes())
|
||||||
|
.succeeds();
|
||||||
|
result.no_stderr();
|
||||||
|
|
||||||
|
let result_seq: Vec<i32> = result
|
||||||
|
.stdout_str()
|
||||||
|
.split('\n')
|
||||||
|
.filter(|x| !x.is_empty())
|
||||||
|
.map(|x| x.parse().unwrap())
|
||||||
|
.collect();
|
||||||
|
assert_eq!(result_seq.len(), repeat_limit, "Output is not limited");
|
||||||
|
assert!(
|
||||||
|
result_seq.iter().all(|x| input_seq.contains(x)),
|
||||||
|
"Output includes element not from input: {}",
|
||||||
|
result.stdout_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_head_count_multi_small_then_big() {
|
||||||
|
let repeat_limit = 5;
|
||||||
|
let input_seq = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||||
|
let input = input_seq
|
||||||
|
.iter()
|
||||||
|
.map(ToString::to_string)
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
let result = new_ucmd!()
|
||||||
|
.arg("-n")
|
||||||
|
.arg(&repeat_limit.to_string())
|
||||||
|
.arg("-n")
|
||||||
|
.arg(&(repeat_limit + 1).to_string())
|
||||||
|
.pipe_in(input.as_bytes())
|
||||||
|
.succeeds();
|
||||||
|
result.no_stderr();
|
||||||
|
|
||||||
|
let result_seq: Vec<i32> = result
|
||||||
|
.stdout_str()
|
||||||
|
.split('\n')
|
||||||
|
.filter(|x| !x.is_empty())
|
||||||
|
.map(|x| x.parse().unwrap())
|
||||||
|
.collect();
|
||||||
|
assert_eq!(result_seq.len(), repeat_limit, "Output is not limited");
|
||||||
|
assert!(
|
||||||
|
result_seq.iter().all(|x| input_seq.contains(x)),
|
||||||
|
"Output includes element not from input: {}",
|
||||||
|
result.stdout_str()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_repeat() {
|
fn test_repeat() {
|
||||||
let repeat_limit = 15000;
|
let repeat_limit = 15000;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue