@@ -134,6 +134,58 @@ SCENARIO("split_string", "[core][utils][string_utils][split_string]")
134
134
run_on_all_variants (string, ' ,' , expected_results);
135
135
}
136
136
}
137
+ GIVEN (" A whitespace delimter" )
138
+ {
139
+ std::string string = " a\n b\n c" ;
140
+ const char delimiter = ' \n ' ;
141
+
142
+ WHEN (" Not stripping, not removing empty" )
143
+ {
144
+ std::vector<std::string> result;
145
+ split_string (string, delimiter, result, false , false );
146
+
147
+ THEN (" Should get expected vector" )
148
+ {
149
+ std::vector<std::string> expected_result = {" a" , " b" , " c" };
150
+ REQUIRE_THAT (
151
+ result,
152
+ Catch::Matchers::Vector::EqualsMatcher<std::string>{expected_result});
153
+ }
154
+ }
155
+ WHEN (" Not stripping, removing empty" )
156
+ {
157
+ std::vector<std::string> result;
158
+ split_string (string, delimiter, result, false , true );
159
+
160
+ THEN (" Should get expected vector" )
161
+ {
162
+ std::vector<std::string> expected_result = {" a" , " b" , " c" };
163
+ REQUIRE_THAT (
164
+ result,
165
+ Catch::Matchers::Vector::EqualsMatcher<std::string>{expected_result});
166
+ }
167
+ }
168
+ WHEN (" Stripping, not removing empty" )
169
+ {
170
+ std::vector<std::string> result;
171
+ THEN (" Should throw an exception" )
172
+ {
173
+ REQUIRE_THROWS_AS (
174
+ split_string (string, delimiter, result, true , false ),
175
+ std::invalid_argument);
176
+ }
177
+ }
178
+ WHEN (" Stripping and removing empty" )
179
+ {
180
+ std::vector<std::string> result;
181
+ THEN (" Should throw an exception" )
182
+ {
183
+ REQUIRE_THROWS_AS (
184
+ split_string (string, delimiter, result, true , true ),
185
+ std::invalid_argument);
186
+ }
187
+ }
188
+ }
137
189
}
138
190
139
191
SCENARIO (" split_string into two" , " [core][utils][string_utils][split_string]" )
@@ -155,4 +207,31 @@ SCENARIO("split_string into two", "[core][utils][string_utils][split_string]")
155
207
}
156
208
}
157
209
}
210
+ GIVEN (" A string and a whitespace delimiter" )
211
+ {
212
+ std::string string = " a\n b" ;
213
+ const char delimiter = ' \n ' ;
214
+
215
+ WHEN (" Splitting in two and not stripping" )
216
+ {
217
+ std::string s1;
218
+ std::string s2;
219
+ split_string (string, delimiter, s1, s2, false );
220
+ THEN (" The string should be split" )
221
+ {
222
+ REQUIRE (s1 == " a" );
223
+ REQUIRE (s2 == " b" );
224
+ }
225
+ }
226
+ WHEN (" Splitting in two and stripping" )
227
+ {
228
+ THEN (" An invalid argument exception should be raised" )
229
+ {
230
+ std::string s1;
231
+ std::string s2;
232
+ REQUIRE_THROWS_AS (
233
+ split_string (string, delimiter, s1, s2, true ), std::invalid_argument);
234
+ }
235
+ }
236
+ }
158
237
}
0 commit comments