From 24c420a2c2ccfd183dd27b396f85b47811f307a2 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Tue, 29 Nov 2016 14:49:05 +0700 Subject: [PATCH 1/4] Fixed Join_ObjectArray test in StringTests --- src/System.Runtime/tests/System/StringTests.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/System.Runtime/tests/System/StringTests.cs b/src/System.Runtime/tests/System/StringTests.cs index e3cf3be98571..a7baff8f0e6f 100644 --- a/src/System.Runtime/tests/System/StringTests.cs +++ b/src/System.Runtime/tests/System/StringTests.cs @@ -1619,22 +1619,25 @@ public static IEnumerable Join_ObjectArray_TestData() 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|" }; } - [ActiveIssue(13747)] [Theory] [MemberData(nameof(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)) - { - Assert.Equal(expected, string.Join(separator, (IEnumerable)values)); - } + var exp = expected; + if (values.Length > 0 && values[0] == null) // Join return empty string if array[0] is null + exp = ""; +#if netstandard17 + // In netstandard17 Join issue was fixed + exp = expected; +#endif + Assert.Equal(exp, string.Join(separator, values)); + Assert.Equal(expected, string.Join(separator, (IEnumerable)values)); } [Fact] From 4bff52e3fc82f598aab4eceece38fd4630811ce2 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Tue, 29 Nov 2016 20:49:59 +0700 Subject: [PATCH 2/4] enumerableExpected --- src/System.Runtime/tests/System/StringTests.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/System.Runtime/tests/System/StringTests.cs b/src/System.Runtime/tests/System/StringTests.cs index a7baff8f0e6f..81d8ea7873fe 100644 --- a/src/System.Runtime/tests/System/StringTests.cs +++ b/src/System.Runtime/tests/System/StringTests.cs @@ -1618,7 +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" }; - // Join does nothing if array[0] is null + // 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 @@ -1629,15 +1629,13 @@ public static IEnumerable Join_ObjectArray_TestData() [MemberData(nameof(Join_ObjectArray_TestData))] public static void Join_ObjectArray(string separator, object[] values, string expected) { - var exp = expected; - if (values.Length > 0 && values[0] == null) // Join return empty string if array[0] is null - exp = ""; -#if netstandard17 - // In netstandard17 Join issue was fixed - exp = expected; + var enumerableExpected = expected; +#if !netstandard17 + if (values.Length > 0 && values[0] == null) // Join return nothing when first value is null + expected = ""; #endif - Assert.Equal(exp, string.Join(separator, values)); - Assert.Equal(expected, string.Join(separator, (IEnumerable)values)); + Assert.Equal(expected, string.Join(separator, values)); + Assert.Equal(enumerableExpected, string.Join(separator, (IEnumerable)values)); } [Fact] From 9ae1b2dfe8af19e4fb502c9cc903dea62a5c1f62 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Tue, 29 Nov 2016 21:18:42 +0700 Subject: [PATCH 3/4] var => string --- 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 81d8ea7873fe..fc964468c869 100644 --- a/src/System.Runtime/tests/System/StringTests.cs +++ b/src/System.Runtime/tests/System/StringTests.cs @@ -1629,7 +1629,7 @@ public static IEnumerable Join_ObjectArray_TestData() [MemberData(nameof(Join_ObjectArray_TestData))] public static void Join_ObjectArray(string separator, object[] values, string expected) { - var enumerableExpected = expected; + string enumerableExpected = expected; #if !netstandard17 if (values.Length > 0 && values[0] == null) // Join return nothing when first value is null expected = ""; From 016bf683d7a240a2fa31925b53eec0cb873f1dcb Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Wed, 30 Nov 2016 02:16:11 +0700 Subject: [PATCH 4/4] I splited test on two --- src/System.Runtime/tests/System/StringTests.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/System.Runtime/tests/System/StringTests.cs b/src/System.Runtime/tests/System/StringTests.cs index fc964468c869..db92512b2915 100644 --- a/src/System.Runtime/tests/System/StringTests.cs +++ b/src/System.Runtime/tests/System/StringTests.cs @@ -1627,13 +1627,21 @@ public static IEnumerable Join_ObjectArray_TestData() [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)); + Assert.Equal(expected, string.Join(separator, (IEnumerable)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 !netstandard17 if (values.Length > 0 && values[0] == null) // Join return nothing when first value is null expected = ""; -#endif Assert.Equal(expected, string.Join(separator, values)); Assert.Equal(enumerableExpected, string.Join(separator, (IEnumerable)values)); }