Skip to content

Commit

Permalink
tests for overloads & extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
clipperhouse committed Jul 19, 2024
1 parent c480626 commit 21d2ca2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Split/Extensions/SpanExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ public static SplitEnumerator<char> SplitOnAny(this ReadOnlySpan<char> source, R
public static SplitEnumerator<char> SplitOnAny(this ReadOnlySpan<char> source, string separators) =>
Span.SplitAny(source, separators);

public static SplitEnumerator<char> SplitOnAny(this string source, SearchValues<char> separators) =>
Span.SplitAny(source, separators);
public static SplitEnumerator<char> SplitOnAny(this ReadOnlySpan<char> source, SearchValues<char> separators) =>
Span.SplitAny(source, separators);


public static SplitEnumerator<byte> SplitOn(this byte[] source, byte separator) =>
Span.Split(source, separator);

public static SplitEnumerator<byte> SplitOn(this byte[] source, ReadOnlySpan<byte> separator) =>
Span.Split(source, separator);

public static SplitEnumerator<byte> SplitOn(this ReadOnlySpan<byte> source, byte separator) =>
Span.Split(source, separator);

Expand All @@ -42,6 +47,9 @@ public static SplitEnumerator<byte> SplitOn(this ReadOnlySpan<byte> source, Read
public static SplitEnumerator<byte> SplitOnAny(this byte[] source, ReadOnlySpan<byte> separators) =>
Span.SplitAny(source, separators);

public static SplitEnumerator<byte> SplitOnAny(this byte[] source, SearchValues<byte> separators) =>
Span.SplitAny(source, separators);

public static SplitEnumerator<byte> SplitOnAny(this ReadOnlySpan<byte> source, ReadOnlySpan<byte> separators) =>
Span.SplitAny(source, separators);

Expand Down
65 changes: 65 additions & 0 deletions Tests/Basic.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Tests;

using System.Buffers;
using System.Text;
using Split;
using Split.Extensions;
Expand Down Expand Up @@ -61,4 +62,68 @@ public void Readme()
Console.WriteLine("\"" + Encoding.UTF8.GetString(word) + "\"");
}
}

[Fact]
public void Overloads()
{
// Just to avoid breaking the API, no actual tests

var example = "foo";
{
char separator = ' ';
Span.Split(example, separator);

var separators = ". ";
Span.Split(example, separators);
Span.SplitAny(example, separators);

var search = SearchValues.Create(separators);
Span.SplitAny(example, search);
}

var bytes = Encoding.UTF8.GetBytes(example);
{
byte separator = (byte)' ';
Span.Split(bytes, separator);

var separators = ". "u8;
Span.Split(bytes, separators);
Span.SplitAny(bytes, separators);

var search = SearchValues.Create(separators);
Span.SplitAny(bytes, search);
}
}

[Fact]
public void Extensions()
{
// Just to avoid breaking the API, no actual tests

var example = "foo";
{
char separator = ' ';
example.SplitOn(separator);

var separators = ". ";
example.SplitOn(separators);
example.SplitOnAny(separators);

var search = SearchValues.Create(separators);
example.SplitOnAny(search);
}

var bytes = Encoding.UTF8.GetBytes(example);
{
byte separator = (byte)' ';
bytes.SplitOn(separator);

var separators = ". "u8;
bytes.SplitOn(separators);
bytes.SplitOnAny(separators);

var search = SearchValues.Create(separators);
bytes.SplitOnAny(search);
}
}
}

0 comments on commit 21d2ca2

Please sign in to comment.