2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2021-03-12 12:26:09 +00:00
|
|
|
struct TestData<'b> {
|
|
|
|
name: &'b str,
|
|
|
|
args: &'b [&'b str],
|
|
|
|
ins: &'b [&'b str],
|
|
|
|
out: &'b str,
|
|
|
|
}
|
|
|
|
|
2021-05-29 12:32:35 +00:00
|
|
|
static EXAMPLE_DATA: &[TestData] = &[
|
2021-03-12 12:26:09 +00:00
|
|
|
// 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",
|
|
|
|
},
|
2022-06-19 10:37:54 +00:00
|
|
|
TestData {
|
|
|
|
name: "zno-nl-1",
|
|
|
|
args: &["-z"],
|
|
|
|
ins: &["a", "b"],
|
|
|
|
out: "a\tb\0",
|
|
|
|
},
|
|
|
|
TestData {
|
|
|
|
name: "zno-nl-2",
|
|
|
|
args: &["-z"],
|
|
|
|
ins: &["a\0", "b"],
|
|
|
|
out: "a\tb\0",
|
|
|
|
},
|
|
|
|
TestData {
|
|
|
|
name: "zno-nl-3",
|
|
|
|
args: &["-z"],
|
|
|
|
ins: &["a", "b\0"],
|
|
|
|
out: "a\tb\0",
|
|
|
|
},
|
|
|
|
TestData {
|
|
|
|
name: "zno-nl-4",
|
|
|
|
args: &["-z"],
|
|
|
|
ins: &["a\0", "b\0"],
|
|
|
|
out: "a\tb\0",
|
|
|
|
},
|
2021-03-12 12:26:09 +00:00
|
|
|
// 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",
|
|
|
|
},
|
2022-06-19 10:37:54 +00:00
|
|
|
TestData {
|
|
|
|
name: "zno-nla1",
|
|
|
|
args: &["-zd", " "],
|
|
|
|
ins: &["1\0a", "2\0b"],
|
|
|
|
out: "1 2\0a b\0",
|
|
|
|
},
|
|
|
|
TestData {
|
|
|
|
name: "zno-nla2",
|
|
|
|
args: &["-zd", " "],
|
|
|
|
ins: &["1\0a\0", "2\0b"],
|
|
|
|
out: "1 2\0a b\0",
|
|
|
|
},
|
|
|
|
TestData {
|
|
|
|
name: "zno-nla3",
|
|
|
|
args: &["-zd", " "],
|
|
|
|
ins: &["1\0a", "2\0b\0"],
|
|
|
|
out: "1 2\0a b\0",
|
|
|
|
},
|
|
|
|
TestData {
|
|
|
|
name: "zno-nla4",
|
|
|
|
args: &["-zd", " "],
|
|
|
|
ins: &["1\0a\0", "2\0b\0"],
|
|
|
|
out: "1 2\0a b\0",
|
|
|
|
},
|
2022-01-31 03:03:17 +00:00
|
|
|
TestData {
|
|
|
|
name: "multibyte-delim",
|
|
|
|
args: &["-d", "💣"],
|
|
|
|
ins: &["1\na\n", "2\nb\n"],
|
|
|
|
out: "1💣2\na💣b\n",
|
|
|
|
},
|
|
|
|
TestData {
|
|
|
|
name: "multibyte-delim-serial",
|
|
|
|
args: &["-d", "💣", "-s"],
|
|
|
|
ins: &["1\na\n", "2\nb\n"],
|
|
|
|
out: "1💣a\n2💣b\n",
|
|
|
|
},
|
2022-01-31 03:49:18 +00:00
|
|
|
TestData {
|
|
|
|
name: "trailing whitespace",
|
|
|
|
args: &["-d", "|"],
|
|
|
|
ins: &["1 \na \n", "2\t\nb\t\n"],
|
|
|
|
out: "1 |2\t\na |b\t\n",
|
|
|
|
},
|
2021-03-12 12:26:09 +00:00
|
|
|
];
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_combine_pairs_of_lines() {
|
2022-04-02 08:47:37 +00:00
|
|
|
for s in ["-s", "--serial"] {
|
|
|
|
for d in ["-d", "--delimiters"] {
|
2021-03-10 22:19:12 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&[s, d, "\t\n", "html_colors.txt"])
|
|
|
|
.run()
|
|
|
|
.stdout_is_fixture("html_colors.expected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multi_stdin() {
|
2022-04-02 08:47:37 +00:00
|
|
|
for d in ["-d", "--delimiters"] {
|
2021-03-10 22:19:12 +00:00
|
|
|
new_ucmd!()
|
|
|
|
.args(&[d, "\t\n", "-", "-"])
|
|
|
|
.pipe_in_fixture("html_colors.txt")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_is_fixture("html_colors.expected");
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
2021-03-12 12:26:09 +00:00
|
|
|
|
|
|
|
#[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);
|
|
|
|
}
|
|
|
|
}
|