1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #734 from ebfe/fix-comm

comm: fix EOF detection
This commit is contained in:
Heather 2015-11-29 00:37:50 +04:00
commit efdaf9a5e5
12 changed files with 68 additions and 0 deletions

View file

@ -114,6 +114,7 @@ TEST_PROGS := \
basename \
cat \
cksum \
comm \
cp \
cut \
dirname \

View file

@ -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
View 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
View file

@ -0,0 +1,2 @@
a
z

3
tests/fixtures/comm/ab.expected vendored Normal file
View file

@ -0,0 +1,3 @@
a
b
z

2
tests/fixtures/comm/ab1.expected vendored Normal file
View file

@ -0,0 +1,2 @@
b
z

2
tests/fixtures/comm/ab2.expected vendored Normal file
View file

@ -0,0 +1,2 @@
a
z

2
tests/fixtures/comm/ab3.expected vendored Normal file
View file

@ -0,0 +1,2 @@
a
b

2
tests/fixtures/comm/aempty.expected vendored Normal file
View file

@ -0,0 +1,2 @@
a
z

2
tests/fixtures/comm/b vendored Normal file
View file

@ -0,0 +1,2 @@
b
z

0
tests/fixtures/comm/empty vendored Normal file
View file

View file