Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,12 @@ public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, in
public string Remove(int startIndex, int count) { return default(string); }
public string Replace(char oldChar, char newChar) { return default(string); }
public string Replace(string oldValue, string newValue) { return default(string); }
#if netcoreapp11
public string[] Split(char separator, System.StringSplitOptions options = System.StringSplitOptions.None) { return default(string[]); }
public string[] Split(char separator, int count, System.StringSplitOptions options = System.StringSplitOptions.None) { return default(string[]); }
public string[] Split(string separator, System.StringSplitOptions options = System.StringSplitOptions.None) { return default(string[]); }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good, so we did decide to go with @svick's optional parameter idea.

public string[] Split(string separator, int count, System.StringSplitOptions options = System.StringSplitOptions.None) { return default(string[]); }
#endif
public string[] Split(params char[] separator) { return default(string[]); }
public string[] Split(char[] separator, int count) { return default(string[]); }
public string[] Split(char[] separator, int count, System.StringSplitOptions options) { return default(string[]); }
Expand Down
3 changes: 2 additions & 1 deletion src/System.Runtime/tests/Performance/Perf.String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ public void Split(int size)
PerfUtils utils = new PerfUtils();
string testString = utils.CreateString(size);
string existingValue = testString.Substring(testString.Length / 2, 1);
string[] separator = new string[] { existingValue };
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
for (int i = 0; i < 10000; i++)
testString.Split(existingValue);
testString.Split(separator, StringSplitOptions.None);
}

[Benchmark]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<Compile Include="Perf.Int32.cs" />
<Compile Include="Perf.IntPtr.cs" />
<Compile Include="Perf.StringBuilder.cs" />
<Compile Include="..\System\String.SplitTests.cs" />
<Compile Include="..\Helpers.cs" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove these tests here, as opposed to including the extensions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place where a unit test file is being included in the perf tests. I think it is a mistake. The perf test was written using the temporary extensions methods (I believe as a mistake). It should have been testing one of the older Split overloads, so there's no need to use the extension methods.

<Compile Include="$(CommonTestPath)\System\PerfUtils.cs">
<Link>Common\System\PerfUtils.cs</Link>
Expand Down
3 changes: 3 additions & 0 deletions src/System.Runtime/tests/System.Runtime.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<Compile Include="System\Runtime\CompilerServices\RuntimeHelpersTests.netcoreapp1.1.cs" />
<Compile Include="System\UIntPtrTests.netcoreapp1.1.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' != 'netcoreapp1.1'">
<Compile Include="System\StringSplitExtensions.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == ''">
<Compile Include="ArrayTests.netstandard1.7.cs" />
<Compile Include="System\AttributeTests.netstandard1.7.cs" />
Expand Down
60 changes: 20 additions & 40 deletions src/System.Runtime/tests/System/String.SplitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Xunit;

