Repository navigation
Expand file tree
/
Copy pathstrmapi.cpp
More file actions
104 lines (81 loc) · 2.24 KB
/
Copy pathstrmapi.cpp
File metadata and controls
104 lines (81 loc) · 2.24 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
94
95
96
97
98
99
100
101
102
103
104
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* strmapi.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kjurkows <kjurkows@student.42warsaw.pl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/06/19 13:40:28 by kjurkows #+# #+# */
/* Updated: 2026/06/25 17:53:14 by kjurkows ### ########.fr */
/* */
/* ************************************************************************** */
#include "_main.hpp"
#include <string.h>
TEST(strmapi, index)
{
const char *str = "9876543210";
char *res = ft_strmapi(str, [](unsigned int i, char c) -> char
{
(void)c;
return ('0' + i);
});
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "0123456789");
free(res);
}
TEST(strmapi, toupper)
{
const char *str = "Hello World!";
char *res = ft_strmapi(str, [](unsigned int i, char c) -> char
{
(void)i;
return (toupper(c));
});
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "HELLO WORLD!");
free(res);
}
TEST(strmapi, tolower)
{
const char *str = "Hello World!";
char *res = ft_strmapi(str, [](unsigned int i, char c) -> char
{
(void)i;
return (tolower(c));
});
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "hello world!");
free(res);
}
TEST(strmapi, empty)
{
const char *str = "";
char *res = ft_strmapi(str, [](unsigned int i, char c) -> char
{
(void)i;
return (c);
});
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "");
free(res);
}
TEST(strmapiDeathTest, nullptr_str)
{
ASSERT_EXIT({
const char *str = nullptr;
char *res = ft_strmapi(str, [](unsigned int i, char c) -> char
{
(void)i;
return (c);
});
exit(!!res);
}, ::testing::ExitedWithCode(0), "");
}
TEST(strmapiDeathTest, nullptr_f)
{
ASSERT_EXIT({
const char *str = "HELLO";
char *res = ft_strmapi(str, nullptr);
exit(!!res);
}, ::testing::ExitedWithCode(0), "");
}