-
Notifications
You must be signed in to change notification settings - Fork 125
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
90 changed files
with
3,188 additions
and
804 deletions.
There are no files selected for viewing
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
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
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,24 @@ | ||
namespace DotNext.Collections.Generic; | ||
|
||
[TestClass] | ||
public class ListTests | ||
{ | ||
[TestMethod] | ||
public void Indexer() | ||
{ | ||
IList<long> array = [5L, 6L, 30L]; | ||
Assert.AreEqual(30L, List.Indexer<long>.Getter(array, 2)); | ||
List.Indexer<long>.Setter(array, 1, 10L); | ||
Assert.AreEqual(10L, array.IndexerGetter().Invoke(1)); | ||
array.IndexerSetter().Invoke(0, 6L); | ||
Assert.AreEqual(6L, array.IndexerGetter().Invoke(0)); | ||
} | ||
|
||
[TestMethod] | ||
public void ReadOnlyIndexer() | ||
{ | ||
IReadOnlyList<long> array = [5L, 6L, 20L]; | ||
Assert.AreEqual(20L, List.Indexer<long>.ReadOnly(array, 2)); | ||
Assert.AreEqual(6L, array.IndexerGetter().Invoke(1)); | ||
} | ||
} |
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,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>DotNext</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Version>5.17.0</Version> | ||
<IsPackable>false</IsPackable> | ||
<Authors>.NET Foundation and Contributors</Authors> | ||
<Product>.NEXT Family of Libraries</Product> | ||
<Description>AOT compatibility tests for .NEXT Familiy of Libraries</Description> | ||
<Copyright>Copyright © .NET Foundation and Contributors</Copyright> | ||
<PackageLicenseUrl>https://github.com/dotnet/DotNext/blob/master/LICENSE</PackageLicenseUrl> | ||
<PackageProjectUrl>https://github.com/dotnet/DotNext</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/dotnet/DotNext.git</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
<PublishAot>true</PublishAot> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DotNext\DotNext.csproj"/> | ||
<PackageReference Include="MSTest.Engine" /> | ||
<PackageReference Include="MSTest.SourceGeneration" /> | ||
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" /> | ||
<PackageReference Include="Microsoft.Testing.Platform.MSBuild"/> | ||
<PackageReference Include="MSTest.TestFramework" /> | ||
<PackageReference Include="MSTest.Analyzers" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
</ItemGroup> | ||
</Project> |
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,23 @@ | ||
namespace DotNext.Reflection; | ||
|
||
[TestClass] | ||
public class TaskTypeTests | ||
{ | ||
[TestMethod] | ||
public void IsCompletedSuccessfullyPropertyGetter() | ||
{ | ||
Assert.IsTrue(TaskType.IsCompletedSuccessfullyGetter(Task.CompletedTask)); | ||
} | ||
|
||
[TestMethod] | ||
public void GetResultSynchronously() | ||
{ | ||
Assert.AreEqual(42, TaskType.GetResultGetter<int>().Invoke(Task.FromResult(42))); | ||
} | ||
|
||
[TestMethod] | ||
public void IsCompletedPropertyGetter() | ||
{ | ||
Assert.IsTrue(Task.CompletedTask.GetIsCompletedGetter().Invoke()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Buffers; | ||
|
||
namespace DotNext.Buffers; | ||
|
||
/// <summary> | ||
/// Represents buffered reader or writer. | ||
/// </summary> | ||
public interface IBufferedChannel : IResettable, IDisposable | ||
{ | ||
/// <summary> | ||
/// Gets buffer allocator. | ||
/// </summary> | ||
MemoryAllocator<byte>? Allocator { get; init; } | ||
|
||
/// <summary> | ||
/// Gets the maximum size of the internal buffer. | ||
/// </summary> | ||
int MaxBufferSize { get; init; } | ||
} |
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,55 @@ | ||
namespace DotNext.Buffers; | ||
|
||
/// <summary> | ||
/// Represents buffered reader. | ||
/// </summary> | ||
public interface IBufferedReader : IBufferedChannel | ||
{ | ||
/// <summary> | ||
/// Gets unconsumed part of the buffer. | ||
/// </summary> | ||
ReadOnlyMemory<byte> Buffer { get; } | ||
|
||
/// <summary> | ||
/// Advances read position. | ||
/// </summary> | ||
/// <param name="count">The number of consumed bytes.</param> | ||
/// <exception cref="ObjectDisposedException">The reader has been disposed.</exception> | ||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is larger than the length of <see cref="Buffer"/>.</exception> | ||
void Consume(int count); | ||
|
||
/// <summary> | ||
/// Fetches the data from the underlying storage to the internal buffer. | ||
/// </summary> | ||
/// <param name="token">The token that can be used to cancel the operation.</param> | ||
/// <returns> | ||
/// <see langword="true"/> if the data has been copied from the underlying storage to the internal buffer; | ||
/// <see langword="false"/> if no more data to read. | ||
/// </returns> | ||
/// <exception cref="ObjectDisposedException">The reader has been disposed.</exception> | ||
/// <exception cref="InternalBufferOverflowException">Internal buffer has no free space.</exception> | ||
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception> | ||
ValueTask<bool> ReadAsync(CancellationToken token = default); | ||
|
||
/// <summary> | ||
/// Reads the block of the memory. | ||
/// </summary> | ||
/// <param name="destination">The output buffer.</param> | ||
/// <param name="token">The token that can be used to cancel the operation.</param> | ||
/// <returns>The number of bytes copied to <paramref name="destination"/>.</returns> | ||
/// <exception cref="ObjectDisposedException">The reader has been disposed.</exception> | ||
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception> | ||
async ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken token = default) | ||
{ | ||
var result = 0; | ||
for (int bytesRead; result < destination.Length; result += bytesRead, destination = destination.Slice(bytesRead)) | ||
{ | ||
Buffer.Span.CopyTo(destination.Span, out bytesRead); | ||
Consume(bytesRead); | ||
if (!await ReadAsync(token).ConfigureAwait(false)) | ||
break; | ||
} | ||
|
||
return result; | ||
} | ||
} |
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,73 @@ | ||
using System.Buffers; | ||
|
||
namespace DotNext.Buffers; | ||
|
||
/// <summary> | ||
/// Represents buffered writer. | ||
/// </summary> | ||
public interface IBufferedWriter : IBufferedChannel, IBufferWriter<byte> | ||
{ | ||
/// <summary> | ||
/// Marks the specified number of bytes in the buffer as produced. | ||
/// </summary> | ||
/// <param name="count">The number of produced bytes.</param> | ||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is larger than the length of <see cref="Buffer"/>.</exception> | ||
/// <exception cref="ObjectDisposedException">The writer has been disposed.</exception> | ||
void Produce(int count); | ||
|
||
/// <summary> | ||
/// The remaining part of the internal buffer available for write. | ||
/// </summary> | ||
/// <remarks> | ||
/// The size of returned buffer may be less than or equal to <see cref="IBufferedChannel.MaxBufferSize"/>. | ||
/// </remarks> | ||
Memory<byte> Buffer { get; } | ||
|
||
/// <summary> | ||
/// Flushes buffered data to the underlying storage. | ||
/// </summary> | ||
/// <param name="token">The token that can be used to cancel the operation.</param> | ||
/// <returns>The task representing asynchronous result.</returns> | ||
/// <exception cref="ObjectDisposedException">The writer has been disposed.</exception> | ||
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception> | ||
ValueTask WriteAsync(CancellationToken token = default); | ||
|
||
/// <summary> | ||
/// Writes the data to the underlying storage through the buffer. | ||
/// </summary> | ||
/// <param name="input">The input data to write.</param> | ||
/// <param name="token">The token that can be used to cancel the operation.</param> | ||
/// <returns>The task representing asynchronous result.</returns> | ||
/// <exception cref="ObjectDisposedException">The object has been disposed.</exception> | ||
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception> | ||
async ValueTask WriteAsync(ReadOnlyMemory<byte> input, CancellationToken token = default) | ||
{ | ||
for (int bytesWritten; !input.IsEmpty; input = input.Slice(bytesWritten)) | ||
{ | ||
input.Span.CopyTo(Buffer.Span, out bytesWritten); | ||
Produce(bytesWritten); | ||
await WriteAsync(token).ConfigureAwait(false); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
void IBufferWriter<byte>.Advance(int count) => Produce(count); | ||
|
||
/// <inheritdoc /> | ||
Memory<byte> IBufferWriter<byte>.GetMemory(int sizeHint) | ||
{ | ||
ArgumentOutOfRangeException.ThrowIfNegative(sizeHint); | ||
|
||
var result = Buffer; | ||
return sizeHint <= result.Length ? result : throw new InsufficientMemoryException(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
Span<byte> IBufferWriter<byte>.GetSpan(int sizeHint) | ||
{ | ||
ArgumentOutOfRangeException.ThrowIfNegative(sizeHint); | ||
|
||
var result = Buffer.Span; | ||
return sizeHint <= result.Length ? result : throw new InsufficientMemoryException(); | ||
} | ||
} |
Oops, something went wrong.