Skip to content

Commit

Permalink
Fixed Join_ObjectArray test in StringTests (dotnet/corefx#14083)
Browse files Browse the repository at this point in the history
* Fixed Join_ObjectArray test in StringTests

Commit migrated from dotnet/corefx@57eb42f
  • Loading branch information
AlexRadch authored and AlexGhiondea committed Dec 1, 2016
1 parent daa5ebe commit 71be9fe
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/libraries/System.Runtime/tests/System/StringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1618,23 +1618,32 @@ 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" }, "" };
// Test join when first value is null
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|" };
}

[ActiveIssue(13747)]
[Theory]
[MemberData(nameof(Join_ObjectArray_TestData))]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework | TargetFrameworkMonikers.NetcoreUwp | TargetFrameworkMonikers.Netcoreapp1_0)]
public static void Join_ObjectArray(string separator, object[] values, string expected)
{
Assert.Equal(expected, string.Join(separator, values));
if (!(values.Length > 0 && values[0] == null))
{
Assert.Equal(expected, string.Join(separator, (IEnumerable<object>)values));
}
Assert.Equal(expected, string.Join(separator, (IEnumerable<object>)values));
}

[Theory]
[MemberData(nameof(Join_ObjectArray_TestData))]
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp1_1)]
public static void Join_ObjectArray_WithNullIssue(string separator, object[] values, string expected)
{
string enumerableExpected = expected;
if (values.Length > 0 && values[0] == null) // Join return nothing when first value is null
expected = "";
Assert.Equal(expected, string.Join(separator, values));
Assert.Equal(enumerableExpected, string.Join(separator, (IEnumerable<object>)values));
}

[Fact]
Expand Down

0 comments on commit 71be9fe

Please sign in to comment.