mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
join: implement basic functionality
The basic implementation of join with some tests. The supported options: -1, -2, -j, -a, -i.
This commit is contained in:
parent
372dda9dfa
commit
b33ce67d91
19 changed files with 560 additions and 0 deletions
4
tests/fixtures/join/capitalized.txt
vendored
Normal file
4
tests/fixtures/join/capitalized.txt
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
A 1
|
||||
B 2
|
||||
C 4
|
||||
D 8
|
3
tests/fixtures/join/case_insensitive.expected
vendored
Normal file
3
tests/fixtures/join/case_insensitive.expected
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
A 1 2 f
|
||||
B 2 3 g
|
||||
C 4 4 h
|
5
tests/fixtures/join/default.expected
vendored
Normal file
5
tests/fixtures/join/default.expected
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
1 a
|
||||
2 b
|
||||
3 c
|
||||
5 e
|
||||
8 h
|
6
tests/fixtures/join/different_field.expected
vendored
Normal file
6
tests/fixtures/join/different_field.expected
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
2 b a f
|
||||
3 c b g
|
||||
4 d c h
|
||||
5 e f i
|
||||
6 f g j
|
||||
7 g h k
|
5
tests/fixtures/join/different_fields.expected
vendored
Normal file
5
tests/fixtures/join/different_fields.expected
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
c 3 2 1 cd
|
||||
d 4 3 2 de
|
||||
e 5 5 3 ef
|
||||
f 6 7 4 fg
|
||||
g 7 11 5 gh
|
0
tests/fixtures/join/empty.txt
vendored
Normal file
0
tests/fixtures/join/empty.txt
vendored
Normal file
5
tests/fixtures/join/fields_1.txt
vendored
Normal file
5
tests/fixtures/join/fields_1.txt
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
5
|
||||
8
|
9
tests/fixtures/join/fields_2.txt
vendored
Normal file
9
tests/fixtures/join/fields_2.txt
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
1 a
|
||||
2 b
|
||||
3 c
|
||||
4 d
|
||||
5 e
|
||||
6 f
|
||||
7 g
|
||||
8 h
|
||||
9 i
|
6
tests/fixtures/join/fields_3.txt
vendored
Normal file
6
tests/fixtures/join/fields_3.txt
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
a 2 f
|
||||
b 3 g
|
||||
c 4 h
|
||||
f 5 i
|
||||
g 6 j
|
||||
h 7 k
|
5
tests/fixtures/join/fields_4.txt
vendored
Normal file
5
tests/fixtures/join/fields_4.txt
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
2 c 1 cd
|
||||
3 d 2 de
|
||||
5 e 3 ef
|
||||
7 f 4 fg
|
||||
11 g 5 gh
|
9
tests/fixtures/join/unpaired_lines.expected
vendored
Normal file
9
tests/fixtures/join/unpaired_lines.expected
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
1 a
|
||||
2 a f b
|
||||
3 b g c
|
||||
4 c h d
|
||||
5 f i e
|
||||
6 g j f
|
||||
7 h k g
|
||||
8 h
|
||||
9 i
|
95
tests/test_join.rs
Normal file
95
tests/test_join.rs
Normal file
|
@ -0,0 +1,95 @@
|
|||
use common::util::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn empty_files() {
|
||||
new_ucmd!()
|
||||
.arg("empty.txt")
|
||||
.arg("empty.txt")
|
||||
.succeeds().stdout_only("");
|
||||
|
||||
new_ucmd!()
|
||||
.arg("empty.txt")
|
||||
.arg("fields_1.txt")
|
||||
.succeeds().stdout_only("");
|
||||
|
||||
new_ucmd!()
|
||||
.arg("fields_1.txt")
|
||||
.arg("empty.txt")
|
||||
.succeeds().stdout_only("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_intersection() {
|
||||
new_ucmd!()
|
||||
.arg("fields_1.txt")
|
||||
.arg("fields_2.txt")
|
||||
.arg("-2")
|
||||
.arg("2")
|
||||
.succeeds().stdout_only("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_arguments() {
|
||||
new_ucmd!()
|
||||
.arg("fields_1.txt")
|
||||
.arg("fields_2.txt")
|
||||
.succeeds().stdout_only_fixture("default.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_fields() {
|
||||
new_ucmd!()
|
||||
.arg("fields_2.txt")
|
||||
.arg("fields_4.txt")
|
||||
.arg("-j")
|
||||
.arg("2")
|
||||
.succeeds().stdout_only_fixture("different_fields.expected");
|
||||
|
||||
new_ucmd!()
|
||||
.arg("fields_2.txt")
|
||||
.arg("fields_4.txt")
|
||||
.arg("-1")
|
||||
.arg("2")
|
||||
.arg("-2")
|
||||
.arg("2")
|
||||
.succeeds().stdout_only_fixture("different_fields.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn different_field() {
|
||||
new_ucmd!()
|
||||
.arg("fields_2.txt")
|
||||
.arg("fields_3.txt")
|
||||
.arg("-2")
|
||||
.arg("2")
|
||||
.succeeds().stdout_only_fixture("different_field.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unpaired_lines() {
|
||||
new_ucmd!()
|
||||
.arg("fields_2.txt")
|
||||
.arg("fields_3.txt")
|
||||
.arg("-a")
|
||||
.arg("1")
|
||||
.succeeds().stdout_only_fixture("fields_2.txt");
|
||||
|
||||
new_ucmd!()
|
||||
.arg("fields_3.txt")
|
||||
.arg("fields_2.txt")
|
||||
.arg("-1")
|
||||
.arg("2")
|
||||
.arg("-a")
|
||||
.arg("2")
|
||||
.succeeds().stdout_only_fixture("unpaired_lines.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn case_insensitive() {
|
||||
new_ucmd!()
|
||||
.arg("capitalized.txt")
|
||||
.arg("fields_3.txt")
|
||||
.arg("-i")
|
||||
.succeeds().stdout_only_fixture("case_insensitive.expected");
|
||||
}
|
|
@ -58,6 +58,7 @@ generic! {
|
|||
"fold", test_fold;
|
||||
"hashsum", test_hashsum;
|
||||
"head", test_head;
|
||||
"join", test_join;
|
||||
"link", test_link;
|
||||
"ln", test_ln;
|
||||
"ls", test_ls;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue