chiark / gitweb /
Prep v239: Do not test terminal_urlify_path()
[elogind.git] / src / test / test-strip-tab-ansi.c
index fff3fcd0d7519c5d2ddd257ff6a5922a913c53a1..8ee10fd0c47bbf0b1a39ae02a1fbc9f2e4ee7f91 100644 (file)
@@ -1,18 +1,19 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-  This file is part of systemd.
-
-  Copyright 2012 Lennart Poettering
-***/
 
 #include <stdio.h>
 
+#include "alloc-util.h"
 #include "string-util.h"
 #include "terminal-util.h"
 #include "util.h"
 
 int main(int argc, char *argv[]) {
-        char *p;
+#if 0 /// urlified is UNNEEDED by elogind
+        _cleanup_free_ char *urlified = NULL, *q = NULL, *qq = NULL;
+#else
+        _cleanup_free_ char *q = NULL, *qq = NULL;
+#endif // 0
+        char *p, *z;
 
         assert_se(p = strdup("\tFoobar\tbar\twaldo\t"));
         assert_se(strip_tab_ansi(&p, NULL, NULL));
@@ -36,5 +37,26 @@ int main(int argc, char *argv[]) {
         assert_se(streq(p, "\x1B[waldo"));
         free(p);
 
+#if 0 /// UNNEEDED by elogind
+        assert_se(terminal_urlify_path("/etc/fstab", "i am a fabulous link", &urlified) >= 0);
+        assert_se(p = strjoin("something ", urlified, " something-else"));
+        assert_se(q = strdup(p));
+        printf("<%s>\n", p);
+        assert_se(strip_tab_ansi(&p, NULL, NULL));
+        printf("<%s>\n", p);
+        assert_se(streq(p, "something i am a fabulous link something-else"));
+        p = mfree(p);
+#endif // 0
+
+        /* Truncate the formatted string in the middle of an ANSI sequence (in which case we shouldn't touch the
+         * incomplete sequence) */
+        z = strstr(q, "fstab");
+        if (z) {
+                *z = 0;
+                assert_se(qq = strdup(q));
+                assert_se(strip_tab_ansi(&q, NULL, NULL));
+                assert_se(streq(q, qq));
+        }
+
         return 0;
 }