From a37c7423b6204e86ca32218265f561e0aca74f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fuszenecker=20R=C3=B3bert?= Date: Thu, 12 Oct 2023 22:09:04 +0200 Subject: [PATCH 1/5] Removed static things. --- .editorconfig | 4 ---- .vscode/settings.json | 7 ------- src/Data.cs | 5 +++-- src/ElementEvents.cs | 8 ++++---- src/ElementIo.cs | 8 ++++---- src/ElementSerializer.cs | 2 +- src/ElementTree.cs | 18 ++++------------- tests/StabilityTests.cs | 2 +- tests/UnitTests.cs | 43 ++++++++++++++++++++-------------------- 9 files changed, 39 insertions(+), 58 deletions(-) delete mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index a79cd86..0000000 --- a/.editorconfig +++ /dev/null @@ -1,4 +0,0 @@ -is_global = true -roslynator_analyzers.enabled_by_default = true -roslynator_refactorings.enabled = true -roslynator_compiler_diagnostic_fixes.enabled = true \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 85a7bfd..d141524 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,3 @@ { "dotnet.defaultSolution": "Promptuarium.sln", - "omnisharp.enableEditorConfigSupport": true, - "cSpell.words": [ - "datetime", - "LINQ", - "Promptuarium", - "roslynator" - ] } \ No newline at end of file diff --git a/src/Data.cs b/src/Data.cs index b086532..c88172c 100644 --- a/src/Data.cs +++ b/src/Data.cs @@ -890,11 +890,12 @@ public static async Task FromElementAsync(Element value) /// var tree = await Data.AsTreeAsync(stream); /// /// - public static async Task AsElementAsync(this Stream stream) + public static async Task AsElementAsync(this Stream stream, Element loaderElement = default) { + loaderElement ??= new Element(); Element result; stream.Position = 0; - result = await Element.LoadAsync(stream).ConfigureAwait(false); + result = await loaderElement.LoadAsync(stream).ConfigureAwait(false); stream.Position = 0; return result; } diff --git a/src/ElementEvents.cs b/src/ElementEvents.cs index a45882a..5013756 100644 --- a/src/ElementEvents.cs +++ b/src/ElementEvents.cs @@ -69,12 +69,12 @@ public partial class Element /// /// Event handler for all Promptuarium data loading events /// - public static event EventHandler? OnDataLoading; + public event EventHandler? OnDataLoading; /// /// Event handler for all Promptuarium data loaded events /// - public static event EventHandler? OnDataLoaded; + public event EventHandler? OnDataLoaded; /// /// Event handler for all Promptuarium data saving events @@ -89,12 +89,12 @@ public partial class Element /// /// Event handler for all Promptuarium metadata loading events /// - public static event EventHandler? OnMetaDataLoading; + public event EventHandler? OnMetaDataLoading; /// /// Event handler for all Promptuarium metadata loaded events /// - public static event EventHandler? OnMetaDataLoaded; + public event EventHandler? OnMetaDataLoaded; /// /// Event handler for all Promptuarium metadata saving events diff --git a/src/ElementIo.cs b/src/ElementIo.cs index 2fd519a..087142f 100644 --- a/src/ElementIo.cs +++ b/src/ElementIo.cs @@ -21,7 +21,7 @@ public partial class Element /// var tree = await Element.LoadAsync(stream, cancellationToken); /// /// - public static Task LoadAsync(Stream stream, CancellationToken cancellationToken) + public Task LoadAsync(Stream stream, CancellationToken cancellationToken) { return DeserializeAsync(stream, cancellationToken); } @@ -38,7 +38,7 @@ public static Task LoadAsync(Stream stream, CancellationToken cancellat /// var tree = await Element.LoadAsync(stream); /// /// - public static Task LoadAsync(Stream stream) + public Task LoadAsync(Stream stream) { return LoadAsync(stream, CancellationToken.None); } @@ -55,7 +55,7 @@ public static Task LoadAsync(Stream stream) /// var tree = await Element.LoadAsync("test.prm", cancellationToken); /// /// - public static async Task LoadAsync(string fileName, CancellationToken cancellationToken) + public async Task LoadAsync(string fileName, CancellationToken cancellationToken) { using var fileStream = new FileStream(fileName, FileMode.Open); return await LoadAsync(fileStream, cancellationToken).ConfigureAwait(false); @@ -72,7 +72,7 @@ public static async Task LoadAsync(string fileName, CancellationToken c /// var tree = await Element.LoadAsync("test.prm"); /// /// - public static Task LoadAsync(string fileName) + public Task LoadAsync(string fileName) { return LoadAsync(fileName, CancellationToken.None); } diff --git a/src/ElementSerializer.cs b/src/ElementSerializer.cs index c935d24..654a8d8 100644 --- a/src/ElementSerializer.cs +++ b/src/ElementSerializer.cs @@ -214,7 +214,7 @@ private static bool Contains(Stream? stream) #region Deserialization routines - private static async Task DeserializeAsync(Stream stream, CancellationToken cancellationToken) + private async Task DeserializeAsync(Stream stream, CancellationToken cancellationToken) { var root = new Element(); Element parent = root; diff --git a/src/ElementTree.cs b/src/ElementTree.cs index 0ee7bee..2d00ae8 100644 --- a/src/ElementTree.cs +++ b/src/ElementTree.cs @@ -534,24 +534,14 @@ public async Task ToBase64StringAsync(CancellationToken cancellationToke /// var tree = await Element.FromBase64StringAsync(base64String); /// /// - public static async Task FromBase64StringAsync(string base64String, CancellationToken cancellationToken) + public static async Task FromBase64StringAsync(string base64String, + Element loaderElement = default, CancellationToken cancellationToken = default) { + loaderElement ??= new Element(); using var memoryStream = new MemoryStream(Convert.FromBase64String(base64String)); - return await LoadAsync(memoryStream, cancellationToken).ConfigureAwait(false); + return await loaderElement.LoadAsync(memoryStream, cancellationToken).ConfigureAwait(false); } - /// - /// Creates a tree from a Base64 string. - /// - /// The tree in Base64. - /// The tree. - /// - /// - /// var tree = await Element.FromBase64StringAsync(base64String); - /// - /// - public static Task FromBase64StringAsync(string base64String) => FromBase64StringAsync(base64String, CancellationToken.None); - #endregion #region IEnumerable implementation diff --git a/tests/StabilityTests.cs b/tests/StabilityTests.cs index 9809284..a557612 100644 --- a/tests/StabilityTests.cs +++ b/tests/StabilityTests.cs @@ -77,7 +77,7 @@ private async Task CreateAndVerifyTrees(int maxTests, int minChildren, int maxCh Assert.IsTrue(new FileInfo(fileName).Length > 0); - Element currentTree = await Element.LoadAsync(fileName).ConfigureAwait(false); + Element currentTree = await new Element().LoadAsync(fileName).ConfigureAwait(false); string currentTreeString = currentTree.TreeToString(); Assert.AreEqual(originalTreeString, currentTreeString); diff --git a/tests/UnitTests.cs b/tests/UnitTests.cs index 2247232..69b2f4f 100644 --- a/tests/UnitTests.cs +++ b/tests/UnitTests.cs @@ -294,7 +294,7 @@ public async Task Load() using var stream = new MemoryStream(data); - var tree = await Element.LoadAsync(stream).ConfigureAwait(false); + var tree = await new Element().LoadAsync(stream).ConfigureAwait(false); Assert.AreEqual((byte)0x80, tree.Data?.AsByte()); Assert.AreEqual((short)0x7819, tree[0].Data?.AsShort()); @@ -310,7 +310,7 @@ public async Task TreeToStringTest() var tree = CreateTestTree(); await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); string treeString = tree.TreeToString(); string treeString2 = tree2.TreeToString(); @@ -331,7 +331,7 @@ public async Task FromInt() tree.Add(subNode); await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual(0x55aa00ff, tree[tree.Children.Count - 1].Data?.AsInt()); Assert.AreEqual(0x55aa00ff, tree2[tree2.Children.Count - 1].Data?.AsInt()); @@ -343,7 +343,7 @@ public async Task TreeToString() var tree = CreateTestTree(); await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); string treeString = tree.TreeToString(); string treeString2 = tree2.TreeToString(); @@ -364,7 +364,7 @@ public async Task Long() tree[0].Add(numericNode); await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual(0x55aa00ff19781986, tree2[0][1].Data?.AsLong()); } @@ -382,7 +382,7 @@ public async Task Double() tree[0].Add(numericNode); await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); double? value = tree2[0][1].MetaData?.AsDouble(); Assert.IsTrue(value > 3.1415926 && value < 3.1415927); @@ -403,7 +403,7 @@ public async Task GuidTest() tree.Add(guidNode); await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual(0, testGuid.CompareTo(tree2[0].Data?.AsGuid())); } @@ -421,7 +421,7 @@ public async Task Decimal() tree.Add(decimalNode); await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual(1.978M, tree2[0].MetaData?.AsDecimal()); } @@ -441,7 +441,7 @@ public async Task ByteArray() tree.Add(byteArrayNode); await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); byte[]? testBytes2 = tree2[0].Data?.AsByteArray(); @@ -465,7 +465,7 @@ public async Task Unicode() tree.Add(unicodeNode); await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual("Hello, UTF-32LE world!", tree2[0].Data?.AsUtf32String()); Assert.AreEqual("Hello, UTF-16LE world!", tree2[0].MetaData?.AsUtf16String()); @@ -485,7 +485,7 @@ public async Task ElementTest() await outerTree.SaveAsync(TestFileName).ConfigureAwait(false); - var outerTree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var outerTree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); var innerTree2 = await outerTree2.Data!.AsElementAsync().ConfigureAwait(false); Assert.AreEqual((short)1000, outerTree2.MetaData?.AsShort()); @@ -507,7 +507,7 @@ public async Task DateTimeTimeSpan() }; await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual(0, birthDay.CompareTo(tree2[0].Data?.AsDateTime())); Assert.AreEqual(0, testTimeSpan.CompareTo(tree2[0].MetaData?.AsTimeSpan())); @@ -531,7 +531,7 @@ public async Task DateTimeOffset() }; await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual(0, birthDay.CompareTo(tree2[0].Data?.AsDateTimeOffset() ?? throw new ArgumentNullException("Test failed."))); @@ -554,7 +554,7 @@ public async Task Char() tree.Add(unicodeNode); await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual('Ä', tree2[0].Data?.AsChar()); Assert.AreEqual('Ő', tree2[0].MetaData?.AsChar()); @@ -580,7 +580,7 @@ public async Task StringPerformance() } await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual(tree.TreeToString(), tree2.TreeToString()); } @@ -601,7 +601,7 @@ public async Task IntPerformance() } await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual(tree.TreeToString(), tree2.TreeToString()); } @@ -629,8 +629,8 @@ public async Task StreamCompatibility() stream.Position = 0; - var tree2A = await Element.LoadAsync(stream).ConfigureAwait(false); - var tree2B = await Element.LoadAsync(stream).ConfigureAwait(false); + var tree2A = await new Element().LoadAsync(stream).ConfigureAwait(false); + var tree2B = await new Element().LoadAsync(stream).ConfigureAwait(false); string sTreeA = treeA.TreeToString(); string sTreeB = treeB.TreeToString(); @@ -810,10 +810,11 @@ public async Task Events() var loadingNodes = new List(); var loadedNodes = new List(); - Element.OnDataLoading += (s, _) => loadingNodes.Add(((Element)s!).Data!.AsUtf8String()); - Element.OnDataLoaded += (s, _) => loadedNodes.Add(((Element)s!).Data!.AsUtf8String()); + var loaderElement = new Element(); + loaderElement.OnDataLoading += (s, _) => loadingNodes.Add(((Element)s!).Data!.AsUtf8String()); + loaderElement.OnDataLoaded += (s, _) => loadedNodes.Add(((Element)s!).Data!.AsUtf8String()); - var tree2 = await Element.LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await loaderElement.LoadAsync(TestFileName).ConfigureAwait(false); Assert.AreEqual(1, savingEventFired); Assert.AreEqual(1, savedEventFired); From 200e69a0d7526b5c2ca467c09942637688e9dd0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fuszenecker=20R=C3=B3bert?= Date: Thu, 12 Oct 2023 22:55:21 +0200 Subject: [PATCH 2/5] Docs. --- .../Data/AsElementAsync/README.md | 6 ++- docs/Promptuarium/Data/README.md | 2 +- .../Element/FromBase64StringAsync/README.md | 48 ++----------------- docs/Promptuarium/Element/LoadAsync/README.md | 8 ++-- .../Element/OnDataLoaded/README.md | 2 +- .../Element/OnDataLoading/README.md | 2 +- .../Element/OnMetaDataLoaded/README.md | 2 +- .../Element/OnMetaDataLoading/README.md | 2 +- docs/Promptuarium/Element/README.md | 3 +- docs/System/IO/Stream/README.md | 2 +- 10 files changed, 20 insertions(+), 57 deletions(-) diff --git a/docs/Promptuarium/Data/AsElementAsync/README.md b/docs/Promptuarium/Data/AsElementAsync/README.md index 23b0d63..9dbd820 100644 --- a/docs/Promptuarium/Data/AsElementAsync/README.md +++ b/docs/Promptuarium/Data/AsElementAsync/README.md @@ -1,4 +1,4 @@ -# Data\.AsElementAsync\(Stream\) Method +# Data\.AsElementAsync\(Stream, Element\) Method [Home](../../../README.md) @@ -10,7 +10,7 @@ Converts a stream to a tree\. ```csharp -public static System.Threading.Tasks.Task AsElementAsync(this System.IO.Stream stream) +public static System.Threading.Tasks.Task AsElementAsync(this System.IO.Stream stream, Promptuarium.Element loaderElement = null) ``` ### Parameters @@ -19,6 +19,8 @@ public static System.Threading.Tasks.Task AsElementAsync(t The source stream +**loaderElement**   [Element](../../Element/README.md) + ### Returns [Task](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1)\<[Element](../../Element/README.md)\> diff --git a/docs/Promptuarium/Data/README.md b/docs/Promptuarium/Data/README.md index becaa42..731eeaa 100644 --- a/docs/Promptuarium/Data/README.md +++ b/docs/Promptuarium/Data/README.md @@ -23,7 +23,7 @@ public static class Data | [AsDateTimeOffset(Stream)](AsDateTimeOffset/README.md) | Converts a stream to a DateTimeOffset value\. | | [AsDecimal(Stream)](AsDecimal/README.md) | Converts a stream to a decimal value\. | | [AsDouble(Stream)](AsDouble/README.md) | Converts a stream to a double value\. | -| [AsElementAsync(Stream)](AsElementAsync/README.md) | Converts a stream to a tree\. | +| [AsElementAsync(Stream, Element)](AsElementAsync/README.md) | Converts a stream to a tree\. | | [AsFloat(Stream)](AsFloat/README.md) | Converts a stream to a float value\. | | [AsGuid(Stream)](AsGuid/README.md) | Converts a stream to a GUID value\. | | [AsInt(Stream)](AsInt/README.md) | Converts a stream to an int value\. | diff --git a/docs/Promptuarium/Element/FromBase64StringAsync/README.md b/docs/Promptuarium/Element/FromBase64StringAsync/README.md index 5524fdf..d84c243 100644 --- a/docs/Promptuarium/Element/FromBase64StringAsync/README.md +++ b/docs/Promptuarium/Element/FromBase64StringAsync/README.md @@ -1,4 +1,4 @@ -# Element\.FromBase64StringAsync Method +# Element\.FromBase64StringAsync\(String, Element, CancellationToken\) Method [Home](../../../README.md) @@ -6,22 +6,11 @@ **Assembly**: Promptuarium\.dll -## Overloads - -| Method | Summary | -| ------ | ------- | -| [FromBase64StringAsync(String, CancellationToken)](#142880008) | Creates a tree from a Base64 string\. | -| [FromBase64StringAsync(String)](#3836437132) | Creates a tree from a Base64 string\. | - - - -## FromBase64StringAsync\(String, CancellationToken\) - Creates a tree from a Base64 string\. ```csharp -public static System.Threading.Tasks.Task FromBase64StringAsync(string base64String, System.Threading.CancellationToken cancellationToken) +public static System.Threading.Tasks.Task FromBase64StringAsync(string base64String, Promptuarium.Element loaderElement = null, System.Threading.CancellationToken cancellationToken = default) ``` ### Parameters @@ -30,6 +19,8 @@ public static System.Threading.Tasks.Task FromBase64String The tree in Base64\. +**loaderElement**   [Element](../README.md) + **cancellationToken**   [CancellationToken](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken) The cancellation token\. @@ -40,36 +31,7 @@ The cancellation token\. The tree\. -### Examples - -``` -var tree = await Element.FromBase64StringAsync(base64String); -``` - - - -## FromBase64StringAsync\(String\) - - -Creates a tree from a Base64 string\. - -```csharp -public static System.Threading.Tasks.Task FromBase64StringAsync(string base64String) -``` - -### Parameters - -**base64String**   [String](https://docs.microsoft.com/en-us/dotnet/api/system.string) - -The tree in Base64\. - -### Returns - -[Task](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1)\<[Element](../README.md)\> - -The tree\. - -### Examples +## Examples ``` var tree = await Element.FromBase64StringAsync(base64String); diff --git a/docs/Promptuarium/Element/LoadAsync/README.md b/docs/Promptuarium/Element/LoadAsync/README.md index 2097bae..bcc9934 100644 --- a/docs/Promptuarium/Element/LoadAsync/README.md +++ b/docs/Promptuarium/Element/LoadAsync/README.md @@ -23,7 +23,7 @@ Loads a tree from a stream\. ```csharp -public static System.Threading.Tasks.Task LoadAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken) +public System.Threading.Tasks.Task LoadAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken) ``` ### Parameters @@ -63,7 +63,7 @@ var tree = await Element.LoadAsync(stream, cancellationToken); Loads a tree from a stream\. ```csharp -public static System.Threading.Tasks.Task LoadAsync(System.IO.Stream stream) +public System.Threading.Tasks.Task LoadAsync(System.IO.Stream stream) ``` ### Parameters @@ -99,7 +99,7 @@ var tree = await Element.LoadAsync(stream); Loads a tree from a file\. ```csharp -public static System.Threading.Tasks.Task LoadAsync(string fileName, System.Threading.CancellationToken cancellationToken) +public System.Threading.Tasks.Task LoadAsync(string fileName, System.Threading.CancellationToken cancellationToken) ``` ### Parameters @@ -138,7 +138,7 @@ var tree = await Element.LoadAsync("test.prm", cancellationToken); Loads a tree from a file\. ```csharp -public static System.Threading.Tasks.Task LoadAsync(string fileName) +public System.Threading.Tasks.Task LoadAsync(string fileName) ``` ### Parameters diff --git a/docs/Promptuarium/Element/OnDataLoaded/README.md b/docs/Promptuarium/Element/OnDataLoaded/README.md index 00a4463..ab48928 100644 --- a/docs/Promptuarium/Element/OnDataLoaded/README.md +++ b/docs/Promptuarium/Element/OnDataLoaded/README.md @@ -10,6 +10,6 @@ Event handler for all Promptuarium data loaded events ```csharp -public static event EventHandler? OnDataLoaded +public event EventHandler? OnDataLoaded ``` diff --git a/docs/Promptuarium/Element/OnDataLoading/README.md b/docs/Promptuarium/Element/OnDataLoading/README.md index 1da1492..bd0a679 100644 --- a/docs/Promptuarium/Element/OnDataLoading/README.md +++ b/docs/Promptuarium/Element/OnDataLoading/README.md @@ -10,6 +10,6 @@ Event handler for all Promptuarium data loading events ```csharp -public static event EventHandler? OnDataLoading +public event EventHandler? OnDataLoading ``` diff --git a/docs/Promptuarium/Element/OnMetaDataLoaded/README.md b/docs/Promptuarium/Element/OnMetaDataLoaded/README.md index 9e0c57c..ce741a1 100644 --- a/docs/Promptuarium/Element/OnMetaDataLoaded/README.md +++ b/docs/Promptuarium/Element/OnMetaDataLoaded/README.md @@ -10,6 +10,6 @@ Event handler for all Promptuarium metadata loaded events ```csharp -public static event EventHandler? OnMetaDataLoaded +public event EventHandler? OnMetaDataLoaded ``` diff --git a/docs/Promptuarium/Element/OnMetaDataLoading/README.md b/docs/Promptuarium/Element/OnMetaDataLoading/README.md index a8c0226..8b68ab6 100644 --- a/docs/Promptuarium/Element/OnMetaDataLoading/README.md +++ b/docs/Promptuarium/Element/OnMetaDataLoading/README.md @@ -10,6 +10,6 @@ Event handler for all Promptuarium metadata loading events ```csharp -public static event EventHandler? OnMetaDataLoading +public event EventHandler? OnMetaDataLoading ``` diff --git a/docs/Promptuarium/Element/README.md b/docs/Promptuarium/Element/README.md index d1c3ae0..8562940 100644 --- a/docs/Promptuarium/Element/README.md +++ b/docs/Promptuarium/Element/README.md @@ -51,8 +51,7 @@ public class Element : System.Collections.Generic.IEnumerable.GetEnumerator](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1.getenumerator)\) | | [GetHashCode()](https://docs.microsoft.com/en-us/dotnet/api/system.object.gethashcode) | \(Inherited from [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object)\) | | [GetStatistics()](GetStatistics/README.md) | Gets the statistics about the tree | diff --git a/docs/System/IO/Stream/README.md b/docs/System/IO/Stream/README.md index 343b725..669bde4 100644 --- a/docs/System/IO/Stream/README.md +++ b/docs/System/IO/Stream/README.md @@ -13,7 +13,7 @@ | [AsDateTimeOffset(Stream)](../../../Promptuarium/Data/AsDateTimeOffset/README.md) | Converts a stream to a DateTimeOffset value\. | | [AsDecimal(Stream)](../../../Promptuarium/Data/AsDecimal/README.md) | Converts a stream to a decimal value\. | | [AsDouble(Stream)](../../../Promptuarium/Data/AsDouble/README.md) | Converts a stream to a double value\. | -| [AsElementAsync(Stream)](../../../Promptuarium/Data/AsElementAsync/README.md) | Converts a stream to a tree\. | +| [AsElementAsync(Stream, Element)](../../../Promptuarium/Data/AsElementAsync/README.md) | Converts a stream to a tree\. | | [AsFloat(Stream)](../../../Promptuarium/Data/AsFloat/README.md) | Converts a stream to a float value\. | | [AsGuid(Stream)](../../../Promptuarium/Data/AsGuid/README.md) | Converts a stream to a GUID value\. | | [AsInt(Stream)](../../../Promptuarium/Data/AsInt/README.md) | Converts a stream to an int value\. | From b9d0f0be26ceb3a4aafbbf1cc3cac2806cc0fc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fuszenecker=20R=C3=B3bert?= Date: Fri, 14 Jun 2024 21:22:01 +0200 Subject: [PATCH 3/5] Small fixes. --- .gitattributes | 1 + src/Data.cs | 8 +- src/ElementEvents.cs | 2 +- src/ElementIo.cs | 6 +- src/ElementSerializer.cs | 53 +- src/ElementTree.cs | 37 +- src/GlobalSuppressions.cs | 55 ++ src/Promptuarium.csproj | 6 +- tests/GlobalSuppressions.cs | 127 +++ tests/Promptuarium.Tests.csproj | 4 +- tests/StabilityTests.cs | 111 ++- tests/UnitTests.cs | 1531 +++++++++++++++--------------- tools/Dump/Dump.csproj | 2 +- tools/Dump/GlobalSuppressions.cs | 8 + tools/Dump/Program.cs | 42 +- 15 files changed, 1075 insertions(+), 918 deletions(-) create mode 100644 .gitattributes create mode 100644 src/GlobalSuppressions.cs create mode 100644 tests/GlobalSuppressions.cs create mode 100644 tools/Dump/GlobalSuppressions.cs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9cc4965 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.cs diff=csharp diff --git a/src/Data.cs b/src/Data.cs index c88172c..979b25e 100644 --- a/src/Data.cs +++ b/src/Data.cs @@ -508,7 +508,7 @@ public static decimal AsDecimal(this Stream stream) public static Stream FromVarInt(long value) { var result = new MemoryStream(); - ulong buffer = (value >= 0) ? (ulong)(value << 1) : (((ulong)(-value) << 1) + 1); + ulong buffer = (value >= 0) ? (ulong)(value << 1) : (((ulong)-value << 1) + 1); CompactBytes(result, buffer); return result; } @@ -876,7 +876,7 @@ public static async Task FromElementAsync(Element value) } var stream = new MemoryStream(); - await value.SaveAsync(stream).ConfigureAwait(false); + await value.SaveAsync(stream); return stream; } @@ -890,12 +890,12 @@ public static async Task FromElementAsync(Element value) /// var tree = await Data.AsTreeAsync(stream); /// /// - public static async Task AsElementAsync(this Stream stream, Element loaderElement = default) + public static async Task AsElementAsync(this Stream stream, Element? loaderElement = default) { loaderElement ??= new Element(); Element result; stream.Position = 0; - result = await loaderElement.LoadAsync(stream).ConfigureAwait(false); + result = await loaderElement.LoadAsync(stream); stream.Position = 0; return result; } diff --git a/src/ElementEvents.cs b/src/ElementEvents.cs index 5013756..d818aa8 100644 --- a/src/ElementEvents.cs +++ b/src/ElementEvents.cs @@ -105,7 +105,7 @@ public partial class Element /// Event handler for all Promptuarium metadata saved events /// public event EventHandler? OnMetaDataSaved; - + #endregion } #endregion diff --git a/src/ElementIo.cs b/src/ElementIo.cs index 087142f..c248ccc 100644 --- a/src/ElementIo.cs +++ b/src/ElementIo.cs @@ -58,7 +58,7 @@ public Task LoadAsync(Stream stream) public async Task LoadAsync(string fileName, CancellationToken cancellationToken) { using var fileStream = new FileStream(fileName, FileMode.Open); - return await LoadAsync(fileStream, cancellationToken).ConfigureAwait(false); + return await LoadAsync(fileStream, cancellationToken); } /// @@ -94,7 +94,7 @@ public Task LoadAsync(string fileName) /// public async Task SaveAsync(Stream stream, CancellationToken cancellationToken) { - await SerializeAsync(stream, new SerializationArguments(), cancellationToken).ConfigureAwait(false); + await SerializeAsync(stream, new SerializationArguments(), cancellationToken); stream.WriteByte(ControlByte(Directions.Append, DataType.Data, SizeType.Linear, 0)); } @@ -127,7 +127,7 @@ public Task SaveAsync(Stream stream) public async Task SaveAsync(string fileName, CancellationToken cancellationToken) { using Stream stream = new FileStream(fileName, FileMode.Create); - await SaveAsync(stream, cancellationToken).ConfigureAwait(false); + await SaveAsync(stream, cancellationToken); } /// diff --git a/src/ElementSerializer.cs b/src/ElementSerializer.cs index 654a8d8..9c78da0 100644 --- a/src/ElementSerializer.cs +++ b/src/ElementSerializer.cs @@ -70,7 +70,7 @@ private async Task SerializeAsync(Stream stream, SerializationArguments serializ if (Contains(Data)) { - appending = await SerializeContentAsync(stream, Data!, DataType.Data, direction, appending, cancellationToken).ConfigureAwait(false); + appending = await SerializeContentAsync(stream, Data!, DataType.Data, direction, appending, cancellationToken); } // Firing event @@ -85,7 +85,7 @@ private async Task SerializeAsync(Stream stream, SerializationArguments serializ if (Contains(MetaData)) { - appending = await SerializeContentAsync(stream, MetaData!, DataType.MetaData, direction, appending, cancellationToken).ConfigureAwait(false); + appending = await SerializeContentAsync(stream, MetaData!, DataType.MetaData, direction, appending, cancellationToken); } // Firing event @@ -105,7 +105,7 @@ private async Task SerializeAsync(Stream stream, SerializationArguments serializ if (child != null) { - await child.SerializeAsync(stream, serializationArguments, cancellationToken).ConfigureAwait(false); + await child.SerializeAsync(stream, serializationArguments, cancellationToken); } } @@ -137,8 +137,8 @@ private static async Task SerializeContentAsync(Stream target, Stream sour int bufferSize = size.SizeType == SizeType.Linear ? size.SizeBits : 1 << (size.SizeBits + NibbleSizeInBits); byte[] buffer = new byte[bufferSize]; - await source.ReadAsync(buffer.AsMemory(0, bufferSize), cancellationToken).ConfigureAwait(false); - await target.WriteAsync(buffer.AsMemory(0, bufferSize), cancellationToken).ConfigureAwait(false); + await source.ReadAsync(buffer.AsMemory(0, bufferSize), cancellationToken); + await target.WriteAsync(buffer.AsMemory(0, bufferSize), cancellationToken); } return appending; @@ -146,12 +146,9 @@ private static async Task SerializeContentAsync(Stream target, Stream sour private static byte ControlByte(Directions direction, DataType dataType, SizeType sizeType, byte sizeBits) { - if (sizeBits <= NibbleMaxValue) - { - return (byte)((byte)direction | (byte)dataType | (byte)sizeType | sizeBits); - } - - throw new PromptuariumException($"Size bits greater than the max value ({NibbleMaxValue.ToString(CultureInfo.InvariantCulture)} bits)"); + return sizeBits <= NibbleMaxValue + ? (byte)((byte)direction | (byte)dataType | (byte)sizeType | sizeBits) + : throw new PromptuariumException($"Size bits greater than the max value ({NibbleMaxValue.ToString(CultureInfo.InvariantCulture)} bits)"); } private static IEnumerable GetSizes(long size) @@ -176,7 +173,7 @@ private static IEnumerable GetSizes(long size) { byte bit; - for (bit = ChunkSizeInBits; (bit >= NibbleSizeInBits) && (word & ((long) 1 << bit)) == 0;) + for (bit = ChunkSizeInBits; (bit >= NibbleSizeInBits) && (word & ((long)1 << bit)) == 0;) { bit--; } @@ -222,20 +219,20 @@ private async Task DeserializeAsync(Stream stream, CancellationToken ca while (stream.Position < stream.Length) { - byte controlByte = (byte) stream.ReadByte(); + byte controlByte = (byte)stream.ReadByte(); - switch (controlByte & (byte) Directions.Mask) + switch (controlByte & (byte)Directions.Mask) { - case (byte) Directions.New: + case (byte)Directions.New: node = AddNewNode(parent); break; - case (byte) Directions.Down: + case (byte)Directions.Down: parent = node; node = AddNewNode(parent); break; - case (byte) Directions.Up: + case (byte)Directions.Up: if (parent.Parent != null) { parent = parent.Parent; @@ -248,19 +245,22 @@ private async Task DeserializeAsync(Stream stream, CancellationToken ca break; - case (byte) Directions.Append: + case (byte)Directions.Append: break; + + default: + throw new InvalidOperationException(); } int chunkSize = GetChunkSize(controlByte); - if (((controlByte & (byte)Directions.Mask) == (byte) Directions.Append) && (chunkSize == 0)) + if (((controlByte & (byte)Directions.Mask) == (byte)Directions.Append) && (chunkSize == 0)) { break; } byte[] buffer = new byte[chunkSize]; - await stream.ReadAsync(buffer.AsMemory(0, chunkSize), cancellationToken).ConfigureAwait(false); + await stream.ReadAsync(buffer.AsMemory(0, chunkSize), cancellationToken); if (IsDataChunk(controlByte)) { @@ -271,7 +271,7 @@ private async Task DeserializeAsync(Stream stream, CancellationToken ca // Firing event OnDataLoading?.Invoke(node, new PromptuariumLoadingEventArgs()); - await node.Data.WriteAsync(buffer.AsMemory(0, chunkSize), cancellationToken).ConfigureAwait(false); + await node.Data.WriteAsync(buffer.AsMemory(0, chunkSize), cancellationToken); // Firing event OnDataLoaded?.Invoke(node, new PromptuariumLoadedEventArgs()); @@ -286,7 +286,7 @@ private async Task DeserializeAsync(Stream stream, CancellationToken ca // Firing event OnMetaDataLoading?.Invoke(node, new PromptuariumLoadingEventArgs()); - await node.MetaData.WriteAsync(buffer.AsMemory(0, chunkSize), cancellationToken).ConfigureAwait(false); + await node.MetaData.WriteAsync(buffer.AsMemory(0, chunkSize), cancellationToken); // Firing event OnMetaDataLoaded?.Invoke(node, new PromptuariumLoadedEventArgs()); @@ -296,14 +296,7 @@ private async Task DeserializeAsync(Stream stream, CancellationToken ca PurgeEmptyNodes(root); - if (root.Children.Count > 0) - { - return root.Children[0]; - } - else - { - return new Element(); - } + return root.Children.Count > 0 ? root.Children[0] : new Element(); } private static int GetChunkSize(byte controlByte) => IsSizeLogarithmic(controlByte) ? diff --git a/src/ElementTree.cs b/src/ElementTree.cs index 2d00ae8..93c5f80 100644 --- a/src/ElementTree.cs +++ b/src/ElementTree.cs @@ -34,7 +34,7 @@ public partial class Element : IEnumerable /// List of children. it is never null, but can be empty /// public IReadOnlyList Children { get; } = new List(); - + #endregion #region Constructors @@ -138,7 +138,7 @@ public Element(Stream? data, Stream? metaData, IEnumerable children) child.Parent = this; } } - + #endregion #region Indexer @@ -154,23 +154,14 @@ public Element(Stream? data, Stream? metaData, IEnumerable children) /// var node = tree[0]; /// /// - public Element this[int index] - { - get - { - if (index >= 0 && index < Children.Count) - { - return Children[index]; - } - - throw new PromptuariumException($"Index {index} in out of range [0...{Children.Count}]"); - } - } + public Element this[int index] => index >= 0 && index < Children.Count + ? Children[index] + : throw new PromptuariumException($"Index {index} in out of range [0...{Children.Count}]"); #endregion #region Tree operations - + /// /// Add node(s) to the tree. Node can be null, in this case nothing will happen. /// @@ -345,7 +336,7 @@ public Element Detach(Element node) { if (node.Parent.Children.Contains(node)) { - ((List)(node.Parent.Children)).Remove(node); + ((List)node.Parent.Children).Remove(node); } else { @@ -417,7 +408,7 @@ public Element Walk(WalkHandler handler) Walk(this, ancestors, handler); return this; } - + #endregion #region Conversion functions @@ -492,7 +483,7 @@ public async Task ToBase64StringAsync(CancellationToken cancellationToke { using var memoryStream = new MemoryStream(); - await SaveAsync(memoryStream, cancellationToken).ConfigureAwait(false); + await SaveAsync(memoryStream, cancellationToken); byte[] buffer = new byte[memoryStream.Length]; Array.Copy(memoryStream.ToArray(), buffer, (int)memoryStream.Length); @@ -534,12 +525,12 @@ public async Task ToBase64StringAsync(CancellationToken cancellationToke /// var tree = await Element.FromBase64StringAsync(base64String); /// /// - public static async Task FromBase64StringAsync(string base64String, - Element loaderElement = default, CancellationToken cancellationToken = default) + public static async Task FromBase64StringAsync(string base64String, + Element? loaderElement = default, CancellationToken cancellationToken = default) { loaderElement ??= new Element(); using var memoryStream = new MemoryStream(Convert.FromBase64String(base64String)); - return await loaderElement.LoadAsync(memoryStream, cancellationToken).ConfigureAwait(false); + return await loaderElement.LoadAsync(memoryStream, cancellationToken); } #endregion @@ -628,7 +619,7 @@ private void NodeToString(Element node, int level, StringBuilder stringBuilder, stringBuilder.Append(" = \""); stringBuilder.Append(node.MetaData! .AsUtf8String() - .Select(c => c < '\u0020' || c > '\u007F' ? '.' : c) + .Select(c => c is < '\u0020' or > '\u007F' ? '.' : c) .ToArray()); stringBuilder.Append('\"'); stringBuilder.Append(']'); @@ -646,7 +637,7 @@ private void NodeToString(Element node, int level, StringBuilder stringBuilder, stringBuilder.Append(" = \""); stringBuilder.Append(node.Data! .AsUtf8String() - .Select(c => c < '\u0020' || c > '\u007F' ? '.' : c) + .Select(c => c is < '\u0020' or > '\u007F' ? '.' : c) .ToArray()); stringBuilder.Append('\"'); } diff --git a/src/GlobalSuppressions.cs b/src/GlobalSuppressions.cs new file mode 100644 index 0000000..bdf36cd --- /dev/null +++ b/src/GlobalSuppressions.cs @@ -0,0 +1,55 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; +[assembly: SuppressMessage("Style", "IDE0160:Convert to block scoped namespace", Justification = "Reviewed.", Scope = "namespace", Target = "~N:Promptuarium")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.FromByte(System.Byte)~System.IO.Stream")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.FromBase64StringAsync(System.String,Promptuarium.Element,System.Threading.CancellationToken)~System.Threading.Tasks.Task{Promptuarium.Element}")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.Remove(Promptuarium.Element)~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.ToBase64StringAsync(System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.String}")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.ToString~System.String")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.TreeToString(System.String)~System.String")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.Walk(Promptuarium.Element,System.Collections.Generic.List{Promptuarium.Element},Promptuarium.Element.WalkHandler)")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.Walk(Promptuarium.Element.WalkHandler)~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0045:Convert to conditional expression", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.SerializeAsync(System.IO.Stream,Promptuarium.Element.SerializationArguments,System.Threading.CancellationToken)~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.Add(System.Collections.Generic.IEnumerable{Promptuarium.Element})~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.DeserializeAsync(System.IO.Stream,System.Threading.CancellationToken)~System.Threading.Tasks.Task{Promptuarium.Element}")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.Detach(Promptuarium.Element)~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.GetStatistics~Promptuarium.Statistics")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.NodeToString(Promptuarium.Element,System.Int32,System.Text.StringBuilder,System.Boolean,System.String)")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.op_Addition(Promptuarium.Element,Promptuarium.Element)~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.op_Subtraction(Promptuarium.Element,Promptuarium.Element)~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.PurgeEmptyNodes(Promptuarium.Element)")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.Remove(Promptuarium.Element)~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.SerializeContentAsync(System.IO.Stream,System.IO.Stream,Promptuarium.Element.DataType,Promptuarium.Element.Directions,System.Boolean,System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Boolean}")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.StreamToString(System.IO.Stream,System.Text.StringBuilder)")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.DeserializeAsync(System.IO.Stream,System.Threading.CancellationToken)~System.Threading.Tasks.Task{Promptuarium.Element}")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.SerializeContentAsync(System.IO.Stream,System.IO.Stream,Promptuarium.Element.DataType,Promptuarium.Element.Directions,System.Boolean,System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Boolean}")] +[assembly: SuppressMessage("Style", "IDE0022:Use block body for method", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.GetChunkSize(System.Byte)~System.Int32")] +[assembly: SuppressMessage("Style", "IDE0022:Use block body for method", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.IsDataChunk(System.Byte)~System.Boolean")] +[assembly: SuppressMessage("Style", "IDE0022:Use block body for method", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.IsSizeLogarithmic(System.Byte)~System.Boolean")] +[assembly: SuppressMessage("Style", "IDE0022:Use block body for method", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.ToBase64StringAsync~System.Threading.Tasks.Task{System.String}")] +[assembly: SuppressMessage("Style", "IDE0028:Simplify collection initialization", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.AsElementAsync(System.IO.Stream,Promptuarium.Element)~System.Threading.Tasks.Task{Promptuarium.Element}")] +[assembly: SuppressMessage("Style", "IDE0028:Simplify collection initialization", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.AddNewNode(Promptuarium.Element)~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0028:Simplify collection initialization", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.DeserializeAsync(System.IO.Stream,System.Threading.CancellationToken)~System.Threading.Tasks.Task{Promptuarium.Element}")] +[assembly: SuppressMessage("Style", "IDE0028:Simplify collection initialization", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.FromBase64StringAsync(System.String,Promptuarium.Element,System.Threading.CancellationToken)~System.Threading.Tasks.Task{Promptuarium.Element}")] +[assembly: SuppressMessage("Style", "IDE0028:Simplify collection initialization", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.GetSizes(System.Int64)~System.Collections.Generic.IEnumerable{Promptuarium.Element.SizeDescriptor}")] +[assembly: SuppressMessage("Style", "IDE0028:Simplify collection initialization", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.SerializeAsync(System.IO.Stream,Promptuarium.Element.SerializationArguments,System.Threading.CancellationToken)~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0028:Simplify collection initialization", Justification = "Reviewed.", Scope = "member", Target = "~P:Promptuarium.Element.Children")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.GetBuffer(System.IO.Stream,System.Int32)~System.Byte[]")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.GetBuffer(System.IO.Stream,System.Int32)~System.Byte[]")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.AsDateTimeOffset(System.IO.Stream)~System.DateTimeOffset")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.AsDecimal(System.IO.Stream)~System.Decimal")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.FromDateTimeOffset(System.DateTimeOffset)~System.IO.Stream")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.FromDecimal(System.Decimal)~System.IO.Stream")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.FromElementAsync(Promptuarium.Element)~System.Threading.Tasks.Task{System.IO.Stream}")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.FromVarInt(System.Int64)~System.IO.Stream")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Data.FromVarUInt(System.UInt64)~System.IO.Stream")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.LoadAsync(System.String,System.Threading.CancellationToken)~System.Threading.Tasks.Task{Promptuarium.Element}")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.SerializeAsync(System.IO.Stream,Promptuarium.Element.SerializationArguments,System.Threading.CancellationToken)~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.AddNewNode(Promptuarium.Element)~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.DeserializeAsync(System.IO.Stream,System.Threading.CancellationToken)~System.Threading.Tasks.Task{Promptuarium.Element}")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.GetSizes(System.Int64)~System.Collections.Generic.IEnumerable{Promptuarium.Element.SizeDescriptor}")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Element.GetStatistics~Promptuarium.Statistics")] diff --git a/src/Promptuarium.csproj b/src/Promptuarium.csproj index be38850..84e9a06 100644 --- a/src/Promptuarium.csproj +++ b/src/Promptuarium.csproj @@ -1,9 +1,9 @@  - netstandard2.1 + net8.0 true - 10 + latest enable preview AllEnabledByDefault @@ -13,7 +13,7 @@ Promptuarium Promptuarium - 5.0.0 + 6.0.0 Fuszenecker Róbert Fuszenecker Róbert Fuszenecker Software Development diff --git a/tests/GlobalSuppressions.cs b/tests/GlobalSuppressions.cs new file mode 100644 index 0000000..46f094e --- /dev/null +++ b/tests/GlobalSuppressions.cs @@ -0,0 +1,127 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.StabilityTests.GenerateTree(Promptuarium.Element,System.Int32,System.Int32,System.Double,System.Int32)")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.Add")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.AddLinq")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.AddNullThrowsException")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.Base64Test~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.ByteArray~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.Char~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.CheckEnumerability")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.CopyConstructor")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.CreateTestFileName~System.String")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.CreateTestTree~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.Decimal~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.Double~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.FromInt~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.GuidTest~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.IntPerformance~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.Long~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.Remove")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.Statistics")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.StreamCompatibility~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.StringPerformance~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.Unicode~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarInt0")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarInt100")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarInt65537")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarIntMinus100")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarIntMinus65537")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarUInt0")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarUInt100")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarUInt65537")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarInt0")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarInt100")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarInt65537")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarIntMinus100")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarIntMinus65537")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarUInt0")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarUInt100")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:PromptuariumTests.UnitTests.VarUInt65537")] +[assembly: SuppressMessage("Style", "IDE0160:Convert to block scoped namespace", Justification = "Reviewed.", Scope = "namespace", Target = "~N:PromptuariumTests")] +[assembly: SuppressMessage("Style", "IDE0160:Convert to block scoped namespace", Justification = "Reviewed.", Scope = "namespace", Target = "~N:Promptuarium.Tests")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.StabilityTests.GenerateTree(Promptuarium.Element,System.Int32,System.Int32,System.Double,System.Int32)")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Add")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.AddNullThrowsException")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Base64Test~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.ByteArray~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Char~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.CopyConstructor")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.CreateTestFileName~System.String")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.CreateTestTree~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Decimal~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Double~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.FromInt~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.GuidTest~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.IntPerformance~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Long~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Remove")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Statistics")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.StreamCompatibility~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.StringPerformance~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Unicode~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarInt0")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarInt100")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarInt65537")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarIntMinus100")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarIntMinus65537")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarUInt0")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarUInt100")] +[assembly: SuppressMessage("Style", "IDE0058:Expression value is never used", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarUInt65537")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarInt0")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarInt100")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarInt65537")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarIntMinus100")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarIntMinus65537")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarUInt0")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarUInt100")] +[assembly: SuppressMessage("Reliability", "CA2022:Avoid inexact read with 'Stream.Read'", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarUInt65537")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.StabilityTests.GenerateTree(System.Int32,System.Int32,System.Double)~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.StabilityTests.GenerateTree(Promptuarium.Element,System.Int32,System.Int32,System.Double,System.Int32)")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.CopyConstructor")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.ParameterlessConstructor")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.ComplexConstructor")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.LinqFriendlyConstructor")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Add")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.AddCollectionInitializer")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.AddLinq")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Base64EventExample~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Base64Test~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.ByteArray~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Char~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.CheckEnumerability")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.CleanupStream~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.CreateTestTree~Promptuarium.Element")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.DateTimeOffset~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.DateTimeTimeSpan~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Decimal~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Detach")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Double~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.ElementTest~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.EmptyNode~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Events~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.FromInt~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.GuidTest~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Indexer")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.IntPerformance~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Load~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Long~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Remove")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Save~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Statistics")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.StreamCompatibility~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.StringPerformance~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.TreeToString~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.TreeToStringTest~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.Unicode~System.Threading.Tasks.Task")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarInt0")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarInt65537")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarIntMinus100")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarIntMinus65537")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarUInt0")] +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.", Scope = "member", Target = "~M:Promptuarium.Tests.UnitTests.VarUInt65537")] +[assembly: SuppressMessage("CodeQuality", "IDE0076:Invalid global 'SuppressMessageAttribute'", Justification = "")] diff --git a/tests/Promptuarium.Tests.csproj b/tests/Promptuarium.Tests.csproj index 75d9f5d..606b54f 100644 --- a/tests/Promptuarium.Tests.csproj +++ b/tests/Promptuarium.Tests.csproj @@ -1,8 +1,8 @@ - net6 - 10 + net8.0 + latest enable preview AllEnabledByDefault diff --git a/tests/StabilityTests.cs b/tests/StabilityTests.cs index a557612..b8271fd 100644 --- a/tests/StabilityTests.cs +++ b/tests/StabilityTests.cs @@ -2,86 +2,83 @@ using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Promptuarium; -namespace PromptuariumTests +namespace Promptuarium.Tests; + +[TestClass] +public class StabilityTests { - [TestClass] - public class StabilityTests - { - private readonly Random random = new ((int)DateTime.Now.Ticks); + private readonly Random random = new((int)DateTime.Now.Ticks); - [TestMethod] - public async Task Stability() - { - const int maxTests = 10000; - const int minChildren = 0; - const int maxChildren = 10; - const double probability = 0.75; + [TestMethod] + public async Task Stability() + { + const int maxTests = 10000; + const int minChildren = 0; + const int maxChildren = 10; + const double probability = 0.75; - await CreateAndVerifyTrees(maxTests, minChildren, maxChildren, probability, @".\stability.prm").ConfigureAwait(false); - } + await CreateAndVerifyTrees(maxTests, minChildren, maxChildren, probability, @".\stability.prm"); + } - [TestMethod] - public async Task BigTrees() - { - const int maxTests = 10; - const int minChildren = 0; - const int maxChildren = 20; - const double probability = 0.95; + [TestMethod] + public async Task BigTrees() + { + const int maxTests = 10; + const int minChildren = 0; + const int maxChildren = 20; + const double probability = 0.95; - await CreateAndVerifyTrees(maxTests, minChildren, maxChildren, probability, @".\big_trees.prm").ConfigureAwait(false); - } + await CreateAndVerifyTrees(maxTests, minChildren, maxChildren, probability, @".\big_trees.prm"); + } - private Element GenerateTree(int minimumChildren, int maximumChildren, double probability) - { - var root = new Element(); + private Element GenerateTree(int minimumChildren, int maximumChildren, double probability) + { + var root = new Element(); - GenerateTree(root, minimumChildren, maximumChildren, probability); + GenerateTree(root, minimumChildren, maximumChildren, probability); - return root; - } + return root; + } - private void GenerateTree(Element node, int minimumChildren, int maximumChildren, double probability, int level = 0) + private void GenerateTree(Element node, int minimumChildren, int maximumChildren, double probability, int level = 0) + { + if (random.NextDouble() < probability) { - if (random.NextDouble() < probability) + int numChildren = random.Next(maximumChildren - minimumChildren) + minimumChildren; + + for (int x = 0; x < numChildren; x++) { - int numChildren = random.Next(maximumChildren - minimumChildren) + minimumChildren; + var nodeGuid = Guid.NewGuid(); - for (int x = 0; x < numChildren; x++) + var child = new Element() { - var nodeGuid = Guid.NewGuid(); - - var child = new Element() - { - MetaData = Data.FromAsciiString(nodeGuid.ToString("N")), - Data = Data.FromUtf8String(string.Format("LEVEL: {0}, NODE: {1}", level, nodeGuid)) - }; + MetaData = Data.FromAsciiString(nodeGuid.ToString("N")), + Data = Data.FromUtf8String(string.Format("LEVEL: {0}, NODE: {1}", level, nodeGuid)) + }; - GenerateTree(child, minimumChildren, maximumChildren, probability * probability, level++); + GenerateTree(child, minimumChildren, maximumChildren, probability * probability, level++); - node.Add(child); - } + node.Add(child); } } + } - private async Task CreateAndVerifyTrees(int maxTests, int minChildren, int maxChildren, double probability, string fileName) + private async Task CreateAndVerifyTrees(int maxTests, int minChildren, int maxChildren, double probability, string fileName) + { + for (int x = 0; x < maxTests; x++) { - for (int x = 0; x < maxTests; x++) - { - Element originalTree = GenerateTree(minChildren, maxChildren, probability); - string originalTreeString = originalTree.TreeToString(); - await originalTree.SaveAsync(fileName).ConfigureAwait(false); + Element originalTree = GenerateTree(minChildren, maxChildren, probability); + string originalTreeString = originalTree.TreeToString(); + await originalTree.SaveAsync(fileName); + _ = originalTree.GetStatistics(); - Statistics stats = originalTree.GetStatistics(); + Assert.IsTrue(new FileInfo(fileName).Length > 0); - Assert.IsTrue(new FileInfo(fileName).Length > 0); + Element currentTree = await new Element().LoadAsync(fileName); + string currentTreeString = currentTree.TreeToString(); - Element currentTree = await new Element().LoadAsync(fileName).ConfigureAwait(false); - string currentTreeString = currentTree.TreeToString(); - - Assert.AreEqual(originalTreeString, currentTreeString); - } + Assert.AreEqual(originalTreeString, currentTreeString); } } } diff --git a/tests/UnitTests.cs b/tests/UnitTests.cs index 69b2f4f..9deb636 100644 --- a/tests/UnitTests.cs +++ b/tests/UnitTests.cs @@ -5,985 +5,980 @@ using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Promptuarium; +namespace Promptuarium.Tests; -namespace PromptuariumTests +/// +/// Unit tests for the Promptuarium tree +/// +[TestClass] +public class UnitTests { /// - /// Unit tests for the Promptuarium tree - /// - [TestClass] - public class UnitTests - { - /// - ///Gets or sets the test context which provides - ///information about and functionality for the current test run. - /// - public TestContext? TestContext { get; set; } - - private string TestFileName = CreateTestFileName(); - - #region Additional test attributes - // Use TestInitialize to run code before running each test - [TestInitialize()] - public void Initialize() - { - TestFileName = CreateTestFileName(); - } + ///Gets or sets the test context which provides + ///information about and functionality for the current test run. + /// + public TestContext? TestContext { get; set; } - // Use TestCleanup to run code after each test has run - [TestCleanup()] - public void MyTestCleanup() - { - } - #endregion + private string TestFileName = CreateTestFileName(); - [TestMethod] - public void ParameterlessConstructor() - { - var node = new Element(); + #region Additional test attributes + // Use TestInitialize to run code before running each test + [TestInitialize()] + public void Initialize() + { + TestFileName = CreateTestFileName(); + } - Assert.IsNull(node.Data); - Assert.IsNull(node.Data); - Assert.IsNull(node.MetaData); - Assert.IsNotNull(node.Children); - Assert.IsNull(node.Parent); - } + // Use TestCleanup to run code after each test has run + [TestCleanup()] + public void MyTestCleanup() + { + } + #endregion - [TestMethod] - public void CopyConstructor() - { - var tree = new Element(); - var child = new Element(); - var parent = new Element(); - - tree.Data = new MemoryStream(new byte[] { 2, 3, 5, 7, 11 }); - tree.Add(child); - tree.Parent = parent; - - Assert.AreEqual(2, tree.Data.ReadByte()); - Assert.AreEqual(3, tree.Data.ReadByte()); - Assert.AreEqual(5, tree.Data.ReadByte()); - Assert.AreEqual(7, tree.Data.ReadByte()); - Assert.AreEqual(11, tree.Data.ReadByte()); - - Assert.IsNotNull(tree.Children.FirstOrDefault(c => c == child)); - Assert.AreEqual(parent, tree.Parent); - } + [TestMethod] + public void ParameterlessConstructor() + { + var node = new Element(); - [TestMethod] - public void ComplexConstructor() - { - var child1 = new Element(); - var child2 = new Element(); - var parent = new Element(); - byte[] data = new byte[] { 2, 3, 5, 7, 11 }; - - var tree = new Element(null, new MemoryStream(data), child1, child2) - { - Parent = parent - }; - - Assert.AreEqual(2, tree.MetaData?.ReadByte()); - Assert.AreEqual(3, tree.MetaData?.ReadByte()); - Assert.AreEqual(5, tree.MetaData?.ReadByte()); - Assert.AreEqual(7, tree.MetaData?.ReadByte()); - Assert.AreEqual(11, tree.MetaData?.ReadByte()); - - Assert.IsNotNull(tree.Children.FirstOrDefault(c => c == child1)); - Assert.IsNotNull(tree.Children.FirstOrDefault(c => c == child2)); - Assert.AreEqual(parent, tree.Parent); - } + Assert.IsNull(node.Data); + Assert.IsNull(node.Data); + Assert.IsNull(node.MetaData); + Assert.IsNotNull(node.Children); + Assert.IsNull(node.Parent); + } - [TestMethod] - public void LinqFriendlyConstructor() - { - var child1 = new Element(); - var child2 = new Element(); - var parent = new Element(); - byte[] data = new byte[] { 2, 3, 5, 7, 11 }; - - var tree = new Element(new MemoryStream(data), new MemoryStream(data), - from child in new byte[] { 1, 1, 2, 3, 5, 8 } select new Element(new MemoryStream(new byte[] { child, child, child }), new MemoryStream(new byte[] { 5 })) - ) - { - Parent = parent - }; - - Assert.AreEqual(2, tree.Data?.ReadByte()); - Assert.AreEqual(3, tree.Data?.ReadByte()); - Assert.AreEqual(5, tree.Data?.ReadByte()); - Assert.AreEqual(7, tree.Data?.ReadByte()); - Assert.AreEqual(11, tree.Data?.ReadByte()); - - Assert.AreEqual(5, tree.Children.ToArray()[4].Data?.ReadByte()); - Assert.AreEqual(8, tree.Children.ToArray()[5].Data?.ReadByte()); - Assert.AreEqual(parent, tree.Parent); - } + [TestMethod] + public void CopyConstructor() + { + var tree = new Element(); + var child = new Element(); + var parent = new Element(); + + tree.Data = new MemoryStream([2, 3, 5, 7, 11]); + tree.Add(child); + tree.Parent = parent; + + Assert.AreEqual(2, tree.Data.ReadByte()); + Assert.AreEqual(3, tree.Data.ReadByte()); + Assert.AreEqual(5, tree.Data.ReadByte()); + Assert.AreEqual(7, tree.Data.ReadByte()); + Assert.AreEqual(11, tree.Data.ReadByte()); + + Assert.IsNotNull(tree.Children.FirstOrDefault(c => c == child)); + Assert.AreEqual(parent, tree.Parent); + } - [TestMethod] - [ExpectedException(typeof(PromptuariumException))] - public void Indexer() - { - var child1 = new Element(); - var child2 = new Element(); - var parent = new Element(); - byte[] data = new byte[] { 2, 3, 5, 7, 11 }; - - var tree = new Element(new MemoryStream(data), null, child1, child2) - { - Parent = parent - }; - - Assert.AreEqual(2, tree.Data?.ReadByte()); - Assert.AreEqual(3, tree.Data?.ReadByte()); - Assert.AreEqual(5, tree.Data?.ReadByte()); - Assert.AreEqual(7, tree.Data?.ReadByte()); - Assert.AreEqual(11, tree.Data?.ReadByte()); - - Assert.AreEqual(parent, tree.Parent); - Assert.AreEqual(child1, tree[0]); - Assert.AreEqual(child2, tree[1]); - Assert.AreEqual(child2, tree[2]); - } + [TestMethod] + public void ComplexConstructor() + { + var child1 = new Element(); + var child2 = new Element(); + var parent = new Element(); + byte[] data = [2, 3, 5, 7, 11]; - [TestMethod] - [ExpectedException(typeof(NullReferenceException))] - public void AddNullThrowsException() + var tree = new Element(null, new MemoryStream(data), child1, child2) { - new Element().Add(null!); - } + Parent = parent + }; - [TestMethod] - [ExpectedException(typeof(PromptuariumException))] - public void Add() - { - var child1 = new Element(new MemoryStream(new byte[] { 1 }), null); - var child2 = new Element(new MemoryStream(new byte[] { 2 }), null); - var child3 = new Element(new MemoryStream(new byte[] { 3 }), null); + Assert.AreEqual(2, tree.MetaData?.ReadByte()); + Assert.AreEqual(3, tree.MetaData?.ReadByte()); + Assert.AreEqual(5, tree.MetaData?.ReadByte()); + Assert.AreEqual(7, tree.MetaData?.ReadByte()); + Assert.AreEqual(11, tree.MetaData?.ReadByte()); - var tree = new Element(null, null); + Assert.IsNotNull(tree.Children.FirstOrDefault(c => c == child1)); + Assert.IsNotNull(tree.Children.FirstOrDefault(c => c == child2)); + Assert.AreEqual(parent, tree.Parent); + } - tree += child1; - tree.Add(child2, child3); + [TestMethod] + public void LinqFriendlyConstructor() + { + var child1 = new Element(); + var child2 = new Element(); + var parent = new Element(); + byte[] data = [2, 3, 5, 7, 11]; + + var tree = new Element(new MemoryStream(data), new MemoryStream(data), + from child in new byte[] { 1, 1, 2, 3, 5, 8 } select new Element(new MemoryStream([child, child, child]), new MemoryStream([5])) + ) + { + Parent = parent + }; + + Assert.AreEqual(2, tree.Data?.ReadByte()); + Assert.AreEqual(3, tree.Data?.ReadByte()); + Assert.AreEqual(5, tree.Data?.ReadByte()); + Assert.AreEqual(7, tree.Data?.ReadByte()); + Assert.AreEqual(11, tree.Data?.ReadByte()); + + Assert.AreEqual(5, tree.Children.ToArray()[4].Data?.ReadByte()); + Assert.AreEqual(8, tree.Children.ToArray()[5].Data?.ReadByte()); + Assert.AreEqual(parent, tree.Parent); + } - Assert.AreEqual(null, tree.Parent); - Assert.AreEqual(child1, tree[0]); - Assert.AreEqual(child2, tree[1]); - Assert.AreEqual(child3, tree[2]); + [TestMethod] + [ExpectedException(typeof(PromptuariumException))] + public void Indexer() + { + var child1 = new Element(); + var child2 = new Element(); + var parent = new Element(); + byte[] data = [2, 3, 5, 7, 11]; + + var tree = new Element(new MemoryStream(data), null, child1, child2) + { + Parent = parent + }; + + Assert.AreEqual(2, tree.Data?.ReadByte()); + Assert.AreEqual(3, tree.Data?.ReadByte()); + Assert.AreEqual(5, tree.Data?.ReadByte()); + Assert.AreEqual(7, tree.Data?.ReadByte()); + Assert.AreEqual(11, tree.Data?.ReadByte()); + + Assert.AreEqual(parent, tree.Parent); + Assert.AreEqual(child1, tree[0]); + Assert.AreEqual(child2, tree[1]); + Assert.AreEqual(child2, tree[2]); + } - Assert.AreEqual(3, tree.Children.Count); + [TestMethod] + [ExpectedException(typeof(NullReferenceException))] + public void AddNullThrowsException() + { + new Element().Add(null!); + } - // tree.Add(null); - // Assert.AreEqual(3, tree.Children.Count); + [TestMethod] + [ExpectedException(typeof(PromptuariumException))] + public void Add() + { + var child1 = new Element(new MemoryStream([1]), null); + var child2 = new Element(new MemoryStream([2]), null); + var child3 = new Element(new MemoryStream([3]), null); - tree.Add(child1); - Assert.AreEqual(3, tree.Children.Count); - } + var tree = new Element(null, null); - [TestMethod] - public void AddLinq() - { - var tree = new Element(null, null); + tree += child1; + tree.Add(child2, child3); - tree.Add( - new byte[] { 5, 9, 3, 6, 7 }.Select(n => new Element - ( - new MemoryStream(new[] { n }), new MemoryStream(new[] { n }), - new Element(new MemoryStream(new byte[] { 66 }), null) - )) - ); - - Assert.AreEqual(null, tree.Parent); - - Assert.AreEqual(5, tree[0].Data?.ReadByte()); - Assert.AreEqual(9, tree[1].Data?.ReadByte()); - Assert.AreEqual(7, tree[4].Data?.ReadByte()); - } + Assert.AreEqual(null, tree.Parent); + Assert.AreEqual(child1, tree[0]); + Assert.AreEqual(child2, tree[1]); + Assert.AreEqual(child3, tree[2]); - [TestMethod] - public void AddCollectionInitializer() - { - var tree = new Element() - { - new Element(new MemoryStream(new byte[] { 1 }), null), - new Element(new MemoryStream(new byte[] { 2 }), null), - new Element(new MemoryStream(new byte[] { 3 }), null) - }; - - Assert.AreEqual(null, tree.Parent); - Assert.AreEqual(3, tree.Children.Count); - } + Assert.AreEqual(3, tree.Children.Count); - [TestMethod] - public void CheckEnumerability() - { - var tree = new Element(null, null); + // tree.Add(null); + // Assert.AreEqual(3, tree.Children.Count); - tree.Add( - new byte[] { 5, 9, 3, 6, 7 }.Select(n => new Element - ( - new MemoryStream(new[] { n }), new MemoryStream(new[] { n }), - new Element(new MemoryStream(new byte[] { 66 }), null) - )) - ); - - Assert.AreEqual(null, tree.Parent); - - Assert.AreEqual(5, tree[0].Data?.ReadByte()); - Assert.AreEqual(9, tree[1].Data?.ReadByte()); - Assert.AreEqual(7, tree[4].Data?.ReadByte()); - - int i = 0; - foreach (var child in tree) - { - Assert.AreEqual(tree[i++], child); - } - } + tree.Add(child1); + Assert.AreEqual(3, tree.Children.Count); + } - [TestMethod] - public void Remove() + [TestMethod] + public void AddLinq() + { + var tree = new Element(null, null) { - var tree = CreateTestTree(); - var nodes = tree.GetStatistics().Nodes; + new byte[] { 5, 9, 3, 6, 7 }.Select(n => new Element + ( + new MemoryStream([n]), new MemoryStream([n]), + new Element(new MemoryStream([66]), null) + )) + }; - tree.Remove(tree[2]); - // tree.Remove(null); - tree -= tree[0]; + Assert.AreEqual(null, tree.Parent); - Assert.AreEqual(6, nodes - tree.GetStatistics().Nodes); - } + Assert.AreEqual(5, tree[0].Data?.ReadByte()); + Assert.AreEqual(9, tree[1].Data?.ReadByte()); + Assert.AreEqual(7, tree[4].Data?.ReadByte()); + } - [TestMethod] - public void Detach() + [TestMethod] + public void AddCollectionInitializer() + { + var tree = new Element() { - var tree = CreateTestTree(); - var reference = tree[1]; - - var child2 = tree[1].Detach(); + new Element(new MemoryStream([1]), null), + new Element(new MemoryStream([2]), null), + new Element(new MemoryStream([3]), null) + }; - Assert.AreEqual(reference, child2); - Assert.AreEqual(240, child2.MetaData?.ReadByte()); - Assert.AreEqual(3, tree.Children.Count); - } + Assert.AreEqual(null, tree.Parent); + Assert.AreEqual(3, tree.Children.Count); + } - [TestMethod] - public async Task Save() + [TestMethod] + public void CheckEnumerability() + { + var tree = new Element(null, null) { - var tree = CreateTestTree(); - using var stream = new MemoryStream(); + new byte[] { 5, 9, 3, 6, 7 }.Select(n => new Element + ( + new MemoryStream([n]), new MemoryStream([n]), + new Element(new MemoryStream([66]), null) + )) + }; - await tree.SaveAsync(stream).ConfigureAwait(false); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); + Assert.AreEqual(null, tree.Parent); - Assert.AreEqual(stream.Length, new FileInfo(TestFileName).Length); - } + Assert.AreEqual(5, tree[0].Data?.ReadByte()); + Assert.AreEqual(9, tree[1].Data?.ReadByte()); + Assert.AreEqual(7, tree[4].Data?.ReadByte()); - [TestMethod] - public async Task Load() + int i = 0; + foreach (var child in tree) { - byte[] data = new byte[] - { - 0x41, 0x80, - 0x42, 0x19, 0x78, 0x02, 0x19, 0x86, 0x21, 0xaa, - 0x65, 0x41, 0x42, 0x43, 0x44, 0x45, - 0x81, 0x13, - 0xc1, 0x55, - 0x00 - }; - - using var stream = new MemoryStream(data); - - var tree = await new Element().LoadAsync(stream).ConfigureAwait(false); - - Assert.AreEqual((byte)0x80, tree.Data?.AsByte()); - Assert.AreEqual((short)0x7819, tree[0].Data?.AsShort()); - Assert.AreEqual((uint)0x86197819, tree[0].Data?.AsUInt()); - Assert.AreEqual((uint)0x44434241, tree[0][0].MetaData?.AsUInt()); - Assert.AreEqual(true, tree[2].Data?.AsBool()); - Assert.IsNull(tree[2].MetaData); + Assert.AreEqual(tree[i++], child); } + } - [TestMethod] - public async Task TreeToStringTest() - { - var tree = CreateTestTree(); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); + [TestMethod] + public void Remove() + { + var tree = CreateTestTree(); + var nodes = tree.GetStatistics().Nodes; - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + tree.Remove(tree[2]); + // tree.Remove(null); + tree -= tree[0]; - string treeString = tree.TreeToString(); - string treeString2 = tree2.TreeToString(); + Assert.AreEqual(6, nodes - tree.GetStatistics().Nodes); + } - Assert.AreEqual(treeString2, treeString); - } + [TestMethod] + public void Detach() + { + var tree = CreateTestTree(); + var reference = tree[1]; - [TestMethod] - public async Task FromInt() - { - var tree = CreateTestTree(); + var child2 = tree[1].Detach(); - var subNode = new Element - { - Data = Data.FromInt(0x55aa00ff) - }; + Assert.AreEqual(reference, child2); + Assert.AreEqual(240, child2.MetaData?.ReadByte()); + Assert.AreEqual(3, tree.Children.Count); + } - tree.Add(subNode); + [TestMethod] + public async Task Save() + { + var tree = CreateTestTree(); + using var stream = new MemoryStream(); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + await tree.SaveAsync(stream); + await tree.SaveAsync(TestFileName); - Assert.AreEqual(0x55aa00ff, tree[tree.Children.Count - 1].Data?.AsInt()); - Assert.AreEqual(0x55aa00ff, tree2[tree2.Children.Count - 1].Data?.AsInt()); - } + Assert.AreEqual(stream.Length, new FileInfo(TestFileName).Length); + } - [TestMethod] - public async Task TreeToString() - { - var tree = CreateTestTree(); + [TestMethod] + public async Task Load() + { + byte[] data = + [ + 0x41, 0x80, + 0x42, 0x19, 0x78, 0x02, 0x19, 0x86, 0x21, 0xaa, + 0x65, 0x41, 0x42, 0x43, 0x44, 0x45, + 0x81, 0x13, + 0xc1, 0x55, + 0x00 + ]; + + using var stream = new MemoryStream(data); + + var tree = await new Element().LoadAsync(stream); + + Assert.AreEqual((byte)0x80, tree.Data?.AsByte()); + Assert.AreEqual((short)0x7819, tree[0].Data?.AsShort()); + Assert.AreEqual(0x86197819, tree[0].Data?.AsUInt()); + Assert.AreEqual((uint)0x44434241, tree[0][0].MetaData?.AsUInt()); + Assert.AreEqual(true, tree[2].Data?.AsBool()); + Assert.IsNull(tree[2].MetaData); + } + + [TestMethod] + public async Task TreeToStringTest() + { + var tree = CreateTestTree(); + await tree.SaveAsync(TestFileName); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + var tree2 = await new Element().LoadAsync(TestFileName); - string treeString = tree.TreeToString(); - string treeString2 = tree2.TreeToString(); + string treeString = tree.TreeToString(); + string treeString2 = tree2.TreeToString(); - Assert.AreEqual(treeString2, treeString); - } + Assert.AreEqual(treeString2, treeString); + } - [TestMethod] - public async Task Long() + [TestMethod] + public async Task FromInt() + { + var tree = CreateTestTree(); + + var subNode = new Element { - var tree = CreateTestTree(); + Data = Data.FromInt(0x55aa00ff) + }; + + tree.Add(subNode); - var numericNode = new Element - { - Data = Data.FromLong(0x55aa00ff19781986) - }; + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - tree[0].Add(numericNode); + Assert.AreEqual(0x55aa00ff, tree[tree.Children.Count - 1].Data?.AsInt()); + Assert.AreEqual(0x55aa00ff, tree2[tree2.Children.Count - 1].Data?.AsInt()); + } - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + [TestMethod] + public async Task TreeToString() + { + var tree = CreateTestTree(); - Assert.AreEqual(0x55aa00ff19781986, tree2[0][1].Data?.AsLong()); - } + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - [TestMethod] - public async Task Double() + string treeString = tree.TreeToString(); + string treeString2 = tree2.TreeToString(); + + Assert.AreEqual(treeString2, treeString); + } + + [TestMethod] + public async Task Long() + { + var tree = CreateTestTree(); + + var numericNode = new Element { - var tree = CreateTestTree(); + Data = Data.FromLong(0x55aa00ff19781986) + }; - var numericNode = new Element - { - MetaData = Data.FromDouble(3.14159265359) - }; + tree[0].Add(numericNode); - tree[0].Add(numericNode); + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + Assert.AreEqual(0x55aa00ff19781986, tree2[0][1].Data?.AsLong()); + } - double? value = tree2[0][1].MetaData?.AsDouble(); - Assert.IsTrue(value > 3.1415926 && value < 3.1415927); - } + [TestMethod] + public async Task Double() + { + var tree = CreateTestTree(); - [TestMethod] - public async Task GuidTest() + var numericNode = new Element { - Guid testGuid = Guid.NewGuid(); + MetaData = Data.FromDouble(3.14159265359) + }; - var tree = new Element(); + tree[0].Add(numericNode); - var guidNode = new Element - { - Data = Data.FromGuid(testGuid) - }; + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - tree.Add(guidNode); + double? value = tree2[0][1].MetaData?.AsDouble(); + Assert.IsTrue(value is > 3.1415926 and < 3.1415927); + } - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + [TestMethod] + public async Task GuidTest() + { + Guid testGuid = Guid.NewGuid(); - Assert.AreEqual(0, testGuid.CompareTo(tree2[0].Data?.AsGuid())); - } + var tree = new Element(); - [TestMethod] - public async Task Decimal() + var guidNode = new Element { - var tree = new Element(); + Data = Data.FromGuid(testGuid) + }; - var decimalNode = new Element - { - MetaData = Data.FromDecimal(1.978M) - }; + tree.Add(guidNode); - tree.Add(decimalNode); + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + Assert.AreEqual(0, testGuid.CompareTo(tree2[0].Data?.AsGuid())); + } - Assert.AreEqual(1.978M, tree2[0].MetaData?.AsDecimal()); - } + [TestMethod] + public async Task Decimal() + { + var tree = new Element(); - [TestMethod] - public async Task ByteArray() + var decimalNode = new Element { - byte[] testBytes = new byte[] { 1, 1, 2, 3, 5, 8, 13, 21 }; - - var tree = new Element(); + MetaData = Data.FromDecimal(1.978M) + }; - var byteArrayNode = new Element - { - Data = Data.FromByteArray(testBytes) - }; + tree.Add(decimalNode); - tree.Add(byteArrayNode); + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + Assert.AreEqual(1.978M, tree2[0].MetaData?.AsDecimal()); + } - byte[]? testBytes2 = tree2[0].Data?.AsByteArray(); + [TestMethod] + public async Task ByteArray() + { + byte[] testBytes = [1, 1, 2, 3, 5, 8, 13, 21]; - for (int i = 0; i < testBytes.Length; i++) - { - Assert.AreEqual(testBytes[i], testBytes2?[i]); - } - } + var tree = new Element(); - [TestMethod] - public async Task Unicode() + var byteArrayNode = new Element { - var tree = new Element(); + Data = Data.FromByteArray(testBytes) + }; - var unicodeNode = new Element - { - Data = Data.FromUtf32String("Hello, UTF-32LE world!"), - MetaData = Data.FromUtf16String("Hello, UTF-16LE world!") - }; + tree.Add(byteArrayNode); - tree.Add(unicodeNode); + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + byte[]? testBytes2 = tree2[0].Data?.AsByteArray(); - Assert.AreEqual("Hello, UTF-32LE world!", tree2[0].Data?.AsUtf32String()); - Assert.AreEqual("Hello, UTF-16LE world!", tree2[0].MetaData?.AsUtf16String()); + for (int i = 0; i < testBytes.Length; i++) + { + Assert.AreEqual(testBytes[i], testBytes2?[i]); } + } + + [TestMethod] + public async Task Unicode() + { + var tree = new Element(); - [TestMethod] - public async Task ElementTest() + var unicodeNode = new Element { - var outerTree = new Element(); - var innerTree = new Element(); + Data = Data.FromUtf32String("Hello, UTF-32LE world!"), + MetaData = Data.FromUtf16String("Hello, UTF-16LE world!") + }; - innerTree += new Element() { Data = Data.FromInt(0x55aa0044) }; - innerTree += new Element() { MetaData = Data.FromInt(0x55aa00ff) }; + tree.Add(unicodeNode); - outerTree.MetaData = Data.FromShort(1000); - outerTree.Data = await Data.FromElementAsync(innerTree).ConfigureAwait(false); + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - await outerTree.SaveAsync(TestFileName).ConfigureAwait(false); + Assert.AreEqual("Hello, UTF-32LE world!", tree2[0].Data?.AsUtf32String()); + Assert.AreEqual("Hello, UTF-16LE world!", tree2[0].MetaData?.AsUtf16String()); + } - var outerTree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); - var innerTree2 = await outerTree2.Data!.AsElementAsync().ConfigureAwait(false); + [TestMethod] + public async Task ElementTest() + { + var outerTree = new Element(); + var innerTree = new Element(); - Assert.AreEqual((short)1000, outerTree2.MetaData?.AsShort()); - Assert.AreEqual(0x55aa00ff, innerTree2[1].MetaData?.AsInt()); - } + innerTree += new Element() { Data = Data.FromInt(0x55aa0044) }; + innerTree += new Element() { MetaData = Data.FromInt(0x55aa00ff) }; - [TestMethod] - public async Task DateTimeTimeSpan() - { - var tree = new Element(); + outerTree.MetaData = Data.FromShort(1000); + outerTree.Data = await Data.FromElementAsync(innerTree); - var birthDay = new DateTime(1978, 10, 27, 8, 0, 0, 230); - var testTimeSpan = new TimeSpan(1978, 12, 27, 8, 239); + await outerTree.SaveAsync(TestFileName); - tree += new Element - { - Data = Data.FromDateTime(birthDay), - MetaData = Data.FromTimeSpan(testTimeSpan) - }; + var outerTree2 = await new Element().LoadAsync(TestFileName); + var innerTree2 = await outerTree2.Data!.AsElementAsync(); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + Assert.AreEqual((short)1000, outerTree2.MetaData?.AsShort()); + Assert.AreEqual(0x55aa00ff, innerTree2[1].MetaData?.AsInt()); + } - Assert.AreEqual(0, birthDay.CompareTo(tree2[0].Data?.AsDateTime())); - Assert.AreEqual(0, testTimeSpan.CompareTo(tree2[0].MetaData?.AsTimeSpan())); + [TestMethod] + public async Task DateTimeTimeSpan() + { + var tree = new Element(); - string treeString = tree.TreeToString(); - string tree2String = tree2.TreeToString(); - Assert.AreEqual(treeString, tree2String); - } + var birthDay = new DateTime(1978, 10, 27, 8, 0, 0, 230); + var testTimeSpan = new TimeSpan(1978, 12, 27, 8, 239); - [TestMethod] - public async Task DateTimeOffset() + tree += new Element { - var tree = new Element(); + Data = Data.FromDateTime(birthDay), + MetaData = Data.FromTimeSpan(testTimeSpan) + }; - var testTimeSpan = new TimeSpan(3, 0, 0); - var birthDay = new DateTimeOffset(1978, 10, 27, 8, 0, 0, 230, testTimeSpan); + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - tree += new Element - { - Data = Data.FromDateTimeOffset(birthDay), - }; + Assert.AreEqual(0, birthDay.CompareTo(tree2[0].Data?.AsDateTime())); + Assert.AreEqual(0, testTimeSpan.CompareTo(tree2[0].MetaData?.AsTimeSpan())); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + string treeString = tree.TreeToString(); + string tree2String = tree2.TreeToString(); + Assert.AreEqual(treeString, tree2String); + } - Assert.AreEqual(0, birthDay.CompareTo(tree2[0].Data?.AsDateTimeOffset() ?? throw new ArgumentNullException("Test failed."))); + [TestMethod] + public async Task DateTimeOffset() + { + var tree = new Element(); - string treeString = tree.TreeToString(); - string tree2String = tree2.TreeToString(); - Assert.AreEqual(treeString, tree2String); - } + var testTimeSpan = new TimeSpan(3, 0, 0); + var birthDay = new DateTimeOffset(1978, 10, 27, 8, 0, 0, 230, testTimeSpan); - [TestMethod] - public async Task Char() + tree += new Element { - var tree = new Element(); + Data = Data.FromDateTimeOffset(birthDay), + }; - var unicodeNode = new Element - { - Data = Data.FromChar('Ä'), - MetaData = Data.FromChar('Ő') - }; + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - tree.Add(unicodeNode); + Assert.AreEqual(0, birthDay.CompareTo(tree2[0].Data?.AsDateTimeOffset() ?? throw new ArgumentNullException("Test failed."))); - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); + string treeString = tree.TreeToString(); + string tree2String = tree2.TreeToString(); + Assert.AreEqual(treeString, tree2String); + } - Assert.AreEqual('Ä', tree2[0].Data?.AsChar()); - Assert.AreEqual('Ő', tree2[0].MetaData?.AsChar()); + [TestMethod] + public async Task Char() + { + var tree = new Element(); - string treeString = tree.TreeToString(); - string tree2String = tree2.TreeToString(); - Assert.AreEqual(treeString, tree2String); - } + var unicodeNode = new Element + { + Data = Data.FromChar('Ä'), + MetaData = Data.FromChar('Ő') + }; + + tree.Add(unicodeNode); + + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); - [TestMethod] - public async Task StringPerformance() + Assert.AreEqual('Ä', tree2[0].Data?.AsChar()); + Assert.AreEqual('Ő', tree2[0].MetaData?.AsChar()); + + string treeString = tree.TreeToString(); + string tree2String = tree2.TreeToString(); + Assert.AreEqual(treeString, tree2String); + } + + [TestMethod] + public async Task StringPerformance() + { + var tree = new Element(); + + for (int i = 0; i < 4000; ++i) { - var tree = new Element(); - - for (int i = 0; i < 4000; ++i) - { - tree.Add( - new Element - { - Data = Data.FromUtf8String("+36702815816") - } - ); - } - - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); - - Assert.AreEqual(tree.TreeToString(), tree2.TreeToString()); + tree.Add( + new Element + { + Data = Data.FromUtf8String("+36702815816") + } + ); } - [TestMethod] - public async Task IntPerformance() + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); + + Assert.AreEqual(tree.TreeToString(), tree2.TreeToString()); + } + + [TestMethod] + public async Task IntPerformance() + { + var tree = new Element(); + + for (int i = 0; i < 4000; ++i) { - var tree = new Element(); - - for (int i = 0; i < 4000; ++i) - { - tree.Add( - new Element - { - Data = Data.FromInt(367028158) - } - ); - } - - await tree.SaveAsync(TestFileName).ConfigureAwait(false); - var tree2 = await new Element().LoadAsync(TestFileName).ConfigureAwait(false); - Assert.AreEqual(tree.TreeToString(), tree2.TreeToString()); + tree.Add( + new Element + { + Data = Data.FromInt(367028158) + } + ); } - [TestMethod] - public async Task StreamCompatibility() - { - using var stream = new MemoryStream(); + await tree.SaveAsync(TestFileName); + var tree2 = await new Element().LoadAsync(TestFileName); + Assert.AreEqual(tree.TreeToString(), tree2.TreeToString()); + } - var treeA = new Element() { Data = Data.FromAsciiString("A") }; + [TestMethod] + public async Task StreamCompatibility() + { + using var stream = new MemoryStream(); - treeA.Add( - new Element { Data = Data.FromAsciiString("A1") }, - new Element { Data = Data.FromAsciiString("A2") } - ); + var treeA = new Element() { Data = Data.FromAsciiString("A") }; - var treeB = new Element() { Data = Data.FromAsciiString("B") }; + treeA.Add( + new Element { Data = Data.FromAsciiString("A1") }, + new Element { Data = Data.FromAsciiString("A2") } + ); - treeB.Add( - new Element { Data = Data.FromAsciiString("B1") }, - new Element { Data = Data.FromAsciiString("B2") } - ); + var treeB = new Element() { Data = Data.FromAsciiString("B") }; - await treeA.SaveAsync(stream).ConfigureAwait(false); - await treeB.SaveAsync(stream).ConfigureAwait(false); + treeB.Add( + new Element { Data = Data.FromAsciiString("B1") }, + new Element { Data = Data.FromAsciiString("B2") } + ); - stream.Position = 0; + await treeA.SaveAsync(stream); + await treeB.SaveAsync(stream); - var tree2A = await new Element().LoadAsync(stream).ConfigureAwait(false); - var tree2B = await new Element().LoadAsync(stream).ConfigureAwait(false); + stream.Position = 0; - string sTreeA = treeA.TreeToString(); - string sTreeB = treeB.TreeToString(); + var tree2A = await new Element().LoadAsync(stream); + var tree2B = await new Element().LoadAsync(stream); - string sTree2A = tree2A.TreeToString(); - string sTree2B = tree2B.TreeToString(); + string sTreeA = treeA.TreeToString(); + string sTreeB = treeB.TreeToString(); - Assert.AreEqual(sTreeA, sTree2A); - Assert.AreEqual(sTreeB, sTree2B); - } + string sTree2A = tree2A.TreeToString(); + string sTree2B = tree2B.TreeToString(); - [TestMethod] - public void VarInt100() - { - Stream stream = Data.FromVarInt(100); + Assert.AreEqual(sTreeA, sTree2A); + Assert.AreEqual(sTreeB, sTree2B); + } - stream.Position = 0; + [TestMethod] + public void VarInt100() + { + Stream stream = Data.FromVarInt(100); - byte[] buffer = new byte[sizeof(long)]; - stream.Read(buffer, 0, sizeof(long)); + stream.Position = 0; - Assert.AreEqual(1, stream.Length); - Assert.AreEqual(200, buffer[0]); - Assert.AreEqual(100, stream.AsVarInt()); - } + byte[] buffer = new byte[sizeof(long)]; + stream.Read(buffer, 0, sizeof(long)); - [TestMethod] - public void VarIntMinus100() - { - var stream = Data.FromVarInt(-100); + Assert.AreEqual(1, stream.Length); + Assert.AreEqual(200, buffer[0]); + Assert.AreEqual(100, stream.AsVarInt()); + } - stream.Position = 0; + [TestMethod] + public void VarIntMinus100() + { + var stream = Data.FromVarInt(-100); - var buffer = new byte[sizeof(long)]; - stream.Read(buffer, 0, sizeof(long)); + stream.Position = 0; - Assert.AreEqual(1, stream.Length); - Assert.AreEqual(201, buffer[0]); - Assert.AreEqual(-100, stream.AsVarInt()); - } + var buffer = new byte[sizeof(long)]; + stream.Read(buffer, 0, sizeof(long)); - [TestMethod] - public void VarInt65537() - { - var stream = Data.FromVarInt(65537); + Assert.AreEqual(1, stream.Length); + Assert.AreEqual(201, buffer[0]); + Assert.AreEqual(-100, stream.AsVarInt()); + } - stream.Position = 0; + [TestMethod] + public void VarInt65537() + { + var stream = Data.FromVarInt(65537); - var buffer = new byte[sizeof(long)]; - stream.Read(buffer, 0, sizeof(long)); + stream.Position = 0; - Assert.AreEqual(3, stream.Length); - Assert.AreEqual(2, buffer[2]); - Assert.AreEqual(0, buffer[1]); - Assert.AreEqual(2, buffer[0]); - Assert.AreEqual(65537, stream.AsVarInt()); - } + var buffer = new byte[sizeof(long)]; + stream.Read(buffer, 0, sizeof(long)); - [TestMethod] - public void VarIntMinus65537() - { - var stream = Data.FromVarInt(-65537); + Assert.AreEqual(3, stream.Length); + Assert.AreEqual(2, buffer[2]); + Assert.AreEqual(0, buffer[1]); + Assert.AreEqual(2, buffer[0]); + Assert.AreEqual(65537, stream.AsVarInt()); + } - stream.Position = 0; + [TestMethod] + public void VarIntMinus65537() + { + var stream = Data.FromVarInt(-65537); - var buffer = new byte[sizeof(long)]; - stream.Read(buffer, 0, sizeof(long)); + stream.Position = 0; - Assert.AreEqual(3, stream.Length); - Assert.AreEqual(2, buffer[2]); - Assert.AreEqual(0, buffer[1]); - Assert.AreEqual(3, buffer[0]); - Assert.AreEqual(-65537, stream.AsVarInt()); - } + var buffer = new byte[sizeof(long)]; + stream.Read(buffer, 0, sizeof(long)); - [TestMethod] - public void VarInt0() - { - var stream = Data.FromVarInt(0); + Assert.AreEqual(3, stream.Length); + Assert.AreEqual(2, buffer[2]); + Assert.AreEqual(0, buffer[1]); + Assert.AreEqual(3, buffer[0]); + Assert.AreEqual(-65537, stream.AsVarInt()); + } - stream.Position = 0; + [TestMethod] + public void VarInt0() + { + var stream = Data.FromVarInt(0); - var buffer = new byte[sizeof(long)]; - stream.Read(buffer, 0, sizeof(long)); + stream.Position = 0; - Assert.AreEqual(1, stream.Length); - Assert.AreEqual(0, buffer[0]); - Assert.AreEqual(0, stream.AsVarInt()); - } + var buffer = new byte[sizeof(long)]; + stream.Read(buffer, 0, sizeof(long)); - [TestMethod] - public void VarUInt100() - { - Stream stream = Data.FromVarInt(100); + Assert.AreEqual(1, stream.Length); + Assert.AreEqual(0, buffer[0]); + Assert.AreEqual(0, stream.AsVarInt()); + } - stream.Position = 0; + [TestMethod] + public void VarUInt100() + { + Stream stream = Data.FromVarInt(100); - byte[] buffer = new byte[sizeof(long)]; - stream.Read(buffer, 0, sizeof(long)); + stream.Position = 0; - Assert.AreEqual(1, stream.Length); - Assert.AreEqual(200, buffer[0]); - Assert.AreEqual(100, stream.AsVarInt()); - } + byte[] buffer = new byte[sizeof(long)]; + stream.Read(buffer, 0, sizeof(long)); - [TestMethod] - public void VarUInt65537() - { - var stream = Data.FromVarInt(65537); + Assert.AreEqual(1, stream.Length); + Assert.AreEqual(200, buffer[0]); + Assert.AreEqual(100, stream.AsVarInt()); + } - stream.Position = 0; + [TestMethod] + public void VarUInt65537() + { + var stream = Data.FromVarInt(65537); - var buffer = new byte[sizeof(long)]; - stream.Read(buffer, 0, sizeof(long)); + stream.Position = 0; - Assert.AreEqual(3, stream.Length); - Assert.AreEqual(2, buffer[2]); - Assert.AreEqual(0, buffer[1]); - Assert.AreEqual(2, buffer[0]); - Assert.AreEqual(65537, stream.AsVarInt()); - } + var buffer = new byte[sizeof(long)]; + stream.Read(buffer, 0, sizeof(long)); - [TestMethod] - public void VarUInt0() - { - var stream = Data.FromVarInt(0); + Assert.AreEqual(3, stream.Length); + Assert.AreEqual(2, buffer[2]); + Assert.AreEqual(0, buffer[1]); + Assert.AreEqual(2, buffer[0]); + Assert.AreEqual(65537, stream.AsVarInt()); + } - stream.Position = 0; + [TestMethod] + public void VarUInt0() + { + var stream = Data.FromVarInt(0); - var buffer = new byte[sizeof(long)]; - stream.Read(buffer, 0, sizeof(long)); + stream.Position = 0; - Assert.AreEqual(1, stream.Length); - Assert.AreEqual(0, buffer[0]); - Assert.AreEqual(0, stream.AsVarInt()); - } + var buffer = new byte[sizeof(long)]; + stream.Read(buffer, 0, sizeof(long)); - [TestMethod] - public async Task Base64EventExample() - { - var tree = new Element(Data.FromUtf8String("ROOT NODE"), Data.FromUtf8String("UTF-8 STRING"), - from i in new int[3] { 2, 3, 5 } - select new Element( - Data.FromDateTime(DateTime.Now), - Data.FromUtf8String("DATETIME.NOW()")) - ); - - tree.OnDataSaving += (s, _) => ((Element)s!).Data = Data.FromUtf8String("ROOT NODE MODIFIED"); - tree.OnDataSaved += (s, _) => ((Element)s!).Data = Data.FromUtf8String("ROOT NODE SAVED"); - - using var fs = new StreamWriter(TestFileName); - using var ms = new MemoryStream(); - await tree.SaveAsync(ms).ConfigureAwait(false); - fs.Write(Convert.ToBase64String(ms.AsByteArray())); - - Assert.AreEqual("ROOT NODE SAVED", tree.Data?.AsUtf8String()); - } + Assert.AreEqual(1, stream.Length); + Assert.AreEqual(0, buffer[0]); + Assert.AreEqual(0, stream.AsVarInt()); + } - [TestMethod] - public async Task Events() - { - // Extra null nodes are not added to the child list - var tree = new Element(Data.FromUtf8String("ROOT"), null, - new Element(Data.FromUtf8String("NODE1"), null), - new Element(Data.FromUtf8String("NODE2"), null), - new Element(Data.FromUtf8String("NODE3"), null) - ); + [TestMethod] + public async Task Base64EventExample() + { + var tree = new Element(Data.FromUtf8String("ROOT NODE"), Data.FromUtf8String("UTF-8 STRING"), + from i in new int[3] { 2, 3, 5 } + select new Element( + Data.FromDateTime(DateTime.Now), + Data.FromUtf8String("DATETIME.NOW()")) + ); + + tree.OnDataSaving += (s, _) => ((Element)s!).Data = Data.FromUtf8String("ROOT NODE MODIFIED"); + tree.OnDataSaved += (s, _) => ((Element)s!).Data = Data.FromUtf8String("ROOT NODE SAVED"); + + using var fs = new StreamWriter(TestFileName); + using var ms = new MemoryStream(); + await tree.SaveAsync(ms); + fs.Write(Convert.ToBase64String(ms.AsByteArray())); + + Assert.AreEqual("ROOT NODE SAVED", tree.Data?.AsUtf8String()); + } - int savingEventFired = 0; - int savedEventFired = 0; + [TestMethod] + public async Task Events() + { + // Extra null nodes are not added to the child list + var tree = new Element(Data.FromUtf8String("ROOT"), null, + new Element(Data.FromUtf8String("NODE1"), null), + new Element(Data.FromUtf8String("NODE2"), null), + new Element(Data.FromUtf8String("NODE3"), null) + ); - tree.OnDataSaving += (_, __) => savingEventFired++; - tree.OnDataSaved += (_, __) => savedEventFired++; + int savingEventFired = 0; + int savedEventFired = 0; - await tree.SaveAsync(TestFileName).ConfigureAwait(false); + tree.OnDataSaving += (_, __) => savingEventFired++; + tree.OnDataSaved += (_, __) => savedEventFired++; - var loadingNodes = new List(); - var loadedNodes = new List(); + await tree.SaveAsync(TestFileName); - var loaderElement = new Element(); - loaderElement.OnDataLoading += (s, _) => loadingNodes.Add(((Element)s!).Data!.AsUtf8String()); - loaderElement.OnDataLoaded += (s, _) => loadedNodes.Add(((Element)s!).Data!.AsUtf8String()); + var loadingNodes = new List(); + var loadedNodes = new List(); - var tree2 = await loaderElement.LoadAsync(TestFileName).ConfigureAwait(false); + var loaderElement = new Element(); + loaderElement.OnDataLoading += (s, _) => loadingNodes.Add(((Element)s!).Data!.AsUtf8String()); + loaderElement.OnDataLoaded += (s, _) => loadedNodes.Add(((Element)s!).Data!.AsUtf8String()); - Assert.AreEqual(1, savingEventFired); - Assert.AreEqual(1, savedEventFired); - Assert.AreEqual(4, loadingNodes.Count); - Assert.AreEqual(4, loadedNodes.Count); + var tree2 = await loaderElement.LoadAsync(TestFileName); - Assert.AreEqual("ROOT", loadedNodes[0]); - Assert.AreEqual("NODE1", loadedNodes[1]); - Assert.AreEqual("NODE2", loadedNodes[2]); - Assert.AreEqual("NODE3", loadedNodes[3]); + Assert.AreEqual(1, savingEventFired); + Assert.AreEqual(1, savedEventFired); + Assert.AreEqual(4, loadingNodes.Count); + Assert.AreEqual(4, loadedNodes.Count); - Assert.AreEqual(string.Empty, loadingNodes[0]); - Assert.AreEqual(string.Empty, loadingNodes[1]); - Assert.AreEqual(string.Empty, loadingNodes[2]); - Assert.AreEqual(string.Empty, loadingNodes[3]); - } + Assert.AreEqual("ROOT", loadedNodes[0]); + Assert.AreEqual("NODE1", loadedNodes[1]); + Assert.AreEqual("NODE2", loadedNodes[2]); + Assert.AreEqual("NODE3", loadedNodes[3]); - [TestMethod] - public async Task CleanupStream() - { - var tree = new Element() { MetaData = Data.FromAsciiString("root") }; - var child1 = new Element() { MetaData = Data.FromAsciiString("child1") }; - var child2 = new Element() { MetaData = Data.FromAsciiString("child2") }; - var child3 = new Element() { MetaData = Data.FromAsciiString("child3") }; + Assert.AreEqual(string.Empty, loadingNodes[0]); + Assert.AreEqual(string.Empty, loadingNodes[1]); + Assert.AreEqual(string.Empty, loadingNodes[2]); + Assert.AreEqual(string.Empty, loadingNodes[3]); + } - child2 += child3; - child1 += child2; - tree += child1; + [TestMethod] + public async Task CleanupStream() + { + var tree = new Element() { MetaData = Data.FromAsciiString("root") }; + var child1 = new Element() { MetaData = Data.FromAsciiString("child1") }; + var child2 = new Element() { MetaData = Data.FromAsciiString("child2") }; + var child3 = new Element() { MetaData = Data.FromAsciiString("child3") }; - using var ms = new MemoryStream(); - await tree.SaveAsync(ms).ConfigureAwait(false); + child2 += child3; + child1 += child2; + tree += child1; - Assert.AreEqual(27, ms.Length); - } + using var ms = new MemoryStream(); + await tree.SaveAsync(ms); - [TestMethod] - public async Task EmptyNode() - { - var tree = new Element(); + Assert.AreEqual(27, ms.Length); + } - await tree.SaveAsync(TestFileName).ConfigureAwait(false); + [TestMethod] + public async Task EmptyNode() + { + var tree = new Element(); - Assert.AreEqual(1, new FileInfo(TestFileName).Length); - } + await tree.SaveAsync(TestFileName); - [TestMethod] - public void Statistics() - { - var tree = new Element(Data.FromInt(0x0), null); + Assert.AreEqual(1, new FileInfo(TestFileName).Length); + } - var ch_A = new Element(Data.FromInt(0x100), null); - var ch_B = new Element(Data.FromInt(0x200), null); - var ch_C = new Element(Data.FromInt(0x300), null); + [TestMethod] + public void Statistics() + { + var tree = new Element(Data.FromInt(0x0), null); - tree.Add(ch_A, ch_B, ch_C); + var ch_A = new Element(Data.FromInt(0x100), null); + var ch_B = new Element(Data.FromInt(0x200), null); + var ch_C = new Element(Data.FromInt(0x300), null); - var ch_A_1 = new Element(Data.FromInt(0x110), null); - var ch_A_2 = new Element(Data.FromInt(0x120), null); + tree.Add(ch_A, ch_B, ch_C); - ch_A.Add(ch_A_1, ch_A_2); + var ch_A_1 = new Element(Data.FromInt(0x110), null); + var ch_A_2 = new Element(Data.FromInt(0x120), null); - var ch_C_1 = new Element(Data.FromInt(0x310), null); - var ch_C_2 = new Element(Data.FromInt(0x320), null); - var ch_C_3 = new Element(Data.FromInt(0x330), null); - var ch_C_4 = new Element(Data.FromInt(0x340), Data.FromAsciiString("123456789")); + ch_A.Add(ch_A_1, ch_A_2); - ch_C.Add(ch_C_1, ch_C_2, ch_C_3, ch_C_4); + var ch_C_1 = new Element(Data.FromInt(0x310), null); + var ch_C_2 = new Element(Data.FromInt(0x320), null); + var ch_C_3 = new Element(Data.FromInt(0x330), null); + var ch_C_4 = new Element(Data.FromInt(0x340), Data.FromAsciiString("123456789")); - var ch_C_3_I = new Element(Data.FromInt(0x331), null); + ch_C.Add(ch_C_1, ch_C_2, ch_C_3, ch_C_4); - ch_C_3.Add(ch_C_3_I); + var ch_C_3_I = new Element(Data.FromInt(0x331), null); - Statistics stats = tree.GetStatistics(); + ch_C_3.Add(ch_C_3_I); - Assert.AreEqual(4, stats.Depth); - Assert.AreEqual(11, stats.Nodes); - Assert.AreEqual(0, stats.MinChildren); - Assert.AreEqual(4, stats.MaxChildren); - Assert.AreEqual(4, stats.LongestData); - Assert.AreEqual(9, stats.LongestMetaData); - Assert.AreEqual(0, stats.ShortestData); - Assert.AreEqual(0, stats.ShortestMetaData); - Assert.AreEqual(10, stats.NodesWithData); - Assert.AreEqual(1, stats.NodesWithDataAndMetaData); - Assert.AreEqual(7, stats.NodesWithoutChildren); - } + Statistics stats = tree.GetStatistics(); - [TestMethod] - public async Task Base64Test() - { - var tree1 = new Element(Data.FromInt(0x0), null); + Assert.AreEqual(4, stats.Depth); + Assert.AreEqual(11, stats.Nodes); + Assert.AreEqual(0, stats.MinChildren); + Assert.AreEqual(4, stats.MaxChildren); + Assert.AreEqual(4, stats.LongestData); + Assert.AreEqual(9, stats.LongestMetaData); + Assert.AreEqual(0, stats.ShortestData); + Assert.AreEqual(0, stats.ShortestMetaData); + Assert.AreEqual(10, stats.NodesWithData); + Assert.AreEqual(1, stats.NodesWithDataAndMetaData); + Assert.AreEqual(7, stats.NodesWithoutChildren); + } - var ch_A = new Element(Data.FromInt(0x100), null); - var ch_B = new Element(Data.FromInt(0x200), null); - var ch_C = new Element(Data.FromInt(0x300), null); + [TestMethod] + public async Task Base64Test() + { + var tree1 = new Element(Data.FromInt(0x0), null); - tree1.Add(ch_A, ch_B, ch_C); + var ch_A = new Element(Data.FromInt(0x100), null); + var ch_B = new Element(Data.FromInt(0x200), null); + var ch_C = new Element(Data.FromInt(0x300), null); - var ch_A_1 = new Element(Data.FromInt(0x110), null); - var ch_A_2 = new Element(Data.FromInt(0x120), null); + tree1.Add(ch_A, ch_B, ch_C); - ch_A.Add(ch_A_1, ch_A_2); + var ch_A_1 = new Element(Data.FromInt(0x110), null); + var ch_A_2 = new Element(Data.FromInt(0x120), null); - var ch_C_1 = new Element(Data.FromInt(0x310), null); - var ch_C_2 = new Element(Data.FromInt(0x320), null); - var ch_C_3 = new Element(Data.FromInt(0x330), null); - var ch_C_4 = new Element(Data.FromInt(0x340), Data.FromAsciiString("123456789")); + ch_A.Add(ch_A_1, ch_A_2); - ch_C.Add(ch_C_1, ch_C_2, ch_C_3, ch_C_4); + var ch_C_1 = new Element(Data.FromInt(0x310), null); + var ch_C_2 = new Element(Data.FromInt(0x320), null); + var ch_C_3 = new Element(Data.FromInt(0x330), null); + var ch_C_4 = new Element(Data.FromInt(0x340), Data.FromAsciiString("123456789")); - var ch_C_3_I = new Element(Data.FromInt(0x331), null); + ch_C.Add(ch_C_1, ch_C_2, ch_C_3, ch_C_4); - ch_C_3.Add(ch_C_3_I); + var ch_C_3_I = new Element(Data.FromInt(0x331), null); - string base64String = await tree1.ToBase64StringAsync().ConfigureAwait(false); + ch_C_3.Add(ch_C_3_I); - var tree2 = await Element.FromBase64StringAsync(base64String).ConfigureAwait(false); + string base64String = await tree1.ToBase64StringAsync(); - Assert.AreEqual(tree1.TreeToString(), tree2.TreeToString()); - } + var tree2 = await Element.FromBase64StringAsync(base64String); - #region Private methods - private static Element CreateTestTree() - { - byte[] longData = new byte[150]; - byte[] veryLongData = new byte[7 * 512 * 1024 + 5 * 16 + 2]; - - longData[0] = 0xf0; - veryLongData[0] = 0xf1; - veryLongData[10] = 0xf2; - - var node = new Element - ( - new MemoryStream(new byte[] { 128, 96 }), null, - - new Element(null, new MemoryStream(new byte[] { 5, 6 })), - new Element(null, new MemoryStream(longData)), - new Element(null, new MemoryStream(new byte[] { 8, 8 }), - new Element(new MemoryStream(longData), null, - new Element(new MemoryStream(new byte[] { 18, 28 }), null, - new Element(new MemoryStream(new byte[] { 1, 7 }), null) - ) - ) - ), - - new Element - { - Data = Data.FromUtf8String("Hello World"), - MetaData = Data.FromGuid(Guid.NewGuid()) - } - ); - - node[0].Add(new Element( - new MemoryStream(veryLongData), - new MemoryStream(longData)) - ); + Assert.AreEqual(tree1.TreeToString(), tree2.TreeToString()); + } - return node; - } + #region Private methods + private static Element CreateTestTree() + { + byte[] longData = new byte[150]; + byte[] veryLongData = new byte[(7 * 512 * 1024) + (5 * 16) + 2]; + + longData[0] = 0xf0; + veryLongData[0] = 0xf1; + veryLongData[10] = 0xf2; + + var node = new Element + ( + new MemoryStream([128, 96]), null, + + new Element(null, new MemoryStream([5, 6])), + new Element(null, new MemoryStream(longData)), + new Element(null, new MemoryStream([8, 8]), + new Element(new MemoryStream(longData), null, + new Element(new MemoryStream([18, 28]), null, + new Element(new MemoryStream([1, 7]), null) + ) + ) + ), + + new Element + { + Data = Data.FromUtf8String("Hello World"), + MetaData = Data.FromGuid(Guid.NewGuid()) + } + ); + + node[0].Add(new Element( + new MemoryStream(veryLongData), + new MemoryStream(longData)) + ); + + return node; + } - private static string CreateTestFileName() + private static string CreateTestFileName() + { + if (!Directory.Exists("test-data")) { - if (!Directory.Exists("test-data")) - { - Directory.CreateDirectory("test-data"); - } - - return $"test-data{Path.DirectorySeparatorChar}{Guid.NewGuid()}.prm"; + Directory.CreateDirectory("test-data"); } - #endregion + + return $"test-data{Path.DirectorySeparatorChar}{Guid.NewGuid()}.prm"; } + #endregion } diff --git a/tools/Dump/Dump.csproj b/tools/Dump/Dump.csproj index 2a7b716..f73f452 100644 --- a/tools/Dump/Dump.csproj +++ b/tools/Dump/Dump.csproj @@ -7,7 +7,7 @@ Exe - net6 + net8.0 dump true diff --git a/tools/Dump/GlobalSuppressions.cs b/tools/Dump/GlobalSuppressions.cs new file mode 100644 index 0000000..9a4d27d --- /dev/null +++ b/tools/Dump/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Style", "IDE0008:Use explicit type", Justification = "Reviewed.")] diff --git a/tools/Dump/Program.cs b/tools/Dump/Program.cs index fb8e291..638626f 100644 --- a/tools/Dump/Program.cs +++ b/tools/Dump/Program.cs @@ -1,33 +1,23 @@ using System; -using System.Threading.Tasks; using Promptuarium; -namespace Dump +if (args.Length != 1) { - internal static class Program - { - private static async Task Main(string[] args) - { - if (args.Length != 1) - { - Console.WriteLine("Usage: dump.exe "); - Environment.Exit(-1); - } + Console.WriteLine("Usage: dump.exe "); + Environment.Exit(-1); +} - try - { - var container = await Element.LoadAsync(args[0]).ConfigureAwait(false); +try +{ + var container = await Element.LoadAsync(args[0]); - Console.WriteLine(container.TreeToString("-> ")); - Console.WriteLine(container.Statistics); - } - catch (Exception ex) - { - var originalColor = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"Exception has been thrown during execution:\n{ex.Message}\n{ex.InnerException?.Message}"); - Console.ForegroundColor = originalColor; - } - } - } + Console.WriteLine(container.TreeToString("-> ")); + Console.WriteLine(container.Statistics); +} +catch (Exception ex) +{ + var originalColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"Exception has been thrown during execution:\n{ex.Message}\n{ex.InnerException?.Message}"); + Console.ForegroundColor = originalColor; } From 1c3135a1cf6afd4149ef73c962c35bd4b4d783fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fuszenecker=20R=C3=B3bert?= Date: Fri, 14 Jun 2024 21:38:02 +0200 Subject: [PATCH 4/5] Build fix. --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index fa1d7c4..76cd182 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.x + dotnet-version: 8.x - name: Restore dependencies run: dotnet restore - name: Build From 803b1d7c9ebb8d39f24fca16f1a05741bea6d900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fuszenecker=20R=C3=B3bert?= Date: Fri, 14 Jun 2024 21:49:36 +0200 Subject: [PATCH 5/5] Small updates. --- src/ElementStatistics.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ElementStatistics.cs b/src/ElementStatistics.cs index 342e904..e6e68f6 100644 --- a/src/ElementStatistics.cs +++ b/src/ElementStatistics.cs @@ -22,52 +22,52 @@ public class Statistics /// /// The number of nodes in the tree /// - public int Nodes; + public int Nodes { get; set; } /// /// The number of nodes with data /// - public int NodesWithData; + public int NodesWithData { get; set; } /// /// The number of nodes with metadata /// - public int NodesWithMetaData; + public int NodesWithMetaData { get; set; } /// /// The number of nodes with data and metadata /// - public int NodesWithDataAndMetaData; + public int NodesWithDataAndMetaData { get; set; } /// /// The number of nodes without data and metadata /// - public int NodesWithoutDataAndMetaData; + public int NodesWithoutDataAndMetaData { get; set; } /// /// The number of nodes without children /// - public int NodesWithoutChildren; + public int NodesWithoutChildren { get; set; } /// /// The depth of the tree /// - public int Depth; + public int Depth { get; set; } /// /// The maximum number of children of a node /// - public int MaxChildren; + public int MaxChildren { get; set; } /// /// The minimum number of children of a node /// - public int MinChildren; + public int MinChildren { get; set; } /// /// The longest data in the tree /// - public long LongestData; + public long LongestData { get; set; } /// /// The longest metadata in the tree @@ -77,12 +77,12 @@ public class Statistics /// /// The shortest data in the tree /// - public long ShortestData; + public long ShortestData { get; set; } /// /// The shortest metadata in the tree /// - public long ShortestMetaData; + public long ShortestMetaData { get; set; } /// /// Returns a string that represents the current object.