]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: add wrap-zero test
authorKarel Zak <kzak@redhat.com>
Mon, 23 Oct 2023 12:47:35 +0000 (14:47 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Oct 2023 19:54:01 +0000 (21:54 +0200)
* 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 <kzak@redhat.com>
libsmartcols/samples/fromfile.c
tests/expected/libsmartcols/fromfile-wrapzero [new file with mode: 0644]
tests/expected/libsmartcols/fromfile-wrapzero-tree [new file with mode: 0644]
tests/ts/libsmartcols/files/col-wrapzero [new file with mode: 0644]
tests/ts/libsmartcols/files/data-string-zero [new file with mode: 0644]
tests/ts/libsmartcols/fromfile

index 5c418758a6a10b35901e3d4c156d2ff3ac5dabc4..a921b20a9239612e488287ac2c8a21b7028cda84 100644 (file)
@@ -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 (file)
index 0000000..11370ff
--- /dev/null
@@ -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 (file)
index 0000000..552470d
--- /dev/null
@@ -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 (file)
index 0000000..0849187
--- /dev/null
@@ -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 (file)
index 0000000..5f936f1
--- /dev/null
@@ -0,0 +1,10 @@
+aaa
+bbbbb
+cccc\x00CCCC
+dddddddd\x00DDDD\x00DD
+hello\x00baby
+aaa\x00bbb\x00ccc\x00ddd
+eee
+fffff
+g\x00hhhhh
+ppppppppp
index 45b84716cf13586ce50b23e6cb590719c79e23eb..c11140cb72b39a1af599a44e7c9d7b6adefdf1b0 100755 (executable)
@@ -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 \