namespace System.Tests
{
// TODO: Remove these extension methods when the actual methods are available on String in System.Runtime.dll
internal static class TemporaryStringSplitExtensions
{
public static string[] Split(this string value, char separator)
{
return value.Split(new[] { separator });
}

public static string[] Split(this string value, char separator, StringSplitOptions options)
{
return value.Split(new[] { separator }, options);
}

public static string[] Split(this string value, char separator, int count, StringSplitOptions options)
{
return value.Split(new[] { separator }, count, options);
}

public static string[] Split(this string value, string separator)
{
return value.Split(new[] { separator }, StringSplitOptions.None);
}

public static string[] Split(this string value, string separator, StringSplitOptions options)
{
return value.Split(new[] { separator }, options);
}

public static string[] Split(this string value, string separator, int count, StringSplitOptions options)
{
return value.Split(new[] { separator }, count, options);
}
}

public static class StringSplitTests
{
[Fact]
Expand All @@ -50,11 +15,13 @@ public static void SplitInvalidCount()
const int count = -1;
const StringSplitOptions options = StringSplitOptions.None;

Assert.Throws<ArgumentOutOfRangeException>(() => value.Split(',', count, options));
Assert.Throws<ArgumentOutOfRangeException>(() => value.Split(new[] { ',' }, count));
Assert.Throws<ArgumentOutOfRangeException>(() => value.Split(new[] { ',' }, count, options));
Assert.Throws<ArgumentOutOfRangeException>(() => value.Split(",", count, options));
Assert.Throws<ArgumentOutOfRangeException>(() => value.Split(new[] { "," }, count, options));
Assert.Throws<ArgumentOutOfRangeException>("count", () => value.Split(',', count));
Assert.Throws<ArgumentOutOfRangeException>("count", () => value.Split(',', count, options));
Assert.Throws<ArgumentOutOfRangeException>("count", () => value.Split(new[] { ',' }, count));
Assert.Throws<ArgumentOutOfRangeException>("count", () => value.Split(new[] { ',' }, count, options));
Assert.Throws<ArgumentOutOfRangeException>("count", () => value.Split(",", count));
Assert.Throws<ArgumentOutOfRangeException>("count", () => value.Split(",", count, options));
Assert.Throws<ArgumentOutOfRangeException>("count", () => value.Split(new[] { "," }, count, options));
}

[Fact]
Expand Down Expand Up @@ -92,9 +59,11 @@ public static void SplitZeroCountEmptyResult()

string[] expected = new string[0];

Assert.Equal(expected, value.Split(',', count));
Assert.Equal(expected, value.Split(',', count, options));
Assert.Equal(expected, value.Split(new[] { ',' }, count));
Assert.Equal(expected, value.Split(new[] { ',' }, count, options));
Assert.Equal(expected, value.Split(",", count));
Assert.Equal(expected, value.Split(",", count, options));
Assert.Equal(expected, value.Split(new[] { "," }, count, options));
}
Expand Down Expand Up @@ -127,9 +96,11 @@ public static void SplitOneCountSingleResult()

string[] expected = new[] { value };

Assert.Equal(expected, value.Split(',', count));
Assert.Equal(expected, value.Split(',', count, options));
Assert.Equal(expected, value.Split(new[] { ',' }, count));
Assert.Equal(expected, value.Split(new[] { ',' }, count, options));
Assert.Equal(expected, value.Split(",", count));
Assert.Equal(expected, value.Split(",", count, options));
Assert.Equal(expected, value.Split(new[] { "," }, count, options));
}
Expand Down Expand Up @@ -472,6 +443,15 @@ public static void SplitStringSeparator(string value, string separator, int coun
Assert.Equal(expected, value.Split(new[] { separator }, count, options));
}

[Fact]
public static void SplitNullCharArraySeparator_BindsToCharArrayOverload()
{
string value = "a b c";
string[] expected = new[] { "a", "b", "c" };
// Ensure Split(null) compiles successfully as a call to Split(char[])
Assert.Equal(expected, value.Split(null));
}

[Theory]
[InlineData("a b c", null, M, StringSplitOptions.None, new[] { "a", "b", "c" })]
[InlineData("a b c", new char[0], M, StringSplitOptions.None, new[] { "a", "b", "c" })]
Expand Down
22 changes: 22 additions & 0 deletions src/System.Runtime/tests/System/StringSplitExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Tests
{
// Allows the string.Split tests to run on targets that *do not* have the new string.Split overloads.
internal static class StringSplitExtensions
{
public static string[] Split(this string value, char separator, StringSplitOptions options = StringSplitOptions.None) =>
value.Split(new[] { separator }, options);

public static string[] Split(this string value, char separator, int count, StringSplitOptions options = StringSplitOptions.None) =>
value.Split(new[] { separator }, count, options);

public static string[] Split(this string value, string separator, StringSplitOptions options = StringSplitOptions.None) =>
value.Split(new[] { separator }, options);

public static string[] Split(this string value, string separator, int count, StringSplitOptions options = StringSplitOptions.None) =>
value.Split(new[] { separator }, count, options);
}
}