Skip to content

Commit

Permalink
Fix field separator issue with no EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
theryangeary committed Apr 23, 2022
1 parent bd32530 commit 0400bf6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main.rs
Expand Up @@ -73,7 +73,9 @@ fn main_generic<W: WriteReceiver>(opt: Opt, handle: &mut W) -> Result<()> {
while let Some(line) = reader.read_line(&mut buffer) {
match line {
Ok(l) => {
let l = if config.opt.character_wise || config.opt.field_separator.is_some() {
let l = if (config.opt.character_wise || config.opt.field_separator.is_some())
&& l.ends_with("\n")
{
&l[0..l.len().saturating_sub(1)]
} else {
&l
Expand Down
8 changes: 8 additions & 0 deletions test/choose_colon_1.txt
@@ -0,0 +1,8 @@
b
b
b

efgh

cd
cd
8 changes: 8 additions & 0 deletions test/colons.txt
@@ -0,0 +1,8 @@
a:b
a:b:c
a:b:c:d

abcd:efgh

ab:cd:ef:
ab:cd:
3 changes: 3 additions & 0 deletions test/e2e_test.sh
Expand Up @@ -25,6 +25,9 @@ diff -w <(cargo run -- 1:-1 -i ${test_dir}/alphabet.txt 2>/dev/null) <(cat "${te
diff -w <(cargo run -- 1:-2 -i ${test_dir}/alphabet.txt 2>/dev/null) <(cat "${test_dir}/choose_1x-2.txt")
diff -w <(cargo run -- 1:-3 -i ${test_dir}/alphabet.txt 2>/dev/null) <(cat "${test_dir}/choose_1x-3.txt")
# add tests for different delimiters
diff -w <(cargo run -- -f : 1 -i ${test_dir}/colons.txt 2>/dev/null) <(cat "${test_dir}/choose_colon_1.txt")
diff -w <(echo a:b | cargo run -- -f : 1) <(echo b)
diff -w <(echo -n a:b | cargo run -- -f : 1) <(echo b)
# add tests using piping

set +e
Expand Down

0 comments on commit 0400bf6

Please sign in to comment.