Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select: fix fixed-auto bug #343

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,9 @@ static enum zsv_status auto_detect_fixed_column_sizes(struct fixed *fixed, struc
if (!first) {
if (verbose)
fprintf(stderr, "%s%zu", count ? "," : "", i);
fixed->offsets[count++] = i;
if (i)
fixed->offsets[count++] = i;
fixed->count = count;
}
if (verbose)
fprintf(stderr, "\n");
Expand Down
13 changes: 9 additions & 4 deletions app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -318,25 +318,30 @@ test-13-select test-13-select-pull: test-13-% : ${BUILD_DIR}/bin/zsv_%${EXE}
@${TEST_INIT}
@${PREFIX} [ "$$(echo 'aaa,bb,c\na,bb\nx,y,z' | $< --header-row-span 2 | head -1)" = "aaa a,bb bb,c" ] && ${TEST_PASS} || ${TEST_FAIL}

test-fixed-1-select test-fixed-1-select-pull: ${BUILD_DIR}/bin/zsv_select${EXE}
test-fixed-1-select-pull test-fixed-2-select-pull test-fixed-3-select-pull test-fixed-4-select-pull:
@echo "$@: n/a"

test-fixed-1-select: ${BUILD_DIR}/bin/zsv_select${EXE}
@${TEST_INIT}
@${PREFIX} $< ${TEST_DATA_DIR}/fixed.csv --fixed 3,7,12,18,20,21,22 ${REDIRECT} ${TMP_DIR}/[email protected]
@${CMP} ${TMP_DIR}/[email protected] expected/test-fixed-1-select.out && ${TEST_PASS} || ${TEST_FAIL}

test-fixed-2-select test-fixed-2-select-pull: ${BUILD_DIR}/bin/zsv_select${EXE}
test-fixed-2-select: ${BUILD_DIR}/bin/zsv_select${EXE}
@${TEST_INIT}
@${PREFIX} $< ${TEST_DATA_DIR}/fixed-auto.txt --fixed-auto ${REDIRECT} ${TMP_DIR}/[email protected]
@${CMP} ${TMP_DIR}/[email protected] expected/test-fixed-2-select.out && ${TEST_PASS} || ${TEST_FAIL}

test-fixed-3-select test-fixed-3-select-pull: ${BUILD_DIR}/bin/zsv_select${EXE}
test-fixed-3-select: ${BUILD_DIR}/bin/zsv_select${EXE}
@${TEST_INIT}
@${PREFIX} $< ${TEST_DATA_DIR}/fixed-auto2.txt --fixed-auto ${REDIRECT} ${TMP_DIR}/[email protected]
@${CMP} ${TMP_DIR}/[email protected] expected/test-fixed-3-select.out && ${TEST_PASS} || ${TEST_FAIL}

test-fixed-4-select test-fixed-4-select-pull: ${BUILD_DIR}/bin/zsv_select${EXE}
test-fixed-4-select: ${BUILD_DIR}/bin/zsv_select${EXE}
@${TEST_INIT}
@${PREFIX} $< ${TEST_DATA_DIR}/fixed-auto3.txt --fixed-auto ${REDIRECT} ${TMP_DIR}/[email protected]
@${CMP} ${TMP_DIR}/[email protected] expected/test-fixed-4-select.out && ${TEST_PASS} || ${TEST_FAIL}
@${PREFIX} $< ${TEST_DATA_DIR}/fixed-auto4a.txt --fixed-auto ${REDIRECT} ${TMP_DIR}/[email protected]
@${CMP} ${TMP_DIR}/[email protected] expected/test-fixed-4a-select.out && ${TEST_PASS} || ${TEST_FAIL}

test-rm: ${BUILD_DIR}/bin/zsv_prop${EXE} ${BUILD_DIR}/bin/zsv_rm${EXE}
@${TEST_INIT}
Expand Down
2 changes: 2 additions & 0 deletions app/test/expected/test-fixed-4a-select.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a b,c
aaa,c
2 changes: 2 additions & 0 deletions data/fixed-auto4a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a b c
aaa c