-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more test coverage for streams and some extension methods.
- Loading branch information
1 parent
b8f0432
commit a513626
Showing
26 changed files
with
166 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
using NUnit.Framework; | ||
|
||
using schema.util; | ||
using schema.util.asserts; | ||
|
||
|
||
namespace schema.text.reader { | ||
|
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
24 changes: 24 additions & 0 deletions
24
Schema Tests/util/enumerables/EnumerableExtensionsTests.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,24 @@ | ||
using NUnit.Framework; | ||
|
||
namespace schema.util.enumerables { | ||
public class EnumerableExtensionsTests { | ||
[Test] | ||
public void TestResizedOriginallyNull() { | ||
CollectionAssert.AreEqual( | ||
new[] { 0, 0, 0 }, | ||
((int[]?) null).Resized(3)); | ||
} | ||
|
||
[Test] | ||
public void TestResizeArrayGrowing() { | ||
var inputList = new[] { 1, 2, 3 }; | ||
CollectionAssert.AreEqual(new[] { 1, 2, 3, 0 }, inputList.Resized(4)); | ||
} | ||
|
||
[Test] | ||
public void TestResizeArrayShrinking() { | ||
var inputList = new[] { 1, 2, 3 }; | ||
CollectionAssert.AreEqual(new[] { 1, 2 }, inputList.Resized(2)); | ||
} | ||
} | ||
} |
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,37 @@ | ||
using NUnit.Framework; | ||
|
||
namespace schema.util.sequences { | ||
public class SequencesUtilTests { | ||
[Test] | ||
public void TestResizeArrayOriginallyNull() { | ||
CollectionAssert.AreEqual( | ||
new[] { 0, 0, 0 }, | ||
SequencesUtil.CloneAndResizeSequence((int[]?) null, 3)); | ||
} | ||
|
||
[Test] | ||
public void TestResizeArrayGrowing() { | ||
var inputList = new[] { 1, 2, 3 }; | ||
CollectionAssert.AreEqual( | ||
new[] { 1, 2, 3, 0 }, | ||
SequencesUtil.CloneAndResizeSequence(inputList, 4)); | ||
} | ||
|
||
[Test] | ||
public void TestResizeArrayShrinking() { | ||
var inputList = new[] { 1, 2, 3 }; | ||
CollectionAssert.AreEqual( | ||
new[] { 1, 2, }, | ||
SequencesUtil.CloneAndResizeSequence(inputList, 2)); | ||
} | ||
|
||
[Test] | ||
public void TestResizingArrayReturnsSameWhenLengthIsSame() { | ||
var inputList = new[] { 1, 2, 3 }; | ||
Assert.AreSame(inputList, | ||
SequencesUtil.CloneAndResizeSequence( | ||
inputList, | ||
inputList.Length)); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,46 @@ | ||
using NUnit.Framework; | ||
using System; | ||
|
||
using NUnit.Framework; | ||
|
||
using schema.util.asserts; | ||
|
||
using static System.Runtime.InteropServices.JavaScript.JSType; | ||
|
||
namespace schema.util.streams { | ||
public class RangedReadableSubstreamTests { | ||
[Test] | ||
public void TestFullSubstream() { | ||
var s = new ReadableStream(new byte[] { 1, 2, 3, 4, 5, 6, 7 }); | ||
var ss = new RangedReadableSubstream(s, 0, s.Length); | ||
var data = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; | ||
var rs = new ReadableStream(data); | ||
var rrs = new RangedReadableSubstream(rs, 0, rs.Length); | ||
|
||
Assert.AreEqual(0, rs.Position); | ||
Assert.AreEqual(0, rrs.Position); | ||
Assert.AreEqual(7, rs.Length); | ||
Assert.AreEqual(7, rrs.Length); | ||
|
||
CollectionAssert.AreEqual(data, rrs.ReadAllBytes()); | ||
Assert.AreEqual(7, rs.Position); | ||
Assert.AreEqual(7, rrs.Position); | ||
} | ||
|
||
[Test] | ||
public void TestPartialSubstream() { | ||
var data = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; | ||
var rs = new ReadableStream(data); | ||
|
||
var rrs = new RangedReadableSubstream(rs, 1, rs.Length - 2); | ||
rrs.Position = 1; | ||
|
||
Assert.AreEqual(0, s.Position); | ||
Assert.AreEqual(0, ss.Position); | ||
Assert.AreEqual(1, rs.Position); | ||
Assert.AreEqual(1, rrs.Position); | ||
Assert.AreEqual(7, rs.Length); | ||
Assert.AreEqual(6, rrs.Length); | ||
|
||
Assert.AreEqual(7, ss.Length); | ||
Assert.AreEqual(7, ss.Length); | ||
CollectionAssert.AreEqual(data.AsSpan(1, data.Length - 2).ToArray(), | ||
rrs.ReadAllBytes()); | ||
Assert.AreEqual(6, rs.Position); | ||
Assert.AreEqual(6, rrs.Position); | ||
} | ||
} | ||
} |
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,39 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<IsRoslynComponent>true</IsRoslynComponent> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<LangVersion>preview</LangVersion> | ||
<RootNamespace>schema</RootNamespace> | ||
<Nullable>enable</Nullable> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<PackageProjectUrl>https://github.com/MeltyPlayer/Schema</PackageProjectUrl> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<Description>Library for converting classes to and from binary. Provides a C# Roslyn generator that automatically implements conversion logic for simple classes.</Description> | ||
<PackageId>schema</PackageId> | ||
<Title>schema</Title> | ||
<Version>0.3.5</Version> | ||
<Authors>MeltyPlayer</Authors> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\README.md" Pack="true" PackagePath="\" /> | ||
<!-- Include the netstandard2.0 DLL into the package --> | ||
<None Include="$(OutputPath)$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.2.0" /> | ||
<PackageReference Include="Encoding.SpanExtensions" Version="1.0.0" /> | ||
<PackageReference Include="Half" Version="1.0.0" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.0.1" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" /> | ||
<PackageReference Include="System.Memory" Version="4.5.5" Condition="'$(TargetFramework)'=='netstandard2.0'" /> | ||
</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
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
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
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
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