1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2012 Lennart Poettering
8 #include "alloc-util.h"
9 #include "string-util.h"
10 #include "terminal-util.h"
13 int main(int argc
, char *argv
[]) {
14 _cleanup_free_
char *urlified
= NULL
, *q
= NULL
, *qq
= NULL
;
17 assert_se(p
= strdup("\tFoobar\tbar\twaldo\t"));
18 assert_se(strip_tab_ansi(&p
, NULL
, NULL
));
19 fprintf(stdout
, "<%s>\n", p
);
20 assert_se(streq(p
, " Foobar bar waldo "));
23 assert_se(p
= strdup(ANSI_HIGHLIGHT
"Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED
" world!" ANSI_NORMAL
));
24 assert_se(strip_tab_ansi(&p
, NULL
, NULL
));
25 fprintf(stdout
, "<%s>\n", p
);
26 assert_se(streq(p
, "Hello world!"));
29 assert_se(p
= strdup("\x1B[\x1B[\t\x1B[" ANSI_HIGHLIGHT
"\x1B[" "Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED
" world!" ANSI_NORMAL
));
30 assert_se(strip_tab_ansi(&p
, NULL
, NULL
));
31 assert_se(streq(p
, "\x1B[\x1B[ \x1B[\x1B[Hello world!"));
34 assert_se(p
= strdup("\x1B[waldo"));
35 assert_se(strip_tab_ansi(&p
, NULL
, NULL
));
36 assert_se(streq(p
, "\x1B[waldo"));
39 assert_se(terminal_urlify_path("/etc/fstab", "i am a fabulous link", &urlified
) >= 0);
40 assert_se(p
= strjoin("something ", urlified
, " something-else"));
41 assert_se(q
= strdup(p
));
43 assert_se(strip_tab_ansi(&p
, NULL
, NULL
));
45 assert_se(streq(p
, "something i am a fabulous link something-else"));
48 /* Truncate the formatted string in the middle of an ANSI sequence (in which case we shouldn't touch the
49 * incomplete sequence) */
50 z
= strstr(q
, "fstab");
53 assert_se(qq
= strdup(q
));
54 assert_se(strip_tab_ansi(&q
, NULL
, NULL
));
55 assert_se(streq(q
, qq
));