1
1
#include " case_insensitive_string.h"
2
2
3
- #include < src/util/generic/string_ut.h>
4
-
5
- class TCaseInsensitiveStringTest : public TTestBase , private TStringTestImpl <TCaseInsensitiveString, TTestData<char >> {
6
- public:
7
- UNIT_TEST_SUITE (TCaseInsensitiveStringTest);
8
- UNIT_TEST (TestOperators);
9
- UNIT_TEST (TestOperatorsCI);
10
-
11
- UNIT_TEST_SUITE_END ();
12
- };
13
-
14
- UNIT_TEST_SUITE_REGISTRATION (TCaseInsensitiveStringTest);
3
+ #include < src/library/testing/unittest/registar.h>
15
4
16
5
Y_UNIT_TEST_SUITE (TCaseInsensitiveCharTraits) {
17
6
Y_UNIT_TEST (EqualTo) {
@@ -30,12 +19,12 @@ Y_UNIT_TEST_SUITE(TCaseInsensitiveCharTraits) {
30
19
for (const auto & [c1, c2, answer] : cases) {
31
20
const auto uc1 = static_cast <char >(std::toupper (static_cast <unsigned char >(c1)));
32
21
const auto uc2 = static_cast <char >(std::toupper (static_cast <unsigned char >(c2)));
33
-
22
+
34
23
UNIT_ASSERT_EQUAL (eq (c1, c2), answer);
35
24
UNIT_ASSERT_EQUAL (eq (c2, c1), answer);
36
25
UNIT_ASSERT_EQUAL (eq_int_type (to_int_type (c1), to_int_type (c2)), answer);
37
26
UNIT_ASSERT_EQUAL (eq_int_type (to_int_type (c2), to_int_type (c1)), answer);
38
-
27
+
39
28
UNIT_ASSERT_EQUAL (eq (c1, uc2), answer);
40
29
UNIT_ASSERT_EQUAL (eq (uc2, c1), answer);
41
30
UNIT_ASSERT_EQUAL (eq_int_type (to_int_type (c1), to_int_type (uc2)), answer);
@@ -45,7 +34,7 @@ Y_UNIT_TEST_SUITE(TCaseInsensitiveCharTraits) {
45
34
UNIT_ASSERT_EQUAL (eq (c2, uc1), answer);
46
35
UNIT_ASSERT_EQUAL (eq_int_type (to_int_type (uc1), to_int_type (c2)), answer);
47
36
UNIT_ASSERT_EQUAL (eq_int_type (to_int_type (c2), to_int_type (uc1)), answer);
48
-
37
+
49
38
UNIT_ASSERT_EQUAL (eq (uc1, uc2), answer);
50
39
UNIT_ASSERT_EQUAL (eq (uc2, uc1), answer);
51
40
UNIT_ASSERT_EQUAL (eq_int_type (to_int_type (uc1), to_int_type (uc2)), answer);
@@ -95,7 +84,7 @@ Y_UNIT_TEST_SUITE(TCaseInsensitiveCharTraits) {
95
84
{" Bar" , " bAR" , 4 },
96
85
};
97
86
98
- for (const auto & [s1, s2, size] : equal_cases) {
87
+ for (const auto & [s1, s2, size] : equal_cases) {
99
88
for (std::size_t n = 0 ; n < size; ++n) {
100
89
UNIT_ASSERT_EQUAL (compare (s1, s1, n), 0 );
101
90
UNIT_ASSERT_EQUAL (compare (s2, s2, n), 0 );
@@ -141,13 +130,13 @@ Y_UNIT_TEST_SUITE(TCaseInsensitiveCharTraits) {
141
130
142
131
UNIT_ASSERT_EQUAL (find (s1, 0 , ch), nullptr );
143
132
UNIT_ASSERT_EQUAL (find (s1, 0 , uch), nullptr );
144
-
133
+
145
134
UNIT_ASSERT_EQUAL (find (s2, 0 , ch), nullptr );
146
135
UNIT_ASSERT_EQUAL (find (s2, 0 , uch), nullptr );
147
136
148
137
UNIT_ASSERT_EQUAL (find (s1, offset, ch), nullptr );
149
138
UNIT_ASSERT_EQUAL (find (s1, offset, uch), nullptr );
150
-
139
+
151
140
UNIT_ASSERT_EQUAL (find (s2, offset, ch), nullptr );
152
141
UNIT_ASSERT_EQUAL (find (s2, offset, uch), nullptr );
153
142
@@ -160,53 +149,105 @@ Y_UNIT_TEST_SUITE(TCaseInsensitiveCharTraits) {
160
149
}
161
150
}
162
151
163
- Y_UNIT_TEST_SUITE (TCaseInsensitiveStringTestEx) {
164
- Y_UNIT_TEST (BasicTString) {
165
- TCaseInsensitiveString foo (" foo" );
166
- TCaseInsensitiveString FOO (" FOO" );
167
- TCaseInsensitiveString Bar (" Bar" );
168
- TCaseInsensitiveString bAR (" bAR" );
152
+ Y_UNIT_TEST_SUITE (TCaseInsensitiveStringTest) {
153
+ using TCIString = TCaseInsensitiveString;
154
+ using TCIStringBuf = TCaseInsensitiveStringBuf;
169
155
170
- UNIT_ASSERT_EQUAL (foo, FOO);
171
- UNIT_ASSERT_EQUAL (Bar, bAR);
156
+ Y_UNIT_TEST (TestOperators) {
157
+ TCIString s (" 0123456" );
158
+
159
+ const auto x = " x" ;
160
+ const auto y = " y" ;
161
+ const auto z = " z" ;
162
+
163
+ // operator +=
164
+ s += TCIString (x);
165
+ UNIT_ASSERT (s == " 0123456x" );
172
166
173
- constexpr TCaseInsensitiveStringBuf foobar (" foobar" );
174
- UNIT_ASSERT (foobar.StartsWith (foo));
175
- UNIT_ASSERT (foobar.StartsWith (FOO));
176
- UNIT_ASSERT (foobar.EndsWith (Bar));
177
- UNIT_ASSERT (foobar.EndsWith (bAR));
178
- UNIT_ASSERT (foobar.Contains (FOO));
179
- UNIT_ASSERT (foobar.Contains (Bar));
167
+ s += y;
168
+ UNIT_ASSERT (s == " 0123456xy" );
169
+
170
+ s += *z;
171
+ UNIT_ASSERT (s == " 0123456xyz" );
172
+
173
+ // operator +
174
+ s = " 0123456" ;
175
+ s = s + TCIString (x);
176
+ UNIT_ASSERT (s == " 0123456x" );
177
+
178
+ s = s + y;
179
+ UNIT_ASSERT (s == " 0123456xy" );
180
+
181
+ s = s + *z;
182
+ UNIT_ASSERT (s == " 0123456xyz" );
183
+
184
+ // operator !=
185
+ s = " 012345" ;
186
+ const auto xyz = " xyz" ;
187
+ UNIT_ASSERT (s != TCIString (xyz));
188
+ UNIT_ASSERT (s != xyz);
189
+ UNIT_ASSERT (xyz != s);
190
+
191
+ // operator <
192
+ UNIT_ASSERT_EQUAL (s < TCIString (xyz), true );
193
+ UNIT_ASSERT_EQUAL (s < xyz, true );
194
+ UNIT_ASSERT_EQUAL (xyz < s, false );
195
+
196
+ // operator <=
197
+ UNIT_ASSERT_EQUAL (s <= TCIString (xyz), true );
198
+ UNIT_ASSERT_EQUAL (s <= xyz, true );
199
+ UNIT_ASSERT_EQUAL (xyz <= s, false );
200
+
201
+ // operator >
202
+ UNIT_ASSERT_EQUAL (s > TCIString (xyz), false );
203
+ UNIT_ASSERT_EQUAL (s > xyz, false );
204
+ UNIT_ASSERT_EQUAL (xyz > s, true );
205
+
206
+ // operator >=
207
+ UNIT_ASSERT_EQUAL (s >= TCIString (xyz), false );
208
+ UNIT_ASSERT_EQUAL (s >= xyz, false );
209
+ UNIT_ASSERT_EQUAL (xyz >= s, true );
180
210
}
181
211
182
- Y_UNIT_TEST (BasicStdString) {
183
- using TCaseInsensitiveStdString = std::basic_string<char , TCaseInsensitiveCharTraits>;
184
- using TCaseInsensitiveStringView = std::basic_string_view<char , TCaseInsensitiveCharTraits>;
212
+ Y_UNIT_TEST (TestOperatorsCI) {
213
+ TCIString s (" ABCD" );
214
+ UNIT_ASSERT (s > " abc0123456xyz" );
215
+ UNIT_ASSERT (s == " abcd" );
216
+ UNIT_ASSERT (s > TCIStringBuf (" abc0123456xyz" ));
217
+ UNIT_ASSERT (TCIStringBuf (" abc0123456xyz" ) < s);
218
+ UNIT_ASSERT (s == TCIStringBuf (" abcd" ));
219
+ }
185
220
186
- TCaseInsensitiveStdString foo (" foo" );
187
- TCaseInsensitiveStdString FOO (" FOO" );
188
- TCaseInsensitiveStdString Bar (" Bar" );
189
- TCaseInsensitiveStdString bAR (" bAR" );
221
+ Y_UNIT_TEST (BasicStdString) {
222
+ TCIString foo (" foo" );
223
+ TCIString FOO (" FOO" );
224
+ TCIString Bar (" Bar" );
225
+ TCIString bAR (" bAR" );
190
226
191
227
UNIT_ASSERT_EQUAL (foo, FOO);
192
228
UNIT_ASSERT_EQUAL (Bar, bAR);
193
229
194
- constexpr TCaseInsensitiveStringView foobar (" foobar" );
230
+ constexpr TCIStringBuf foobar (" foobar" );
195
231
UNIT_ASSERT (foobar.starts_with (foo));
196
232
UNIT_ASSERT (foobar.starts_with (FOO));
197
233
UNIT_ASSERT (foobar.ends_with (Bar));
198
234
UNIT_ASSERT (foobar.ends_with (bAR));
199
- // TODO: test contains after C++23
235
+ #if __cpp_lib_string_contains >= 202011L
236
+ UNIT_ASSERT (foobar.contains (FOO));
237
+ UNIT_ASSERT (foobar.contains (Bar));
238
+ #endif
200
239
}
201
240
202
- /*
241
+ // StringSplitter does not use CharTraits properly
242
+ // Splitting such strings is explicitly disabled.
243
+ #if 0
203
244
Y_UNIT_TEST(TestSplit) {
204
- TCaseInsensitiveStringBuf input("splitAmeAbro");
205
- std::vector<TCaseInsensitiveStringBuf > expected{"split", "me", "bro"};
245
+ TCIStringBuf input("splitAmeAbro");
246
+ std::vector<TCIStringBuf > expected{"split", "me", "bro"};
206
247
207
- std::vector<TCaseInsensitiveStringBuf > split = StringSplitter(input).Split('a');
248
+ std::vector<TCIStringBuf > split = StringSplitter(input).Split('a');
208
249
209
250
UNIT_ASSERT_VALUES_EQUAL(split, expected);
210
251
}
211
- */
252
+ # endif
212
253
}
0 commit comments