1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "alloc-util.h"
6 #include "pretty-print.h"
7 #include "string-util.h"
8 #include "terminal-util.h"
11 int main(int argc
, char *argv
[]) {
12 _cleanup_free_
char *urlified
= NULL
, *q
= NULL
, *qq
= NULL
;
15 assert_se(p
= strdup("\tFoobar\tbar\twaldo\t"));
16 assert_se(strip_tab_ansi(&p
, NULL
, NULL
));
17 fprintf(stdout
, "<%s>\n", p
);
18 assert_se(streq(p
, " Foobar bar waldo "));
21 assert_se(p
= strdup(ANSI_HIGHLIGHT
"Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED
" world!" ANSI_NORMAL
));
22 assert_se(strip_tab_ansi(&p
, NULL
, NULL
));
23 fprintf(stdout
, "<%s>\n", p
);
24 assert_se(streq(p
, "Hello world!"));
27 assert_se(p
= strdup("\x1B[\x1B[\t\x1B[" ANSI_HIGHLIGHT
"\x1B[" "Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED
" world!" ANSI_NORMAL
));
28 assert_se(strip_tab_ansi(&p
, NULL
, NULL
));
29 assert_se(streq(p
, "\x1B[\x1B[ \x1B[\x1B[Hello world!"));
32 assert_se(p
= strdup("\x1B[waldo"));
33 assert_se(strip_tab_ansi(&p
, NULL
, NULL
));
34 assert_se(streq(p
, "\x1B[waldo"));
37 assert_se(terminal_urlify_path("/etc/fstab", "i am a fabulous link", &urlified
) >= 0);
38 assert_se(p
= strjoin("something ", urlified
, " something-else"));
39 assert_se(q
= strdup(p
));
41 assert_se(strip_tab_ansi(&p
, NULL
, NULL
));
43 assert_se(streq(p
, "something i am a fabulous link something-else"));
46 /* Truncate the formatted string in the middle of an ANSI sequence (in which case we shouldn't touch the
47 * incomplete sequence) */
48 z
= strstr(q
, "fstab");
51 assert_se(qq
= strdup(q
));
52 assert_se(strip_tab_ansi(&q
, NULL
, NULL
));
53 assert_se(streq(q
, qq
));