From: Karel Zak Date: Mon, 23 Oct 2023 12:47:35 +0000 (+0200) Subject: libsmartcols: add wrap-zero test X-Git-Tag: v2.40-rc1~181 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d585a4159d5dac1889bccfc8d3b17e3795ef8de6;p=thirdparty%2Futil-linux.git libsmartcols: add wrap-zero test * modify samples/fromfile.c to use scols_wrapzero_nextchunk() callback if "wrapzero" specified for the test colum * add col-wrapzero and data-string-zero to define the column and zero separated data Signed-off-by: Karel Zak --- diff --git a/libsmartcols/samples/fromfile.c b/libsmartcols/samples/fromfile.c index 5c418758a6..a921b20a92 100644 --- a/libsmartcols/samples/fromfile.c +++ b/libsmartcols/samples/fromfile.c @@ -36,6 +36,7 @@ static const struct column_flag flags[] = { { "hidden", SCOLS_FL_HIDDEN }, { "wrap", SCOLS_FL_WRAP }, { "wrapnl", SCOLS_FL_WRAP }, + { "wrapzero", SCOLS_FL_WRAP }, { "none", 0 } }; @@ -100,11 +101,16 @@ static struct libscols_column *parse_column(FILE *f) goto fail; if (strcmp(line, "wrapnl") == 0) { scols_column_set_wrapfunc(cl, - scols_wrapnl_chunksize, + NULL, scols_wrapnl_nextchunk, NULL); scols_column_set_safechars(cl, "\n"); + } else if (strcmp(line, "wrapzero") == 0) { + scols_column_set_wrapfunc(cl, + NULL, + scols_wrapzero_nextchunk, + NULL); } break; } diff --git a/tests/expected/libsmartcols/fromfile-wrapzero b/tests/expected/libsmartcols/fromfile-wrapzero new file mode 100644 index 0000000000..11370ff087 --- /dev/null +++ b/tests/expected/libsmartcols/fromfile-wrapzero @@ -0,0 +1,19 @@ +NAME NUM WRAPZERO +aaaa 0 aaa +bbb 100 bbbbb +ccccc 21 cccc + CCCC +dddddd 3 dddddddd + DDDD + DD +ee 411 hello + baby +ffff 5111 aaa + bbb + ccc + ddd +gggggg 678993321 eee +hhh 7666666 fffff +iiiiii 8765 g + hhhhh +jj 987456 ppppppppp diff --git a/tests/expected/libsmartcols/fromfile-wrapzero-tree b/tests/expected/libsmartcols/fromfile-wrapzero-tree new file mode 100644 index 0000000000..552470d4d6 --- /dev/null +++ b/tests/expected/libsmartcols/fromfile-wrapzero-tree @@ -0,0 +1,19 @@ +TREE ID PARENT WRAPZERO +aaaa 1 0 aaa +|-bbb 2 1 bbbbb +| |-ee 5 2 hello +| | baby +| `-ffff 6 2 aaa +| bbb +| ccc +| ddd +|-ccccc 3 1 cccc +| | CCCC +| `-gggggg 7 3 eee +| |-hhh 8 7 fffff +| | `-iiiiii 9 8 g +| | hhhhh +| `-jj 10 7 ppppppppp +`-dddddd 4 1 dddddddd + DDDD + DD diff --git a/tests/ts/libsmartcols/files/col-wrapzero b/tests/ts/libsmartcols/files/col-wrapzero new file mode 100644 index 0000000000..0849187c21 --- /dev/null +++ b/tests/ts/libsmartcols/files/col-wrapzero @@ -0,0 +1,3 @@ +WRAPZERO +0 +wrapzero diff --git a/tests/ts/libsmartcols/files/data-string-zero b/tests/ts/libsmartcols/files/data-string-zero new file mode 100644 index 0000000000..5f936f137a --- /dev/null +++ b/tests/ts/libsmartcols/files/data-string-zero @@ -0,0 +1,10 @@ +aaa +bbbbb +cccc\x00CCCC +dddddddd\x00DDDD\x00DD +hello\x00baby +aaa\x00bbb\x00ccc\x00ddd +eee +fffff +g\x00hhhhh +ppppppppp diff --git a/tests/ts/libsmartcols/fromfile b/tests/ts/libsmartcols/fromfile index 45b84716cf..c11140cb72 100755 --- a/tests/ts/libsmartcols/fromfile +++ b/tests/ts/libsmartcols/fromfile @@ -249,6 +249,32 @@ ts_run $TESTPROG --nlines 10 \ >> $TS_OUTPUT 2>> $TS_ERRLOG ts_finalize_subtest +ts_init_subtest "wrapzero" +ts_run $TESTPROG --nlines 10 \ + --column $TS_SELF/files/col-name \ + --column $TS_SELF/files/col-number \ + --column $TS_SELF/files/col-wrapzero \ + $TS_SELF/files/data-string \ + $TS_SELF/files/data-number \ + $TS_SELF/files/data-string-zero \ + >> $TS_OUTPUT 2>> $TS_ERRLOG +ts_finalize_subtest + +ts_init_subtest "wrapzero-tree" +ts_run $TESTPROG --nlines 10 \ + --tree-id-column 1 \ + --tree-parent-column 2 \ + --column $TS_SELF/files/col-tree \ + --column $TS_SELF/files/col-id \ + --column $TS_SELF/files/col-parent \ + --column $TS_SELF/files/col-wrapzero \ + $TS_SELF/files/data-string \ + $TS_SELF/files/data-id \ + $TS_SELF/files/data-parent \ + $TS_SELF/files/data-string-zero \ + >> $TS_OUTPUT 2>> $TS_ERRLOG +ts_finalize_subtest + ts_init_subtest "raw" ts_run $TESTPROG --nlines 10 --raw \ --column $TS_SELF/files/col-name \