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