]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-strip-tab-ansi.c
Merge pull request #8676 from keszybz/drop-license-boilerplate
[thirdparty/systemd.git] / src / test / test-strip-tab-ansi.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 This file is part of systemd.
4
5 Copyright 2012 Lennart Poettering
6 ***/
7
8 #include <stdio.h>
9
10 #include "string-util.h"
11 #include "terminal-util.h"
12 #include "util.h"
13
14 int main(int argc, char *argv[]) {
15 char *p;
16
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 "));
21 free(p);
22
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!"));
27 free(p);
28
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!"));
32 free(p);
33
34 assert_se(p = strdup("\x1B[waldo"));
35 assert_se(strip_tab_ansi(&p, NULL, NULL));
36 assert_se(streq(p, "\x1B[waldo"));
37 free(p);
38
39 return 0;
40 }