2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2017-12-13 21:02:42 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn empty_files() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("empty.txt")
|
|
|
|
.arg("empty.txt")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("");
|
2017-12-13 21:02:42 +00:00
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("empty.txt")
|
|
|
|
.arg("fields_1.txt")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("");
|
2017-12-13 21:02:42 +00:00
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_1.txt")
|
|
|
|
.arg("empty.txt")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("");
|
2017-12-13 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn empty_intersection() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_1.txt")
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("-2")
|
|
|
|
.arg("2")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("");
|
2017-12-13 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_arguments() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_1.txt")
|
|
|
|
.arg("fields_2.txt")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("default.expected");
|
2017-12-13 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn different_fields() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("fields_4.txt")
|
|
|
|
.arg("-j")
|
|
|
|
.arg("2")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("different_fields.expected");
|
2017-12-13 21:02:42 +00:00
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("fields_4.txt")
|
|
|
|
.arg("-1")
|
|
|
|
.arg("2")
|
|
|
|
.arg("-2")
|
|
|
|
.arg("2")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("different_fields.expected");
|
2017-12-13 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn different_field() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("fields_3.txt")
|
|
|
|
.arg("-2")
|
|
|
|
.arg("2")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("different_field.expected");
|
2017-12-13 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unpaired_lines() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("fields_3.txt")
|
|
|
|
.arg("-a")
|
|
|
|
.arg("1")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("fields_2.txt");
|
2017-12-13 21:02:42 +00:00
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_3.txt")
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("-1")
|
|
|
|
.arg("2")
|
|
|
|
.arg("-a")
|
|
|
|
.arg("2")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("unpaired_lines.expected");
|
2017-12-13 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
2018-06-09 09:11:58 +00:00
|
|
|
#[test]
|
|
|
|
fn suppress_joined() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_3.txt")
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("-1")
|
|
|
|
.arg("2")
|
|
|
|
.arg("-v")
|
|
|
|
.arg("2")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("suppress_joined.expected");
|
2018-06-09 09:11:58 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 21:02:42 +00:00
|
|
|
#[test]
|
|
|
|
fn case_insensitive() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("capitalized.txt")
|
|
|
|
.arg("fields_3.txt")
|
|
|
|
.arg("-i")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("case_insensitive.expected");
|
2017-12-13 21:02:42 +00:00
|
|
|
}
|
2017-12-24 13:22:48 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn semicolon_separated() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("semicolon_fields_1.txt")
|
|
|
|
.arg("semicolon_fields_2.txt")
|
|
|
|
.arg("-t")
|
|
|
|
.arg(";")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("semicolon_separated.expected");
|
2017-12-24 13:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn new_line_separated() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-")
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("-t")
|
|
|
|
.arg("")
|
|
|
|
.pipe_in("1 a\n1 b\n8 h\n")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("1 a\n8 h\n");
|
2017-12-24 13:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multitab_character() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("semicolon_fields_1.txt")
|
|
|
|
.arg("semicolon_fields_2.txt")
|
|
|
|
.arg("-t")
|
|
|
|
.arg("э")
|
2020-04-13 18:36:03 +00:00
|
|
|
.fails()
|
|
|
|
.stderr_is("join: error: multi-character tab э");
|
2017-12-24 13:22:48 +00:00
|
|
|
}
|
2018-01-06 19:49:07 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_format() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_1.txt")
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("-o")
|
|
|
|
.arg("1.1 2.2")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("default.expected");
|
2018-01-06 19:49:07 +00:00
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_1.txt")
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("-o")
|
|
|
|
.arg("0 2.2")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("default.expected");
|
2018-01-06 19:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unpaired_lines_format() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("fields_3.txt")
|
|
|
|
.arg("-a")
|
|
|
|
.arg("2")
|
|
|
|
.arg("-o")
|
|
|
|
.arg("1.2 1.1 2.4 2.3 2.2 0")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("unpaired_lines_format.expected");
|
2018-01-06 19:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn autoformat() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("different_lengths.txt")
|
|
|
|
.arg("-o")
|
|
|
|
.arg("auto")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("autoformat.expected");
|
2019-02-07 20:54:48 +00:00
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("-")
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("-o")
|
|
|
|
.arg("auto")
|
|
|
|
.pipe_in("1 x y z\n2 p")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("1 x y z a\n2 p b\n");
|
2018-01-06 19:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn empty_format() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_1.txt")
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("-o")
|
|
|
|
.arg("")
|
2020-04-13 18:36:03 +00:00
|
|
|
.fails()
|
|
|
|
.stderr_is("join: error: invalid file number in field spec: ''");
|
2018-01-06 19:49:07 +00:00
|
|
|
}
|
2018-01-13 19:44:37 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn empty_key() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_1.txt")
|
|
|
|
.arg("empty.txt")
|
|
|
|
.arg("-j")
|
|
|
|
.arg("2")
|
|
|
|
.arg("-a")
|
|
|
|
.arg("1")
|
|
|
|
.arg("-e")
|
|
|
|
.arg("x")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("empty_key.expected");
|
2018-01-13 19:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn missing_format_fields() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("different_lengths.txt")
|
|
|
|
.arg("-o")
|
|
|
|
.arg("0 1.2 2.4")
|
|
|
|
.arg("-e")
|
|
|
|
.arg("x")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("missing_format_fields.expected");
|
2018-01-13 19:44:37 +00:00
|
|
|
}
|
2018-02-11 15:23:12 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn wrong_line_order() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("fields_2.txt")
|
|
|
|
.arg("fields_4.txt")
|
2020-04-13 18:36:03 +00:00
|
|
|
.fails()
|
|
|
|
.stderr_is("fields_4.txt:5: is not sorted");
|
2018-02-11 15:23:12 +00:00
|
|
|
}
|
2018-04-11 19:55:44 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn headers() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("header_1.txt")
|
|
|
|
.arg("header_2.txt")
|
|
|
|
.arg("--header")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("header.expected");
|
2018-04-11 19:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn headers_autoformat() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("header_1.txt")
|
|
|
|
.arg("header_2.txt")
|
|
|
|
.arg("--header")
|
|
|
|
.arg("-o")
|
|
|
|
.arg("auto")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only_fixture("header_autoformat.expected");
|
2018-04-11 19:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn single_file_with_header() {
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("capitalized.txt")
|
|
|
|
.arg("empty.txt")
|
|
|
|
.arg("--header")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_is("A 1\n");
|
2018-04-11 19:55:44 +00:00
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.arg("empty.txt")
|
|
|
|
.arg("capitalized.txt")
|
|
|
|
.arg("--header")
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_is("A 1\n");
|
2018-04-11 19:55:44 +00:00
|
|
|
}
|