@@ -219,4 +219,127 @@ void main() {
219219 expect (StringUtils .isIP ('0.0.0.256' ), false );
220220 expect (StringUtils .isIP ('26.0.0.256' ), false );
221221 });
222+
223+ group ('strip extension' , () {
224+ test ('strip' , () {
225+ // tested function's comment
226+ expect ('@£^£Some @£^ Thing@@£@^' .strip ('@£^' ), 'Some @£^ Thing' );
227+
228+ // edge cases that doesn't modify the string
229+ expect ('something' .strip ('@' ), 'something' );
230+ expect ('something' .strip ('@£^' ), 'something' );
231+ expect ('something' .strip ('' ), 'something' );
232+
233+ // remove a single character at either end from the source
234+ expect ('@something' .strip ('@' ), 'something' );
235+ expect ('@something@' .strip ('@' ), 'something' );
236+ expect ('something@' .strip ('@' ), 'something' );
237+
238+ // remove more than one character at either end from the source
239+ expect ('@@@something' .strip ('@' ), 'something' );
240+ expect ('@@something@@@' .strip ('@' ), 'something' );
241+ expect ('something@@@' .strip ('@' ), 'something' );
242+
243+ // search-string with multiple characters in it
244+ expect ('@£something' .strip ('@£' ), 'something' );
245+ expect ('@£something@£^' .strip ('@£^' ), 'something' );
246+ expect ('something@£^' .strip ('@£^' ), 'something' );
247+
248+ // source string with strip-chars in the middle
249+ expect ('@£some@£^thing' .strip ('@£' ), 'some@£^thing' );
250+ expect ('@£some@£^thing@£@' .strip ('@£' ), 'some@£^thing' );
251+ expect ('some@£^thing@£@' .strip ('@£' ), 'some@£^thing' );
252+
253+ // strip returns an empty string
254+ expect ('@@@@@£^^£@£' .strip ('@£^' ), '' );
255+ expect ('' .strip ('@£^' ), '' );
256+ expect ('' .strip ('' ), '' );
257+ expect ('2' .strip ('2' ), '' );
258+
259+ // results in a string with one character in it
260+ expect ('£@£@£@£@3@££££@^' .strip ('£@^' ), '3' );
261+
262+ // ensure that strip works with unicode chars: this text in in the script "Malayalam"
263+ expect ('വ മലയാളം' .strip ('' ), 'വ മലയാളം' );
264+ expect ('വ മലയാളം' .strip ('വ' ), ' മലയാളം' );
265+ expect ('വ മലയാളംx' .strip ('xവ' ), ' മലയാളം' );
266+ expect ('kമലയാളംx' .strip ('xk' ), 'മലയാളം' );
267+ });
268+ test ('stripLeft' , () {
269+ // tested function's comment
270+ expect ('@£^£Some @£^ Thing@@£@^' .stripLeft ('@£^' ), 'Some @£^ Thing@@£@^' );
271+
272+ // edge cases that doesn't modify the string
273+ expect ('something' .stripLeft ('@' ), 'something' );
274+ expect ('something' .stripLeft ('@£^' ), 'something' );
275+ expect ('something' .stripLeft ('' ), 'something' );
276+
277+ // remove a single character at the beginning
278+ expect ('@something' .stripLeft ('@' ), 'something' );
279+ expect ('@something@' .stripLeft ('@' ), 'something@' );
280+ expect ('something@' .stripLeft ('@' ), 'something@' );
281+
282+ // remove more than one character from the beginning
283+ expect ('@@@something' .stripLeft ('@' ), 'something' );
284+ expect ('@@something@@@' .stripLeft ('@' ), 'something@@@' );
285+ expect ('something@@@' .stripLeft ('@' ), 'something@@@' );
286+
287+ // search-string with multiple characters in it
288+ expect ('@£something' .stripLeft ('@£' ), 'something' );
289+ expect ('@£something@£@' .stripLeft ('@£' ), 'something@£@' );
290+ expect ('something@£@' .stripLeft ('@£' ), 'something@£@' );
291+
292+ // source string with strip-chars in the middle
293+ expect ('@£some@£^thing' .stripLeft ('@£' ), 'some@£^thing' );
294+ expect ('@£some@£^thing@£@' .stripLeft ('@£' ), 'some@£^thing@£@' );
295+ expect ('some@£^thing@£@' .stripLeft ('@£' ), 'some@£^thing@£@' );
296+
297+ // strip returns an empty string
298+ expect ('@@@@@£^£@£' .stripLeft ('@£^' ), '' );
299+ expect ('' .stripLeft ('@£^' ), '' );
300+ expect ('' .stripLeft ('' ), '' );
301+ expect ('2' .stripLeft ('2' ), '' );
302+
303+ // results in a string with one character in it
304+ expect ('£@£@£@£@3' .stripLeft ('£@^' ), '3' );
305+ });
306+ test ('stripRight' , () {
307+ // tested function's comment
308+ expect ('@£^£Some @£^ Thing@@£@^' .stripRight ('@£^' ),'@£^£Some @£^ Thing' );
309+
310+ // edge cases that doesn't modify the string
311+ expect ('something' .stripRight ('@' ), 'something' );
312+ expect ('something' .stripRight ('@£^' ), 'something' );
313+ expect ('something' .stripRight ('' ), 'something' );
314+
315+ // remove a single character at the end
316+ expect ('@something' .stripRight ('@' ), '@something' );
317+ expect ('@something@' .stripRight ('@' ), '@something' );
318+ expect ('something@' .stripRight ('@' ), 'something' );
319+
320+ // remove more than one character from the end
321+ expect ('@@@something' .stripRight ('@' ), '@@@something' );
322+ expect ('@@something@@@' .stripRight ('@' ), '@@something' );
323+ expect ('something@@@' .stripRight ('@' ), 'something' );
324+
325+ // search-string with multiple characters in it
326+ expect ('@£something' .stripRight ('£@' ), '@£something' );
327+ expect ('@£something@£@' .stripRight ('@£' ), '@£something' );
328+ expect ('something@£@' .stripRight ('@£' ), 'something' );
329+
330+ // source string with strip-chars in the middle
331+ expect ('@£some@£^thing' .stripRight ('@£' ), '@£some@£^thing' );
332+ expect ('@£some@£^thing@£@' .stripRight ('@£' ), '@£some@£^thing' );
333+ expect ('some@£^thing@£@' .stripRight ('@£' ), 'some@£^thing' );
334+
335+ // strip returns an empty string
336+ expect ('@@@@@£^£@£' .stripRight ('@£^' ), '' );
337+ expect ('' .stripRight ('@£^' ), '' );
338+ expect ('' .stripRight ('' ), '' );
339+ expect ('2' .stripRight ('2' ), '' );
340+
341+ // results in a string with one character in it
342+ expect ('3@££££@^' .strip ('£@^' ), '3' );
343+ });
344+ });
222345}
0 commit comments