summaryrefslogtreecommitdiff
path: root/src/test/test-strip-tab-ansi.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-04-20 15:16:13 +0200
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commit044eac165bdf48b010bceb1038d7b1f7ce732988 (patch)
tree4873526bcdc7bff46ebbb0b26b39d619be1bb6dc /src/test/test-strip-tab-ansi.c
parent6cdfea2bf0fd711bc2a9d56d7e7b596713ad16b7 (diff)
string-util: teach strip_tab_ansi() to deal with CSO sequences
With the recent terminal_urlify() APIs we'll now sometimes generate clickable link CSO sequences. Hence we should also be able to remove them again from strings. This beefs up the logic to do so. Follow-up for: 23b27b39d2a3a002ad827a2e8a9872a51495d797
Diffstat (limited to 'src/test/test-strip-tab-ansi.c')
-rw-r--r--src/test/test-strip-tab-ansi.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/test/test-strip-tab-ansi.c b/src/test/test-strip-tab-ansi.c
index fff3fcd0d..1b5e040a8 100644
--- a/src/test/test-strip-tab-ansi.c
+++ b/src/test/test-strip-tab-ansi.c
@@ -7,12 +7,14 @@
#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;
+ _cleanup_free_ char *urlified = NULL, *q = NULL, *qq = NULL;
+ char *p, *z;
assert_se(p = strdup("\tFoobar\tbar\twaldo\t"));
assert_se(strip_tab_ansi(&p, NULL, NULL));
@@ -36,5 +38,24 @@ int main(int argc, char *argv[]) {
assert_se(streq(p, "\x1B[waldo"));
free(p);
+ 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);
+
+ /* 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;
}