diff options
author | Ryan Geary <rtgnj42@gmail.com> | 2022-04-23 17:50:06 -0400 |
---|---|---|
committer | Ryan Geary <7076013+theryangeary@users.noreply.github.com> | 2022-04-23 18:19:10 -0400 |
commit | 0400bf6ce4ae30dcc852c9d05e24482fabb200b3 (patch) | |
tree | 090d9ca3561fcb5d1a0687ea1b6a530a7e558461 | |
parent | bd32530e84c960897c56f856448c93e0480ffc4d (diff) |
Fix field separator issue with no EOF
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | test/choose_colon_1.txt | 8 | ||||
-rw-r--r-- | test/colons.txt | 8 | ||||
-rwxr-xr-x | test/e2e_test.sh | 3 |
4 files changed, 22 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 9b511a7..07f66d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 diff --git a/test/choose_colon_1.txt b/test/choose_colon_1.txt new file mode 100644 index 0000000..e8fbbc8 --- /dev/null +++ b/test/choose_colon_1.txt @@ -0,0 +1,8 @@ +b +b +b + +efgh + +cd +cd diff --git a/test/colons.txt b/test/colons.txt new file mode 100644 index 0000000..89b97f4 --- /dev/null +++ b/test/colons.txt @@ -0,0 +1,8 @@ +a:b +a:b:c +a:b:c:d + +abcd:efgh + +ab:cd:ef: +ab:cd: diff --git a/test/e2e_test.sh b/test/e2e_test.sh index 6fe58ff..6091170 100755 --- a/test/e2e_test.sh +++ b/test/e2e_test.sh @@ -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 |