On a Friday in 2026, Peter Krempa via Devel wrote:
From: Peter Krempa <[email protected]>

The new test case iterates over all combinations and tries the
formatting of the table with strings of 3 distinct lengths (1 char, 8
chars and maximum widht that fits in the column (8+3 characters)).


width

Signed-off-by: Peter Krempa <[email protected]>
---
tests/vshtabletest.c                         | 68 ++++++++++++++++++++
tests/vshtabletestdata/testRowsWithFlags.out | 24 +++++++
2 files changed, 92 insertions(+)
create mode 100644 tests/vshtabletestdata/testRowsWithFlags.out

diff --git a/tests/vshtabletest.c b/tests/vshtabletest.c
index bb75a41418..e4c670d27f 100644
--- a/tests/vshtabletest.c
+++ b/tests/vshtabletest.c
@@ -316,6 +316,71 @@ testNTables(const void *opaque G_GNUC_UNUSED)
    return 0;
}

+
+static int
+testRowsWithFlags(const void *opaque G_GNUC_UNUSED)
+{
+    g_autoptr(vshTable) t = vshTableNew("comment", "|", "content", "|", NULL);
+    g_autofree char *act  = NULL;
+    unsigned int fl;
+    unsigned int maxfl = VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING | VSH_TABLE_CELL_ALIGN_RIGHT;
+
+    for (fl = 0; fl <= maxfl; fl++) {
+        size_t maxlen = 8;
+        g_auto(virBuffer) b = VIR_BUFFER_INITIALIZER;
+        g_auto(virBuffer) n = VIR_BUFFER_INITIALIZER;
+        size_t i;
+
+        virBufferAddLit(&n, "base");
+
+        if (fl & VSH_TABLE_CELL_SKIP_LEADING) {
+            maxlen += 1;
+            virBufferAddLit(&n, "+skip_leading");
+        }
+
+        if (fl & VSH_TABLE_CELL_SKIP_TRAILING) {
+            maxlen += 2;
+            virBufferAddLit(&n, "+skip_trailing");
+        }
+
+        if (fl & VSH_TABLE_CELL_ALIGN_RIGHT) {
+            virBufferAddLit(&n, "+align_right");
+        }

These would look nicer in the test name. With the added benefit of
having the test output separated from the names.

Anyway,
Reviewed-by: Ján Tomko <[email protected]>

Jano

+
+        for (i = 0; i < maxlen; i++)
+            virBufferAddChar(&b, 'b');
+
+        vshTableRowAppendFlags(t,
+                               VSH_TABLE_CELL_DEFAULT, 
virBufferCurrentContent(&n),
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               fl, "short",
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               0, NULL);
+
+        vshTableRowAppendFlags(t,
+                               VSH_TABLE_CELL_DEFAULT, 
virBufferCurrentContent(&n),
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               fl, "8__chars",
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               0, NULL);
+
+        vshTableRowAppendFlags(t,
+                               VSH_TABLE_CELL_DEFAULT, 
virBufferCurrentContent(&n),
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               fl, virBufferCurrentContent(&b),
+                               VSH_TABLE_CELL_SKIP_LEADING | 
VSH_TABLE_CELL_SKIP_TRAILING, "|",
+                               0, NULL);
+    }
+
+    act = vshTablePrintToString(t, false);
+
+    if (virTestCompareToFile(act, abs_srcdir 
"/vshtabletestdata/testRowsWithFlags.out") < 0)
+        return -1;
+
+    return 0;
+}
+
+
static int
mymain(void)
{

Attachment: signature.asc
Description: PGP signature

Reply via email to