1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <stdio.h>
4
5 #include "macro.h"
6 #include "replace-var.h"
7 #include "string-util.h"
8 #include "tests.h"
9
lookup(const char * variable,void * userdata)10 static char *lookup(const char *variable, void *userdata) {
11 return strjoin("<<<", variable, ">>>");
12 }
13
TEST(replace_var)14 TEST(replace_var) {
15 char *r;
16
17 assert_se(r = replace_var("@@@foobar@xyz@HALLO@foobar@test@@testtest@TEST@...@@@", lookup, NULL));
18 puts(r);
19 assert_se(streq(r, "@@@foobar@xyz<<<HALLO>>>foobar@test@@testtest<<<TEST>>>...@@@"));
20 free(r);
21 }
22
TEST(strreplace)23 TEST(strreplace) {
24 char *r;
25
26 assert_se(r = strreplace("XYZFFFFXYZFFFFXYZ", "XYZ", "ABC"));
27 puts(r);
28 assert_se(streq(r, "ABCFFFFABCFFFFABC"));
29 free(r);
30 }
31
32 DEFINE_TEST_MAIN(LOG_INFO);
33