Repository navigation
Expand file tree
/
Copy pathstrtrim.cpp
More file actions
93 lines (68 loc) · 2.16 KB
/
Copy pathstrtrim.cpp
File metadata and controls
93 lines (68 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* strtrim.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kjurkows <kjurkows@student.42warsaw.pl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/06/19 16:04:08 by kjurkows #+# #+# */
/* Updated: 2026/06/25 17:54:18 by kjurkows ### ########.fr */
/* */
/* ************************************************************************** */
#include "_main.hpp"
TEST(strtrim, basic)
{
const char *set = " \n\t";
const char *str = " \n\tHello, World!\n\t ";
char *res = ft_strtrim(str, set);
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "Hello, World!");
free(res);
}
TEST(strtrim, no_trim)
{
const char *set = " \n\t";
const char *str = "Hello, World!";
char *res = ft_strtrim(str, set);
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "Hello, World!");
free(res);
}
TEST(strtrim, all_trim)
{
const char *set = " \n\t";
const char *str = " \n\t \n\t";
char *res = ft_strtrim(str, set);
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "");
free(res);
}
TEST(strtrim, empty_set)
{
const char *set = "";
const char *str = "Hello, World!";
char *res = ft_strtrim(str, set);
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "Hello, World!");
free(res);
}
TEST(strtrimDeathTest, nullptr_set)
{
ASSERT_EXIT({
const char *set = nullptr;
const char *str = "Hello, World!";
char *res = ft_strtrim(str, set);
const int res_cmp = strcmp(res, "Hello, World!");
free(res);
exit(res_cmp);
}, ::testing::ExitedWithCode(0), "");
}
TEST(strtrimDeathTest, nullptr_str)
{
ASSERT_EXIT({
const char *set = " \t";
const char *str = nullptr;
char *res = ft_strtrim(str, set);
exit(!!res);
}, ::testing::ExitedWithCode(0), "");
}