-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove.cc
170 lines (149 loc) · 4.89 KB
/
remove.cc
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <text_processing/remove.hpp>
#include <gtest/gtest.h>
TEST(Remove, SimpleWithViews)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove(simple, " "sv);
EXPECT_EQ(result, 3);
EXPECT_EQ(simple, "simplestringwithwords"s);
}
TEST(Remove, ConstVersion)
{
using namespace std::literals;
std::string_view simple("simple string with words");
auto result = Text::removed(simple, " "sv);
EXPECT_EQ(result, "simplestringwithwords"s);
EXPECT_EQ(simple, "simple string with words"s);
}
TEST(Remove, WideView)
{
using namespace std::literals;
std::wstring simple(L"simple string with words");
auto result = Text::remove(simple, L" "sv);
EXPECT_EQ(result, 3);
EXPECT_EQ(simple, L"simplestringwithwords"s);
}
TEST(Remove, OutOfBoundsStart)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove(simple, " "sv, 100);
EXPECT_EQ(result, 0);
EXPECT_EQ(simple, "simple string with words");
}
TEST(Remove, SimpleWithViewsAndText)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove(simple, "string "sv);
EXPECT_EQ(result, 1);
EXPECT_EQ(simple, "simple with words"s);
}
TEST(Remove, SimpleWithViewsAndStart)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove(simple, " "sv, 7);
EXPECT_EQ(result, 2);
EXPECT_EQ(simple, "simple stringwithwords"s);
}
TEST(Remove, SimpleWithViewsAndStartNegative)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove(simple, " "sv, -7);
EXPECT_EQ(result, 1);
EXPECT_EQ(simple, "simple string withwords"s);
}
TEST(Remove, CaseInsensitive)
{
using namespace std::literals;
std::string simple("simple String with words");
auto result = Text::remove(simple, "s"sv, Text::Start, Text::End, Text::Step, Text::Case::Insensitive);
EXPECT_EQ(result, 3);
EXPECT_EQ(simple, "imple tring with word"s);
}
TEST(Remove, WithSteps)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove(simple, "s"sv, 1, Text::End, 2);
EXPECT_EQ(result, 2);
EXPECT_EQ(simple, "simple tring with word"s);
}
TEST(RemoveIf, ConstVersion)
{
using namespace std::literals;
std::string_view simple("simple string with words");
auto result = Text::removed_if(simple, [](auto ch) { return ch > 'u'; });
auto expected = "simple string ith ords"s;
EXPECT_EQ(result, expected);
EXPECT_EQ(simple, "simple string with words");
}
TEST(RemoveIf, ValueLargerThan)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove_if(simple, [](auto ch) { return ch > 'u'; });
auto expected = "simple string ith ords"s;
EXPECT_EQ(result, 2);
EXPECT_EQ(simple, expected);
}
TEST(RemoveIf, OutOfBoundsStart)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove_if(simple, [](auto ch) { return ch > 'u'; }, 100);
EXPECT_EQ(result, 0);
EXPECT_EQ(simple, "simple string with words");
}
TEST(RemoveAny, SimpleWithViews)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove_any(simple, "tg"sv);
EXPECT_EQ(result, 3);
EXPECT_EQ(simple, "simple srin wih words"s);
}
TEST(RemoveAny, SimpleWithViewsAndStart)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove_any(simple, "tg"sv, 9);
EXPECT_EQ(result, 2);
EXPECT_EQ(simple, "simple strin wih words"s);
}
TEST(RemoveAny, OutOfBoundsStart)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove_any(simple, "tg"sv, 100);
EXPECT_EQ(result, 0);
EXPECT_EQ(simple, "simple string with words");
}
TEST(RemoveAny, SimpleWithViewsAndStartNegative)
{
using namespace std::literals;
std::string simple("simple string with words");
auto result = Text::remove_any(simple, "tg"sv, -9);
EXPECT_EQ(result, 1);
EXPECT_EQ(simple, "simple string wih words"s);
}
TEST(RemoveAny, ConstVersion)
{
using namespace std::literals;
std::string_view simple("simple string with words");
auto result = Text::removed_any(simple, "tg"sv);
EXPECT_EQ(result, "simple srin wih words"s);
EXPECT_EQ(simple, "simple string with words");
}
TEST(RemoveAny, CaseInsensitive)
{
using namespace std::literals;
std::string simple("simple String With words");
auto result = Text::remove_any(simple, "Sw"sv, Text::Start, Text::End, Text::Step, Text::Case::Insensitive);
EXPECT_EQ(result, 5);
EXPECT_EQ(simple, "imple tring ith ord");
}
//Add steps for replace/split