Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 397c9fb

Browse files
committed
Additional String.Join tests for null separators and empty arrays
1 parent dc801a5 commit 397c9fb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/System.Runtime/tests/System/String.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,12 +704,18 @@ public static void TestJoin()
704704
String s;
705705

706706
// String Array
707+
s = String.Join("$$", new String[] { }, 0, 0);
708+
Assert.Equal("", s);
709+
707710
s = String.Join("$$", new String[] { null }, 0, 1);
708711
Assert.Equal("", s);
709712

710713
s = String.Join("$$", new String[] { null, "Bar", null }, 0, 3);
711714
Assert.Equal("$$Bar$$", s);
712715

716+
s = String.Join(null, new String[] { "Foo", "Bar", "Baz" }, 0, 3);
717+
Assert.Equal("FooBarBaz", s);
718+
713719
s = String.Join("$$", new String[] { "Foo", "Bar", "Baz" }, 0, 3);
714720
Assert.Equal("Foo$$Bar$$Baz", s);
715721

@@ -730,12 +736,18 @@ public static void TestJoin()
730736
Assert.Throws<ArgumentOutOfRangeException>(() => s = String.Join("$$", new String[] { "Foo" }, 2, 1));
731737

732738
// Object Array
739+
s = String.Join("@@", new object[] { });
740+
Assert.Equal("", s);
741+
733742
s = String.Join("@@", new object[] { "Red" });
734743
Assert.Equal("Red", s);
735744

736745
s = String.Join("@@", new object[] { "Red", "Green", "Blue" });
737746
Assert.Equal("Red@@Green@@Blue", s);
738747

748+
s = String.Join(null, new object[] { "Red", "Green", "Blue" });
749+
Assert.Equal("RedGreenBlue", s);
750+
739751
s = String.Join("@@", new object[] { null, "Green", "Blue" }); // Feature of object[] overload to exit if [0] is null
740752
Assert.Equal("", s);
741753

@@ -754,6 +766,9 @@ public static void TestJoin()
754766
s = String.Join("|", new List<string>() { "Red" });
755767
Assert.Equal("Red", s);
756768

769+
s = String.Join(null, new List<string>() { "Red", "Green", "Blue" });
770+
Assert.Equal("RedGreenBlue", s);
771+
757772
s = String.Join("|", new List<string>() { "Red", "Green", "Blue" });
758773
Assert.Equal("Red|Green|Blue", s);
759774

@@ -772,6 +787,9 @@ public static void TestJoin()
772787
s = String.Join("--", new List<Object>() { "Red" });
773788
Assert.Equal("Red", s);
774789

790+
s = String.Join(null, new List<Object>() { "Red", "Green", "Blue" });
791+
Assert.Equal("RedGreenBlue", s);
792+
775793
s = String.Join("--", new List<Object>() { "Red", "Green", "Blue" });
776794
Assert.Equal("Red--Green--Blue", s);
777795

0 commit comments

Comments
 (0)