@@ -281,6 +281,7 @@ defmodule StringTest do
281281 end
282282
283283 test :starts_with? do
284+ ## Normal cases ##
284285 assert String . starts_with? "hello" , "he"
285286 assert String . starts_with? "hello" , "hello"
286287 assert String . starts_with? "hello" , [ "hellö" , "hell" ]
@@ -289,9 +290,28 @@ defmodule StringTest do
289290 refute String . starts_with? "hello" , "hellö"
290291 refute String . starts_with? "hello" , [ "hellö" , "goodbye" ]
291292 refute String . starts_with? "エリクシア" , "仙丹"
293+
294+ ## Edge cases ##
295+ assert String . starts_with? "" , ""
296+ assert String . starts_with? "" , [ "" , "a" ]
297+ assert String . starts_with? "b" , [ "" , "a" ]
298+
299+ assert String . starts_with? "abc" , ""
300+ assert String . starts_with? "abc" , [ "" ]
301+
302+ refute String . starts_with? "" , "abc"
303+ refute String . starts_with? "" , [ " " ]
304+
305+ ## Sanity checks ##
306+ assert String . starts_with? "" , [ "" , "" ]
307+ assert String . starts_with? "abc" , [ "" , "" ]
308+ assert_raise ArgumentError , fn ->
309+ String . starts_with? "abc" , [ [ "a" ] , "a" ]
310+ end
292311 end
293312
294313 test :ends_with? do
314+ ## Normal cases ##
295315 assert String . ends_with? "hello" , "lo"
296316 assert String . ends_with? "hello" , "hello"
297317 assert String . ends_with? "hello" , [ "hell" , "lo" , "xx" ]
@@ -301,15 +321,49 @@ defmodule StringTest do
301321 refute String . ends_with? "hello" , "hellö"
302322 refute String . ends_with? "hello" , [ "hel" , "goodbye" ]
303323 refute String . ends_with? "エリクシア" , "仙丹"
324+
325+ ## Edge cases ##
326+ assert String . ends_with? "" , ""
327+ assert String . ends_with? "" , [ "" , "a" ]
328+ refute String . ends_with? "" , [ "a" , "b" ]
329+
330+ assert String . ends_with? "abc" , ""
331+ assert String . ends_with? "abc" , [ "" , "x" ]
332+
333+ refute String . ends_with? "" , "abc"
334+ refute String . ends_with? "" , [ " " ]
335+
336+ ## Sanity checks ##
337+ assert String . ends_with? "" , [ "" , "" ]
338+ assert String . ends_with? "abc" , [ "" , "" ]
339+ assert_raise ArgumentError , fn ->
340+ String . ends_with? "abc" , [ [ "c" ] , "c" ]
341+ end
304342 end
305343
306344 test :contains? do
345+ ## Normal cases ##
307346 assert String . contains? "elixir of life" , "of"
308347 assert String . contains? "エリクシア" , "シ"
309348 assert String . contains? "elixir of life" , [ "mercury" , "life" ]
310349 refute String . contains? "exlixir of life" , "death"
311350 refute String . contains? "エリクシア" , "仙"
312351 refute String . contains? "elixir of life" , [ "death" , "mercury" , "eternal life" ]
352+
353+ ## Edge cases ##
354+ assert String . contains? "" , ""
355+ assert String . contains? "abc" , ""
356+ assert String . contains? "abc" , [ "" , "x" ]
357+
358+ refute String . contains? "" , " "
359+ refute String . contains? "" , "a"
360+
361+ ## Sanity checks ##
362+ assert String . contains? "" , [ "" , "" ]
363+ assert String . contains? "abc" , [ "" , "" ]
364+ assert_raise ArgumentError , fn ->
365+ String . contains? "abc" , [ [ "b" ] , "b" ]
366+ end
313367 end
314368
315369end
0 commit comments