Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/System.Runtime/tests/System/StringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1618,8 +1618,7 @@ public static IEnumerable<object[]> Join_ObjectArray_TestData()
yield return new object[] { null, new object[] { "Foo", "Bar", "Baz" }, "FooBarBaz" };
yield return new object[] { "$$", new object[] { "Foo", null, "Baz" }, "Foo$$$$Baz" };

// Join does nothing if array[0] is null
yield return new object[] { "$$", new object[] { null, "Bar", "Baz" }, "" };
yield return new object[] { "$$", new object[] { null, "Bar", "Baz" }, "$$Bar$$Baz" };

// Join should ignore objects that have a null ToString() value
yield return new object[] { "|", new object[] { new ObjectWithNullToString(), "Foo", new ObjectWithNullToString(), "Bar", new ObjectWithNullToString() }, "|Foo||Bar|" };
Expand All @@ -1629,11 +1628,15 @@ public static IEnumerable<object[]> Join_ObjectArray_TestData()
[MemberData(nameof(Join_ObjectArray_TestData))]
public static void Join_ObjectArray(string separator, object[] values, string expected)
{
#if netstandard17
Assert.Equal(expected, string.Join(separator, values));
if (!(values.Length > 0 && values[0] == null))
{
Assert.Equal(expected, string.Join(separator, (IEnumerable<object>)values));
}
#else
if (values.Length > 0 && values[0] == null) // Join return empty string if array[0] is null
Assert.Equal("", string.Join(separator, values));
else
Assert.Equal(expected, string.Join(separator, values));
#endif
Assert.Equal(expected, string.Join(separator, (IEnumerable<object>)values));
}

[Fact]
Expand Down