mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
paste: cleanup multi-stdin support (#1803)
cleaner impl for multi-stdin support
This commit is contained in:
parent
3ab114f283
commit
5ced3a670b
3 changed files with 95 additions and 28 deletions
|
@ -1,5 +1,67 @@
|
|||
use crate::common::util::*;
|
||||
|
||||
struct TestData<'b> {
|
||||
name: &'b str,
|
||||
args: &'b [&'b str],
|
||||
ins: &'b [&'b str],
|
||||
out: &'b str,
|
||||
}
|
||||
|
||||
static EXAMPLE_DATA: &'static [TestData<'static>] = &[
|
||||
// Ensure that paste properly handles files lacking a final newline.
|
||||
TestData {
|
||||
name: "no-nl-1",
|
||||
args: &[],
|
||||
ins: &["a", "b"],
|
||||
out: "a\tb\n",
|
||||
},
|
||||
TestData {
|
||||
name: "no-nl-2",
|
||||
args: &[],
|
||||
ins: &["a\n", "b"],
|
||||
out: "a\tb\n",
|
||||
},
|
||||
TestData {
|
||||
name: "no-nl-3",
|
||||
args: &[],
|
||||
ins: &["a", "b\n"],
|
||||
out: "a\tb\n",
|
||||
},
|
||||
TestData {
|
||||
name: "no-nl-4",
|
||||
args: &[],
|
||||
ins: &["a\n", "b\n"],
|
||||
out: "a\tb\n",
|
||||
},
|
||||
// Same as above, but with a two lines in each input file and the
|
||||
// addition of the -d option to make SPACE be the output
|
||||
// delimiter.
|
||||
TestData {
|
||||
name: "no-nla-1",
|
||||
args: &["-d", " "],
|
||||
ins: &["1\na", "2\nb"],
|
||||
out: "1 2\na b\n",
|
||||
},
|
||||
TestData {
|
||||
name: "no-nla-2",
|
||||
args: &["-d", " "],
|
||||
ins: &["1\na\n", "2\nb"],
|
||||
out: "1 2\na b\n",
|
||||
},
|
||||
TestData {
|
||||
name: "no-nla-3",
|
||||
args: &["-d", " "],
|
||||
ins: &["1\na", "2\nb\n"],
|
||||
out: "1 2\na b\n",
|
||||
},
|
||||
TestData {
|
||||
name: "no-nla-4",
|
||||
args: &["-d", " "],
|
||||
ins: &["1\na\n", "2\nb\n"],
|
||||
out: "1 2\na b\n",
|
||||
},
|
||||
];
|
||||
|
||||
#[test]
|
||||
fn test_combine_pairs_of_lines() {
|
||||
for s in vec!["-s", "--serial"] {
|
||||
|
@ -22,3 +84,21 @@ fn test_multi_stdin() {
|
|||
.stdout_is_fixture("html_colors.expected");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_data() {
|
||||
for example in EXAMPLE_DATA {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let mut ins = vec![];
|
||||
for (i, _in) in example.ins.iter().enumerate() {
|
||||
let file = format!("in{}", i);
|
||||
at.write(&file, _in);
|
||||
ins.push(file);
|
||||
}
|
||||
println!("{}", example.name);
|
||||
ucmd.args(example.args)
|
||||
.args(&ins)
|
||||
.succeeds()
|
||||
.stdout_is(example.out);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue