]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-strip-tab-ansi.c
util-lib: split our string related calls from util.[ch] into its own file string...
[thirdparty/systemd.git] / src / test / test-strip-tab-ansi.c
CommitLineData
e8bc0ea2
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2012 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <stdio.h>
23
07630cea 24#include "string-util.h"
288a74cc 25#include "terminal-util.h"
07630cea 26#include "util.h"
e8bc0ea2
LP
27
28int main(int argc, char *argv[]) {
29 char *p;
30
31 assert_se(p = strdup("\tFoobar\tbar\twaldo\t"));
32 assert_se(strip_tab_ansi(&p, NULL));
33 fprintf(stdout, "<%s>\n", p);
34 assert_se(streq(p, " Foobar bar waldo "));
35 free(p);
36
1fc464f6 37 assert_se(p = strdup(ANSI_HIGHLIGHT "Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED " world!" ANSI_NORMAL));
e8bc0ea2
LP
38 assert_se(strip_tab_ansi(&p, NULL));
39 fprintf(stdout, "<%s>\n", p);
40 assert_se(streq(p, "Hello world!"));
41 free(p);
42
1fc464f6 43 assert_se(p = strdup("\x1B[\x1B[\t\x1B[" ANSI_HIGHLIGHT "\x1B[" "Hello" ANSI_NORMAL ANSI_HIGHLIGHT_RED " world!" ANSI_NORMAL));
e8bc0ea2
LP
44 assert_se(strip_tab_ansi(&p, NULL));
45 assert_se(streq(p, "\x1B[\x1B[ \x1B[\x1B[Hello world!"));
46 free(p);
47
48 assert_se(p = strdup("\x1B[waldo"));
49 assert_se(strip_tab_ansi(&p, NULL));
50 assert_se(streq(p, "\x1B[waldo"));
51 free(p);
52
53 return 0;
54}