]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
e8bc0ea2 LP |
2 | |
3 | #include <stdio.h> | |
4 | ||
695a944c | 5 | #include "alloc-util.h" |
294bf0c3 | 6 | #include "pretty-print.h" |
07630cea | 7 | #include "string-util.h" |
288a74cc | 8 | #include "terminal-util.h" |
07630cea | 9 | #include "util.h" |
e8bc0ea2 LP |
10 | |
11 | int main(int argc, char *argv[]) { | |
695a944c LP |
12 | _cleanup_free_ char *urlified = NULL, *q = NULL, *qq = NULL; |
13 | char *p, *z; | |
e8bc0ea2 LP |
14 | |
15 | assert_se(p = strdup("\tFoobar\tbar\twaldo\t")); | |
b4766d5f | 16 | assert_se(strip_tab_ansi(&p, NULL, NULL)); |
e8bc0ea2 LP |
17 | fprintf(stdout, "<%s>\n", p); |
18 | assert_se(streq(p, " Foobar bar waldo ")); | |
19 | free(p); | |
20 | ||
1fc464f6 | 21 | assert_se(p = strdup(ANSI_HIGHLIGHT "Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED " world!" ANSI_NORMAL)); |
b4766d5f | 22 | assert_se(strip_tab_ansi(&p, NULL, NULL)); |
e8bc0ea2 LP |
23 | fprintf(stdout, "<%s>\n", p); |
24 | assert_se(streq(p, "Hello world!")); | |
25 | free(p); | |
26 | ||
1fc464f6 | 27 | assert_se(p = strdup("\x1B[\x1B[\t\x1B[" ANSI_HIGHLIGHT "\x1B[" "Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED " world!" ANSI_NORMAL)); |
b4766d5f | 28 | assert_se(strip_tab_ansi(&p, NULL, NULL)); |
e8bc0ea2 LP |
29 | assert_se(streq(p, "\x1B[\x1B[ \x1B[\x1B[Hello world!")); |
30 | free(p); | |
31 | ||
32 | assert_se(p = strdup("\x1B[waldo")); | |
b4766d5f | 33 | assert_se(strip_tab_ansi(&p, NULL, NULL)); |
e8bc0ea2 LP |
34 | assert_se(streq(p, "\x1B[waldo")); |
35 | free(p); | |
36 | ||
695a944c LP |
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)); | |
40 | printf("<%s>\n", p); | |
41 | assert_se(strip_tab_ansi(&p, NULL, NULL)); | |
42 | printf("<%s>\n", p); | |
43 | assert_se(streq(p, "something i am a fabulous link something-else")); | |
44 | p = mfree(p); | |
45 | ||
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"); | |
49 | if (z) { | |
50 | *z = 0; | |
51 | assert_se(qq = strdup(q)); | |
52 | assert_se(strip_tab_ansi(&q, NULL, NULL)); | |
53 | assert_se(streq(q, qq)); | |
54 | } | |
55 | ||
e8bc0ea2 LP |
56 | return 0; |
57 | } |