Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
372a0f6
created a Tests project for unit tests
Guiorgy Jan 26, 2024
b613402
added tests for ReadOnlySpan.Split
Guiorgy Jan 26, 2024
5576a2c
added tests for ReadOnlySpan.SplitAny
Guiorgy Jan 26, 2024
0cdbbb5
added tests for ReadOnlySpan.Split sequence
Guiorgy Jan 27, 2024
f34aadc
added tests for Span.Split and SplitAny
Guiorgy Jan 27, 2024
aa8de01
added tests for RemoveEmptyEntries option
Guiorgy Jan 27, 2024
aa5dcf5
swaped StringSplitOptions and count
Guiorgy Jan 27, 2024
4229731
added space to the generated strings in tests
Guiorgy Jan 28, 2024
b79e346
improved message on assertion failure
Guiorgy Jan 28, 2024
e71eefa
added more tests
Guiorgy Jan 28, 2024
4097f48
solved conflicts
dragon7307 Jan 30, 2024
0b85aa5
adapted tests to project style
dragon7307 Jan 30, 2024
2883e06
adapted tests to project style
dragon7307 Jan 30, 2024
ba298a3
adapted tests to project style
dragon7307 Jan 30, 2024
c1f8d60
hardcoded StringSplitOptions flags
Guiorgy Jan 31, 2024
ca7a1d0
swap count and options parameters
Guiorgy Feb 3, 2024
2f5959c
removed unnecessary ToCharArray calls
Guiorgy Feb 3, 2024
e77ab3e
wrong methods referenced
Guiorgy Feb 3, 2024
2c1a926
added missing tests for Span Split
Guiorgy Feb 3, 2024
18559a3
added CountExceedingBehaviour to tests
Guiorgy Feb 4, 2024
544c972
more tests
Guiorgy Feb 5, 2024
4bfd64e
fixed out of bound exception
Guiorgy Feb 5, 2024
cb26d55
fixed typo in doc-comment tag
Guiorgy Feb 5, 2024
e435547
added tests for count equal 0 and negative
Guiorgy Feb 5, 2024
a00a58d
don't use "should" in Facts
Guiorgy Feb 5, 2024
bf4deb4
added tests for count equals 1 and RemoveEmptyEntries set
Guiorgy Feb 5, 2024
ec0bf15
renamed RandomData tests to MonkeyTests
Guiorgy Feb 17, 2024
c78d145
exclude MonkeyTests from automatic integration tests
Guiorgy Feb 17, 2024
c6d0386
renamed MonkeyTests to FuzzTests
Guiorgy Feb 17, 2024
f176336
simplified Facts tests
Guiorgy Feb 18, 2024
83c4b92
refactored FuzzTests into a separate project
Guiorgy Feb 18, 2024
4e6b778
refactored FuzzTests into groups like Tests
Guiorgy Feb 18, 2024
115672a
fixed CutLastElements and count = 1 incorrect
Guiorgy Feb 18, 2024
eaee8f4
refactored and simplified FuzzTests
Guiorgy Feb 18, 2024
d2f8aa4
make int.MaxValue the default value of count
Guiorgy Feb 19, 2024
ab40dd5
fixed source of truth Split implementation
Guiorgy Feb 19, 2024
bb616ca
moved tests projects
Guiorgy Feb 19, 2024
69ee284
renamed tests projects
Guiorgy Feb 19, 2024
4218a7c
renamed test namespaces
Guiorgy Feb 19, 2024
dd812f2
updated github actions fuzzing namespace filter
Guiorgy Feb 20, 2024
4da820f
split unit tests into separate files
Guiorgy Feb 19, 2024
6687548
split fuzzing tests into separate files
Guiorgy Feb 19, 2024
f2625d5
parameterized fuzzing tests
Guiorgy Feb 19, 2024
0297411
added tests to check the correct enumeration type
Guiorgy Feb 20, 2024
e59748f
separated split by sequence delimiter tests
Guiorgy Feb 21, 2024
868cedc
reduce unnecessary repetitions
Guiorgy Feb 21, 2024
9771809
suppress CS0183 for EnumerationReturns(ReadOnly)Spans
Guiorgy Feb 24, 2024
11b049c
added more tests
Guiorgy Feb 24, 2024
5b5ab8a
fixed and added a test
Guiorgy Feb 25, 2024
df0f580
added tests for sequence delimiters
Guiorgy Feb 25, 2024
f0d1ab6
updated NuGet packages
Guiorgy Feb 25, 2024
25da2a0
renamed CountExceedingBehaviour options
Guiorgy Feb 25, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test --no-build --verbosity normal --filter FullyQualifiedName!~SpanExtensions.Tests.Fuzzing
12 changes: 12 additions & 0 deletions SpanExtensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ VisualStudioVersion = 17.5.33627.172
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpanExtensions", "src\SpanExtensions.csproj", "{75DE5AFD-663E-415D-9B95-6BC513BD4A07}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "tests\unit-tests\UnitTests.csproj", "{B48A0293-A7FF-4E39-8F8D-57B6F824D70F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FuzzingTests", "tests\fuzzing\FuzzingTests.csproj", "{63CA0F05-0019-4ED3-AD94-45A5CE4D338F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +19,14 @@ Global
{75DE5AFD-663E-415D-9B95-6BC513BD4A07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75DE5AFD-663E-415D-9B95-6BC513BD4A07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75DE5AFD-663E-415D-9B95-6BC513BD4A07}.Release|Any CPU.Build.0 = Release|Any CPU
{B48A0293-A7FF-4E39-8F8D-57B6F824D70F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B48A0293-A7FF-4E39-8F8D-57B6F824D70F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B48A0293-A7FF-4E39-8F8D-57B6F824D70F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B48A0293-A7FF-4E39-8F8D-57B6F824D70F}.Release|Any CPU.Build.0 = Release|Any CPU
{63CA0F05-0019-4ED3-AD94-45A5CE4D338F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63CA0F05-0019-4ED3-AD94-45A5CE4D338F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63CA0F05-0019-4ED3-AD94-45A5CE4D338F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63CA0F05-0019-4ED3-AD94-45A5CE4D338F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
20 changes: 10 additions & 10 deletions src/Enumerators/Split/SpanSplitWithCountEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace SpanExtensions.Enumerators
/// Supports iteration over a <see cref="ReadOnlySpan{T}"/> by splitting it a a specified delimiter of type <typeparamref name="T"/> with an upper limit of splits performed.
/// </summary>
/// <typeparam name="T">The type of elements in the enumerated <see cref="ReadOnlySpan{T}"/>.</typeparam>
public ref struct SpanSplitWithCountEnumerator<T> where T : IEquatable<T>
public ref struct SpanSplitWithCountEnumerator<T> where T : IEquatable<T>
{
ReadOnlySpan<T> Span;
readonly T Delimiter;
readonly int Count;
readonly CountExceedingBehaviour CountExceedingBehaviour;
readonly CountExceedingBehaviour CountExceedingBehaviour;
int currentCount;
bool enumerationDone;
readonly int CountMinusOne;
Expand Down Expand Up @@ -68,18 +68,18 @@ public bool MoveNext()
switch(CountExceedingBehaviour)
{
case CountExceedingBehaviour.CutLastElements:
break;
break;
case CountExceedingBehaviour.AppendLastElements:
if(currentCount == CountMinusOne)
if(currentCount == CountMinusOne)
{
ReadOnlySpan<T> lower = span[..index];
ReadOnlySpan<T> upper = span[(index + 1)..];
Span<T> temp = new T[lower.Length + upper.Length];
lower.CopyTo(temp[..index]);
ReadOnlySpan<T> lower = span[..index];
ReadOnlySpan<T> upper = span[(index + 1)..];
Span<T> temp = new T[lower.Length + upper.Length];
lower.CopyTo(temp[..index]);
upper.CopyTo(temp[index..]);
Current = temp;
Current = temp;
currentCount++;
return true;
return true;
}
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/ReadOnlySpan/ReadOnlySpanExtensions.Linq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ public static ReadOnlySpan<T> Take<T>(this ReadOnlySpan<T> source, int count)
public static ReadOnlySpan<T> SkipWhile<T>(this ReadOnlySpan<T> source, Predicate<T> condition)
{
int count = 0;
while (count < source.Length)
while(count < source.Length)
{
T t = source[count];
T t = source[count];
if(!condition(t))
{
return source.Skip(count);
Expand Down
6 changes: 3 additions & 3 deletions src/Extensions/Span/SpanExtensions.Split.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static SpanSplitStringSplitOptionsEnumerator Split(this Span<char> source
/// <param name="options">A bitwise combination of the enumeration values that specifies whether to trim results and include empty results.</param>
/// <param name="countExceedingBehaviour">The handling of the instances more than count.</param>
/// <returns>An instance of the ref struct <see cref="SpanSplitAnyStringSplitOptionsWithCountEnumerator"/>, which works the same way as every <see cref="IEnumerator"/> does and can be used in a foreach construct.</returns>
public static SpanSplitStringSplitOptionsWithCountEnumerator Split(this Span<char> source, char delimiter, StringSplitOptions options, int count, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
public static SpanSplitStringSplitOptionsWithCountEnumerator Split(this Span<char> source, char delimiter, int count, StringSplitOptions options, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
{
return new SpanSplitStringSplitOptionsWithCountEnumerator(source, delimiter, count, options, countExceedingBehaviour);
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public static SpanSplitAnyStringSplitOptionsEnumerator SplitAny(this Span<char>
/// <param name="count">The maximum number of sub-ReadOnlySpans to split into.</param>
/// <param name="countExceedingBehaviour">The handling of the instances more than count.</param>
/// <returns>An instance of the ref struct <see cref="SpanSplitAnyStringSplitOptionsWithCountEnumerator"/>, which works the same way as every <see cref="IEnumerator"/> does and can be used in a foreach construct.</returns>
public static SpanSplitAnyStringSplitOptionsWithCountEnumerator SplitAny(this Span<char> source, ReadOnlySpan<char> delimiters, StringSplitOptions options, int count, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
public static SpanSplitAnyStringSplitOptionsWithCountEnumerator SplitAny(this Span<char> source, ReadOnlySpan<char> delimiters, int count, StringSplitOptions options, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
{
return new SpanSplitAnyStringSplitOptionsWithCountEnumerator(source, delimiters, count, options, countExceedingBehaviour);
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public static SpanSplitSequenceStringSplitOptionsEnumerator Split(this Span<char
/// <param name="options">A bitwise combination of the enumeration values that specifies whether to trim results and include empty results.</param>
/// <param name="countExceedingBehaviour">The handling of the instances more than count.</param>
/// <returns>An instance of the ref struct <see cref="SpanSplitSequenceStringSplitOptionsWithCountEnumerator"/>, which works the same way as every <see cref="IEnumerator"/> does and can be used in a foreach construct.</returns>
public static SpanSplitSequenceStringSplitOptionsWithCountEnumerator Split(this Span<char> source, ReadOnlySpan<char> delimiter, StringSplitOptions options, int count, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
public static SpanSplitSequenceStringSplitOptionsWithCountEnumerator Split(this Span<char> source, ReadOnlySpan<char> delimiter, int count, StringSplitOptions options, CountExceedingBehaviour countExceedingBehaviour = CountExceedingBehaviour.AppendLastElements)
{
return new SpanSplitSequenceStringSplitOptionsWithCountEnumerator(source, delimiter, count, options, countExceedingBehaviour);
}
Expand Down
8 changes: 4 additions & 4 deletions src/InvalidCountExceedingBehaviourException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class InvalidCountExceedingBehaviourException : Exception
/// </summary>
/// <param name="countExceedingBehaviour"> The invalid <see cref="CountExceedingBehaviour"/>. </param>
public InvalidCountExceedingBehaviourException(CountExceedingBehaviour countExceedingBehaviour) :
base($"CountExceedingBehaviour with ID '{(int) countExceedingBehaviour} is not defined. CountExceedingBehaviour only defines {GetCountExceedingBehaviourNamesListed()}.")
base($"CountExceedingBehaviour with ID '{(int)countExceedingBehaviour} is not defined. CountExceedingBehaviour only defines {GetCountExceedingBehaviourNamesListed()}.")
{

}

static string GetCountExceedingBehaviourNamesListed()
Expand All @@ -24,7 +24,7 @@ static string GetCountExceedingBehaviourNamesListed()
#if NET5_0_OR_GREATER
countExceedingBehaviourNames = Enum.GetNames<CountExceedingBehaviour>();
#else
countExceedingBehaviourNames = (string[]) Enum.GetNames(typeof(CountExceedingBehaviour));
countExceedingBehaviourNames = (string[])Enum.GetNames(typeof(CountExceedingBehaviour));
#endif
switch(countExceedingBehaviourNames.Length)
{
Expand All @@ -33,7 +33,7 @@ static string GetCountExceedingBehaviourNamesListed()
case 1:
return countExceedingBehaviourNames[0];
default:
string first = countExceedingBehaviourNames[0];
string first = countExceedingBehaviourNames[0];
string end = string.Join(',', countExceedingBehaviourNames, 1, countExceedingBehaviourNames.Length - 1);
return $"{first} and {end}";
}
Expand Down
2 changes: 1 addition & 1 deletion src/SpanExtensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netstandard2.1</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Platforms>AnyCPU</Platforms>
Expand Down
32 changes: 32 additions & 0 deletions tests/fuzzing/FuzzingTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>

<RootNamespace>SpanExtensions.Tests.Fuzzing</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\SpanExtensions.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions tests/fuzzing/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Loading