From d1dda5c08edb42150abf4af19b602b46808a3d22 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Thu, 17 Nov 2016 10:26:40 +0700 Subject: [PATCH 1/5] Join(string separator, params object[] values) is fixed Join issue for first null in object array is fixed. So calling string.Join(",", null, 1, 2, 3) now return ",1,2,3", but not empty string as before. See https://github.com/dotnet/coreclr/pull/8114 --- src/System.Runtime/tests/System/StringTests.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/System.Runtime/tests/System/StringTests.cs b/src/System.Runtime/tests/System/StringTests.cs index 30f3257cdc67..ae1d7178398b 100644 --- a/src/System.Runtime/tests/System/StringTests.cs +++ b/src/System.Runtime/tests/System/StringTests.cs @@ -1618,8 +1618,8 @@ public static IEnumerable 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" }, "" }; + // Join is fixed if array[0] 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|" }; @@ -1630,10 +1630,9 @@ public static IEnumerable Join_ObjectArray_TestData() 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)) - { + // Join is fixed if array[0] is null + //if (!(values.Length > 0 && values[0] == null)) Assert.Equal(expected, string.Join(separator, (IEnumerable)values)); - } } [Fact] From 2299480f934af0f8ca36847fde5f0bb3153f0de6 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Thu, 17 Nov 2016 10:33:54 +0700 Subject: [PATCH 2/5] Update StringTests.cs --- src/System.Runtime/tests/System/StringTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Runtime/tests/System/StringTests.cs b/src/System.Runtime/tests/System/StringTests.cs index ae1d7178398b..6d09e3f6c0bf 100644 --- a/src/System.Runtime/tests/System/StringTests.cs +++ b/src/System.Runtime/tests/System/StringTests.cs @@ -1630,7 +1630,7 @@ public static IEnumerable Join_ObjectArray_TestData() public static void Join_ObjectArray(string separator, object[] values, string expected) { Assert.Equal(expected, string.Join(separator, values)); - // Join is fixed if array[0] is null + // Join is fixed if array[0] is null //if (!(values.Length > 0 && values[0] == null)) Assert.Equal(expected, string.Join(separator, (IEnumerable)values)); } From 7a5c867edf2040eda86389cd5d18da1e0e500f70 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Fri, 18 Nov 2016 03:22:11 +0700 Subject: [PATCH 3/5] Add different Join_ObjectArray tests for netstandard17 and other versions --- src/System.Runtime/tests/System/StringTests.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/System.Runtime/tests/System/StringTests.cs b/src/System.Runtime/tests/System/StringTests.cs index 6d09e3f6c0bf..5c196efcc7a2 100644 --- a/src/System.Runtime/tests/System/StringTests.cs +++ b/src/System.Runtime/tests/System/StringTests.cs @@ -1618,9 +1618,13 @@ public static IEnumerable 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" }; +#if netstandard17 // Join is fixed if array[0] is null yield return new object[] { "$$", new object[] { null, "Bar", "Baz" }, "$$Bar$$Baz" }; - +#else + // Join does nothing if array[0] is null + yield return new object[] { "$$", new object[] { null, "Bar", "Baz" }, "" }; +#endif // 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|" }; } @@ -1630,9 +1634,14 @@ public static IEnumerable Join_ObjectArray_TestData() public static void Join_ObjectArray(string separator, object[] values, string expected) { Assert.Equal(expected, string.Join(separator, values)); +#if netstandard17 // Join is fixed if array[0] is null - //if (!(values.Length > 0 && values[0] == null)) + Assert.Equal(expected, string.Join(separator, (IEnumerable)values)); +#else + // Join does nothing if array[0] is null + if (!(values.Length > 0 && values[0] == null)) Assert.Equal(expected, string.Join(separator, (IEnumerable)values)); +#endif } [Fact] From eef41a48e7bb9208f08aa3e135237c318e508dab Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Fri, 18 Nov 2016 03:24:00 +0700 Subject: [PATCH 4/5] format --- src/System.Runtime/tests/System/StringTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.Runtime/tests/System/StringTests.cs b/src/System.Runtime/tests/System/StringTests.cs index 5c196efcc7a2..6fbf7b6f9564 100644 --- a/src/System.Runtime/tests/System/StringTests.cs +++ b/src/System.Runtime/tests/System/StringTests.cs @@ -1625,6 +1625,7 @@ public static IEnumerable Join_ObjectArray_TestData() // Join does nothing if array[0] is null yield return new object[] { "$$", new object[] { null, "Bar", "Baz" }, "" }; #endif + // 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|" }; } From 2336e8aaa17d1fc6df2bf2b44a22c001758558da Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Fri, 18 Nov 2016 12:30:39 +0700 Subject: [PATCH 5/5] Expand code coverage --- src/System.Runtime/tests/System/StringTests.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/System.Runtime/tests/System/StringTests.cs b/src/System.Runtime/tests/System/StringTests.cs index 6fbf7b6f9564..adc0055be7e3 100644 --- a/src/System.Runtime/tests/System/StringTests.cs +++ b/src/System.Runtime/tests/System/StringTests.cs @@ -1618,13 +1618,7 @@ public static IEnumerable 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" }; -#if netstandard17 - // Join is fixed if array[0] is null yield return new object[] { "$$", new object[] { null, "Bar", "Baz" }, "$$Bar$$Baz" }; -#else - // Join does nothing if array[0] is null - yield return new object[] { "$$", new object[] { null, "Bar", "Baz" }, "" }; -#endif // 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|" }; @@ -1634,15 +1628,15 @@ public static IEnumerable Join_ObjectArray_TestData() [MemberData(nameof(Join_ObjectArray_TestData))] public static void Join_ObjectArray(string separator, object[] values, string expected) { - Assert.Equal(expected, string.Join(separator, values)); #if netstandard17 - // Join is fixed if array[0] is null - Assert.Equal(expected, string.Join(separator, (IEnumerable)values)); + Assert.Equal(expected, string.Join(separator, values)); #else - // Join does nothing if array[0] is null - if (!(values.Length > 0 && values[0] == null)) - Assert.Equal(expected, string.Join(separator, (IEnumerable)values)); + 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)values)); } [Fact]