mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
commit
efdaf9a5e5
12 changed files with 68 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -114,6 +114,7 @@ TEST_PROGS := \
|
|||
basename \
|
||||
cat \
|
||||
cksum \
|
||||
comm \
|
||||
cp \
|
||||
cut \
|
||||
dirname \
|
||||
|
|
|
@ -72,6 +72,7 @@ fn comm(a: &mut LineReader, b: &mut LineReader, opts: &getopts::Matches) {
|
|||
(false, true) => Ordering::Greater,
|
||||
(true , false) => Ordering::Less,
|
||||
(true , true) => match(&na, &nb) {
|
||||
(&Ok(0), &Ok(0)) => break,
|
||||
(&Ok(0), _) => Ordering::Greater,
|
||||
(_, &Ok(0)) => Ordering::Less,
|
||||
_ => ra.cmp(&rb),
|
||||
|
@ -85,6 +86,7 @@ fn comm(a: &mut LineReader, b: &mut LineReader, opts: &getopts::Matches) {
|
|||
ensure_nl(ra);
|
||||
print!("{}{}", delim[1], ra);
|
||||
}
|
||||
ra.clear();
|
||||
na = a.read_line(ra);
|
||||
},
|
||||
Ordering::Greater => {
|
||||
|
@ -92,6 +94,7 @@ fn comm(a: &mut LineReader, b: &mut LineReader, opts: &getopts::Matches) {
|
|||
ensure_nl(rb);
|
||||
print!("{}{}", delim[2], rb);
|
||||
}
|
||||
rb.clear();
|
||||
nb = b.read_line(rb);
|
||||
},
|
||||
Ordering::Equal => {
|
||||
|
@ -99,6 +102,8 @@ fn comm(a: &mut LineReader, b: &mut LineReader, opts: &getopts::Matches) {
|
|||
ensure_nl(ra);
|
||||
print!("{}{}", delim[3], ra);
|
||||
}
|
||||
ra.clear();
|
||||
rb.clear();
|
||||
na = a.read_line(ra);
|
||||
nb = b.read_line(rb);
|
||||
}
|
||||
|
|
47
tests/comm.rs
Normal file
47
tests/comm.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
#[macro_use] mod common;
|
||||
|
||||
use common::util;
|
||||
|
||||
static UTIL_NAME: &'static str = "comm";
|
||||
|
||||
#[test]
|
||||
fn test_comm_ab_no_args() {
|
||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["a", "b"]).run();
|
||||
assert_eq!(result.stdout, at.read("ab.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_comm_ab_dash_one() {
|
||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["a", "b", "-1"]).run();
|
||||
assert_eq!(result.stdout, at.read("ab1.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_comm_ab_dash_two() {
|
||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["a", "b", "-2"]).run();
|
||||
assert_eq!(result.stdout, at.read("ab2.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_comm_ab_dash_three() {
|
||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["a", "b", "-3"]).run();
|
||||
assert_eq!(result.stdout, at.read("ab3.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_comm_aempty() {
|
||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["a", "empty"]).run();
|
||||
assert_eq!(result.stdout, at.read("aempty.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_comm_emptyempty() {
|
||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["empty", "empty"]).run();
|
||||
assert_eq!(result.stdout, at.read("emptyempty.expected"));
|
||||
}
|
2
tests/fixtures/comm/a
vendored
Normal file
2
tests/fixtures/comm/a
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
a
|
||||
z
|
3
tests/fixtures/comm/ab.expected
vendored
Normal file
3
tests/fixtures/comm/ab.expected
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
a
|
||||
b
|
||||
z
|
2
tests/fixtures/comm/ab1.expected
vendored
Normal file
2
tests/fixtures/comm/ab1.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
b
|
||||
z
|
2
tests/fixtures/comm/ab2.expected
vendored
Normal file
2
tests/fixtures/comm/ab2.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
a
|
||||
z
|
2
tests/fixtures/comm/ab3.expected
vendored
Normal file
2
tests/fixtures/comm/ab3.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
a
|
||||
b
|
2
tests/fixtures/comm/aempty.expected
vendored
Normal file
2
tests/fixtures/comm/aempty.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
a
|
||||
z
|
2
tests/fixtures/comm/b
vendored
Normal file
2
tests/fixtures/comm/b
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
b
|
||||
z
|
0
tests/fixtures/comm/empty
vendored
Normal file
0
tests/fixtures/comm/empty
vendored
Normal file
0
tests/fixtures/comm/emptyempty.expected
vendored
Normal file
0
tests/fixtures/comm/emptyempty.expected
vendored
Normal file
Loading…
Add table
Add a link
Reference in a new issue