Skip to content

Commit

Permalink
sheet: Fix bug in \r\n line handling
Browse files Browse the repository at this point in the history
Also add a test on a file with only \r\n line endings as the mixed
line endings test did not reproduce this bug.
  • Loading branch information
richiejp committed Dec 11, 2024
1 parent d8cc28b commit 5dd0e1a
Show file tree
Hide file tree
Showing 6 changed files with 2,778 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,16 @@ test-sheet-14: ${BUILD_DIR}/bin/zsv_sheet${EXE} worldcitiespop_mil.csv ${TIMINGS
tmux send-keys -t $@ "Escape" && \
${EXPECT} $@ && ${TEST_PASS} || ${TEST_FAIL})

test-sheet-15: ${BUILD_DIR}/bin/zsv_sheet${EXE} ${TIMINGS_CSV}
@${TEST_INIT}
@echo 'set-option default-terminal "${TMUX_TERM}"' > ~/.tmux.conf
@(tmux new-session -x 80 -y 6 -d -s $@ "${PREFIX} $< -d 3 ${TEST_DATA_DIR}/test/crlf-line-ending.csv" && \
${EXPECT} $@ indexed && \
tmux send-keys -t $@ "G" && \
${EXPECT} $@ bottom && \
tmux send-keys -t $@ -N 4096 "k" && \
${EXPECT} $@ && ${TEST_PASS} || ${TEST_FAIL})

test-sheet-subcommand:\
test-sheet-subcommand-open-file-prompt test-sheet-subcommand-open-file-argument\
test-sheet-subcommand-filter-file-prompt test-sheet-subcommand-filter-file-argument
Expand Down
6 changes: 6 additions & 0 deletions app/test/expected/test-sheet-15-bottom.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Row # HA1 HA2 HA3 HB1 HB2 HB3 HC1 HC2 HC3
4093 A4093 B4093 C4093
4094 A4094 B4094 C4094
4095 A4095 B4095 C4095
4096 A4096 B4096 C4096
? for help 4096
6 changes: 6 additions & 0 deletions app/test/expected/test-sheet-15-indexed.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Row # HA1 HA2 HA3 HB1 HB2 HB3 HC1 HC2 HC3
1 A1 B1 C1
2 A2 B2 C2
3 A3 B3 C3
4 A4 B4 C4
? for help 1
6 changes: 6 additions & 0 deletions app/test/expected/test-sheet-15.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Row # HA1 HA2 HA3 HB1 HB2 HB3 HC1 HC2 HC3
1 A1 B1 C1
2 A2 B2 C2
3 A3 B3 C3
4 A4 B4 C4
? for help Row #
8 changes: 3 additions & 5 deletions app/utils/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,10 @@ static enum zsv_index_status seek_and_check_newline(long *offset, struct zsv_opt
if (new_line[0] == '\n') {
*offset += 1;
} else if (new_line[0] == '\r') {
if (new_line[1] == '\n') {
*offset += 1;
return zsv_index_status_ok;
}

*offset += 1;

if (new_line[1] == '\n')
*offset += 1;
} else {
return zsv_index_status_error;
}
Expand Down
Loading

0 comments on commit 5dd0e1a

Please sign in to comment.