Change string_contains
[libstring.git] / test / main.c
blob68b51b68333c505e59dbf6af1b95af3645aa0ebd
1 #include "../src/libstring.h"
2 #include <stdio.h>
4 int main(void)
6 cstr_t * str1 = string_init("THE CARMESIM PROJECT.");
7 cstr_t * str2 = string_init("The Carmesim Project.");
9 //! Testing string_to_lower_case(cstr_t*, bool)
10 printf("Testing string_to_lower_case(cstr_t*, bool)\n");
12 printf("Before: %s\n", str1->value);
13 cstr_t * str1low = string_to_lower_case(str1); //! str1low is a copy of str1 with all lower-case characters.
14 printf("After: %s\n", str1low->value);
15 //!
17 //! Testing string_to_upper_case(cstr_t*)
18 printf("Testing string_to_upper_case(cstr_t*, bool)\n");
20 printf("Before: %s\n", str2->value);
21 cstr_t * str2low = string_to_upper_case(str2); //! str1low is a copy of str1 with all lower-case characters.
22 printf("After: %s\n", str2low->value);
23 //!
25 //! Testing string_resize(cstr_t*, bool);
26 printf("Testing string_to_upper_case(cstr_t*, bool);\n");
27 if (string_reserve(str1, 55))
29 printf("string_reserve worked with cap=%zu.\n", str1->reserved);
31 //!
33 //! Testing string_swap();
34 printf("Testing string_swap(cstr_t*, cstr_t*);\n");
36 printf("Before string_swap: str1->val = %s, str2->val = %s.\n", str1->value, str2->value);
37 if(string_swap(str1, str2))
39 printf("string_swap worked.\n");
40 printf("After string_swap: str1->val = %s, str2->val = %s.\n", str1->value, str2->value);
42 //!
44 //! Testing string_replace_char(cstr_t *, char, char);
45 string_replace_char(str2, 'T', 'o');
46 printf("After string_replace_char: str2->val = %s.\n", str2->value);
47 //!
49 //! Testing string_contains(cstr_t *, cstr_t *) and string_replace(cstr_t *, const char *);
50 printf("\nTesting string_contains(cstr_t *, cstr_t *) and string_replace(cstr_t *, const char *);\n");
51 string_replace(str1, "carmesim");
52 if (string_contains(str1, "armes"))
54 printf("%s is in %s\n", "armes", str1->value);
56 //!
57 string_free_all();