-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
423 additions
and
631 deletions.
There are no files selected for viewing
599 changes: 0 additions & 599 deletions
599
NetFabric.Hyperlinq.UnitTests/Bindings/System/Collections/Generic/List.Tests.cs
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
....UnitTests/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using NetFabric.Assertive; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Generic | ||
{ | ||
public class ListTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] | ||
public void AsValueEnumerable_With_List_Must_ReturnWrapper(int[] source) | ||
{ | ||
// Arrange | ||
var wrapped = source.ToList(); | ||
|
||
// Act | ||
var result = wrapped.AsValueEnumerable(); | ||
|
||
// Assert | ||
_ = result.Must() | ||
.BeOfType<ArrayExtensions.ArraySegmentValueEnumerable<int>>() | ||
.BeEnumerableOf<int>() | ||
.BeEqualTo(source, testRefStructs: false); | ||
_ = result.SequenceEqual(source).Must().BeTrue(); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...onversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using NetFabric.Assertive; | ||
using System.Collections.Immutable; | ||
using Xunit; | ||
|
||
namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Immutable | ||
{ | ||
public class ImmutableArrayTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] | ||
public void AsValueEnumerable_With_ImmutableArray_Must_ReturnWrapper(int[] source) | ||
{ | ||
// Arrange | ||
var wrapped = source.ToImmutableArray(); | ||
|
||
// Act | ||
var result = wrapped.AsValueEnumerable(); | ||
|
||
// Assert | ||
_ = result.Must() | ||
.BeOfType<ReadOnlyListExtensions.ListValueEnumerable<int>>() | ||
// .BeOfType<ReadOnlyCollectionExtensions.ValueEnumerable<ImmutableArray<int>, ValueEnumerator<int>, ImmutableArray<int>.Enumerator, int, ImmutableArrayExtensions.GetEnumerator<int>, ImmutableArrayExtensions.GetEnumerator2<int>>>() | ||
.BeEnumerableOf<int>() | ||
.BeEqualTo(source); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...sion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using NetFabric.Assertive; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Immutable | ||
{ | ||
public class ImmutableDictionaryTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] | ||
public void AsValueEnumerable_With_ImmutableDictionary_Must_ReturnWrapper(int[] source) | ||
{ | ||
// Arrange | ||
var wrapped = source.ToImmutableDictionary(item => item, default); | ||
var expected = source.ToDictionary(item => item); | ||
|
||
// Act | ||
var result = wrapped.AsValueEnumerable(); | ||
|
||
// Assert | ||
_ = result.Must() | ||
.BeOfType<ReadOnlyCollectionExtensions.ValueEnumerable<ImmutableDictionary<int, int>, ImmutableDictionary<int, int>.Enumerator, ImmutableDictionary<int, int>.Enumerator, KeyValuePair<int, int>, ImmutableDictionaryExtensions.GetEnumerator<int, int>, ImmutableDictionaryExtensions.GetEnumerator<int, int>>>() | ||
.BeEnumerableOf<KeyValuePair<int, int>>() | ||
.BeEqualTo(expected); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...version/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableHashSet.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using NetFabric.Assertive; | ||
using System.Collections.Immutable; | ||
using Xunit; | ||
|
||
namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Immutable | ||
{ | ||
public class ImmutableHashSetTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] | ||
public void AsValueEnumerable_With_ImmutableHashSet_Must_ReturnWrapper(int[] source) | ||
{ | ||
// Arrange | ||
var wrapped = source.ToImmutableHashSet(); | ||
|
||
// Act | ||
var result = wrapped.AsValueEnumerable(); | ||
|
||
// Assert | ||
_ = result.Must() | ||
.BeOfType<ReadOnlyCollectionExtensions.ValueEnumerable<ImmutableHashSet<int>, ImmutableHashSet<int>.Enumerator, ImmutableHashSet<int>.Enumerator, int, ImmutableHashSetExtensions.GetEnumerator<int>, ImmutableHashSetExtensions.GetEnumerator<int>>>() | ||
.BeEnumerableOf<int>() | ||
.BeEqualTo(source); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableList.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using NetFabric.Assertive; | ||
using System.Collections.Immutable; | ||
using Xunit; | ||
|
||
namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Immutable | ||
{ | ||
public class ImmutableListTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] | ||
public void AsValueEnumerable_With_ImmutableList_Must_ReturnWrapper(int[] source) | ||
{ | ||
// Arrange | ||
var wrapped = source.ToImmutableList(); | ||
|
||
// Act | ||
var result = wrapped.AsValueEnumerable(); | ||
|
||
// Assert | ||
_ = result.Must() | ||
.BeOfType<ReadOnlyCollectionExtensions.ValueEnumerable<ImmutableList<int>, ImmutableList<int>.Enumerator, ImmutableList<int>.Enumerator, int, ImmutableListExtensions.GetEnumerator<int>, ImmutableListExtensions.GetEnumerator<int>>>() | ||
.BeEnumerableOf<int>() | ||
.BeEqualTo(source); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...onversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableQueue.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using NetFabric.Assertive; | ||
using System.Collections.Immutable; | ||
using Xunit; | ||
|
||
namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Immutable | ||
{ | ||
public class ImmutableQueueTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] | ||
public void AsValueEnumerable_With_ImmutableQueue_Must_ReturnWrapper(int[] source) | ||
{ | ||
// Arrange | ||
var wrapped = ImmutableQueue.Create(source); | ||
|
||
// Act | ||
var result = wrapped.AsValueEnumerable(); | ||
|
||
// Assert | ||
_ = result.Must() | ||
.BeOfType<EnumerableExtensions.ValueEnumerable<ImmutableQueue<int>, ValueEnumerator<int>, ImmutableQueue<int>.Enumerator, int, ImmutableQueueExtensions.GetEnumerator<int>, ImmutableQueueExtensions.GetEnumerator2<int>>>() | ||
.BeEnumerableOf<int>() | ||
.BeEqualTo(source); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...sValueEnumerable/Bindings/System/Collections/Immutable/ImmutableSortedDictionary.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using NetFabric.Assertive; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Immutable | ||
{ | ||
public class ImmutableSortedDictionaryTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] | ||
public void AsValueEnumerable_With_ImmutableSortedDictionry_Must_ReturnWrapper(int[] source) | ||
{ | ||
// Arrange | ||
var dictionary = source.ToDictionary(item => item); | ||
var wrapped = ImmutableSortedDictionary.CreateRange(default, dictionary); | ||
var expected = new SortedDictionary<int, int>(dictionary); | ||
|
||
// Act | ||
var result = wrapped.AsValueEnumerable(); | ||
|
||
// Assert | ||
_ = result.Must() | ||
.BeOfType<ReadOnlyCollectionExtensions.ValueEnumerable<ImmutableSortedDictionary<int, int>, ImmutableSortedDictionary<int, int>.Enumerator, ImmutableSortedDictionary<int, int>.Enumerator, KeyValuePair<int, int>, ImmutableSortedDictionaryExtensions.GetEnumerator<int, int>, ImmutableSortedDictionaryExtensions.GetEnumerator<int, int>>>() | ||
.BeEnumerableOf<KeyValuePair<int, int>>() | ||
.BeEqualTo(expected); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...onversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableStack.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using NetFabric.Assertive; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using Xunit; | ||
|
||
namespace NetFabric.Hyperlinq.UnitTests.Conversion.AsValueEnumerable.Bindings.System.Collections.Immutable | ||
{ | ||
public class ImmutableStackTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(TestData.Empty), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Single), MemberType = typeof(TestData))] | ||
[MemberData(nameof(TestData.Multiple), MemberType = typeof(TestData))] | ||
public void AsValueEnumerable_With_ImmutableStack_Must_ReturnWrapper(int[] source) | ||
{ | ||
// Arrange | ||
var wrapped = ImmutableStack.Create(source); | ||
var expected = new Stack<int>(source); | ||
|
||
// Act | ||
var result = wrapped.AsValueEnumerable(); | ||
|
||
// Assert | ||
_ = result.Must() | ||
.BeOfType<EnumerableExtensions.ValueEnumerable<ImmutableStack<int>, ValueEnumerator<int>, ImmutableStack<int>.Enumerator, int, ImmutableStackExtensions.GetEnumerator<int>, ImmutableStackExtensions.GetEnumerator2<int>>>() | ||
.BeEnumerableOf<int>() | ||
.BeEqualTo(expected); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
NetFabric.Hyperlinq/Conversion/AsValueEnumerable/Bindings/System/Collections/Generic/List.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace NetFabric.Hyperlinq | ||
{ | ||
public static class ListBindings | ||
{ | ||
// List<TSource> is simply converted to ArraySegment<TSource> and share its IValueEnumerable<TSource> wrapper. | ||
// It's not converted to ReadOnlySpan<TSource> because its enumerators cannot be casted to IEnumerable<TSource>, restricting its use. | ||
// It's not converted to ReadOnlyMemory<TSource> because it's less efficient in enumerables (it has to call .Span on each iteration). | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static ArrayExtensions.ArraySegmentValueEnumerable<TSource> AsValueEnumerable<TSource>(this List<TSource> source) | ||
=> source.AsArraySegment().AsValueEnumerable(); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static ArrayExtensions.ArraySegmentValueEnumerableRef<TSource> AsValueEnumerableRef<TSource>(this List<TSource> source) | ||
=> source.AsArraySegment().AsValueEnumerableRef(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...linq/Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableArray.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace NetFabric.Hyperlinq | ||
{ | ||
public static class ImmutableArrayExtensions | ||
{ | ||
// ImmutableArray<TSource> implements IReadOnlyList<TSource> | ||
// No need for bindings | ||
/* | ||
// ImmutableArray<TSource> implements IReadOnlyCollection<TSource> and has two enumerators: | ||
// One that is a value-type and doesn't implement interfaces. | ||
// Another that is a reference-type and implements IEnumerator<TSource>. | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static ReadOnlyCollectionExtensions.ValueEnumerable<ImmutableArray<TSource>, ValueEnumerator<TSource>, ImmutableArray<TSource>.Enumerator, TSource, GetEnumerator<TSource>, GetEnumerator2<TSource>> AsValueEnumerable<TSource>(this ImmutableArray<TSource> source) | ||
=> ReadOnlyCollectionExtensions.AsValueEnumerable<ImmutableArray<TSource>, ValueEnumerator<TSource>, ImmutableArray<TSource>.Enumerator, TSource, GetEnumerator<TSource>, GetEnumerator2<TSource>>(source); | ||
[StructLayout(LayoutKind.Auto)] | ||
public readonly struct GetEnumerator<TSource> | ||
: IFunction<ImmutableArray<TSource>, ValueEnumerator<TSource>> | ||
{ | ||
public ValueEnumerator<TSource> Invoke(ImmutableArray<TSource> source) | ||
=> new(((IEnumerable<TSource>)source).GetEnumerator()); | ||
} | ||
[StructLayout(LayoutKind.Auto)] | ||
public readonly struct GetEnumerator2<TSource> | ||
: IFunction<ImmutableArray<TSource>, ImmutableArray<TSource>.Enumerator> | ||
{ | ||
public ImmutableArray<TSource>.Enumerator Invoke(ImmutableArray<TSource> source) | ||
=> source.GetEnumerator(); | ||
} | ||
*/ | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...Conversion/AsValueEnumerable/Bindings/System/Collections/Immutable/ImmutableDictionary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace NetFabric.Hyperlinq | ||
{ | ||
public static class ImmutableDictionaryExtensions | ||
{ | ||
// ImmutableDictionary<TKey, TValue> implements IReadOnlyCollection<KeyValuePair<TKey, TValue>> and has a value-type enumerator that implements IEnumerator<TKey, TValue> | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static ReadOnlyCollectionExtensions.ValueEnumerable<ImmutableDictionary<TKey, TValue>, ImmutableDictionary<TKey, TValue>.Enumerator, ImmutableDictionary<TKey, TValue>.Enumerator, KeyValuePair<TKey, TValue>, GetEnumerator<TKey, TValue>, GetEnumerator<TKey, TValue>> AsValueEnumerable<TKey, TValue>(this ImmutableDictionary<TKey, TValue> source) | ||
where TKey: notnull | ||
=> ReadOnlyCollectionExtensions.AsValueEnumerable<ImmutableDictionary<TKey, TValue>, ImmutableDictionary<TKey, TValue>.Enumerator, KeyValuePair<TKey, TValue>, GetEnumerator<TKey, TValue>>(source); | ||
|
||
[StructLayout(LayoutKind.Auto)] | ||
public readonly struct GetEnumerator<TKey, TValue> | ||
: IFunction<ImmutableDictionary<TKey, TValue>, ImmutableDictionary<TKey, TValue>.Enumerator> | ||
where TKey: notnull | ||
{ | ||
public ImmutableDictionary<TKey, TValue>.Enumerator Invoke(ImmutableDictionary<TKey, TValue> source) | ||
=> source.GetEnumerator(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.