-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubstr.cpp
More file actions
82 lines (62 loc) · 2.03 KB
/
Copy pathsubstr.cpp
File metadata and controls
82 lines (62 loc) · 2.03 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* substr.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kjurkows <kjurkows@student.42warsaw.pl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/06/19 14:32:30 by kjurkows #+# #+# */
/* Updated: 2026/06/25 17:54:35 by kjurkows ### ########.fr */
/* */
/* ************************************************************************** */
#include "_main.hpp"
TEST(substr, basic)
{
const char *str = "Hello, World!";
const unsigned int start = 7;
const size_t len = 5;
char *res = ft_substr(str, start, len);
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "World");
free(res);
}
TEST(substr, start_beyond_length)
{
const char *str = "Hello";
const unsigned int start = 10;
const size_t len = 5;
char *res = ft_substr(str, start, len);
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "");
free(res);
}
TEST(substr, length_exceeds)
{
const char *str = "Hello";
const unsigned int start = 1;
const size_t len = 10;
char *res = ft_substr(str, start, len);
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "ello");
free(res);
}
TEST(substr, zero_length)
{
const char *str = "Hello";
const unsigned int start = 1;
const size_t len = 0;
char *res = ft_substr(str, start, len);
ASSERT_NE(res, nullptr);
ASSERT_STREQ(res, "");
free(res);
}
TEST(substrDeathTest, nullptr)
{
ASSERT_EXIT({
const char *str = nullptr;
const unsigned int start = 1;
const size_t len = 5;
char *res = ft_substr(str, start, len);
exit(!!res);
}, ::testing::ExitedWithCode(0), "");
}