From 50cea48ea4b6cf6b94ee7c303dcab5670d2b327b Mon Sep 17 00:00:00 2001 From: Lilith River Date: Wed, 31 Jan 2024 15:12:17 -0700 Subject: [PATCH 01/11] Add PolySharp and change LangVersion=latest --- src/Tomlyn/Tomlyn.props | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Tomlyn/Tomlyn.props b/src/Tomlyn/Tomlyn.props index ec129d2..1d82582 100644 --- a/src/Tomlyn/Tomlyn.props +++ b/src/Tomlyn/Tomlyn.props @@ -2,7 +2,7 @@ netstandard2.0;net7.0 - 10.0 + latest Tomlyn is a TOML parser, validator and authoring library for .NET. Alexandre Mutel Alexandre Mutel @@ -21,6 +21,12 @@ true true snupkg + + true + + + + @@ -35,6 +41,12 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From 012208e4725a62b955fe9e1cbd69b232366decb9 Mon Sep 17 00:00:00 2001 From: Lilith River Date: Wed, 31 Jan 2024 17:21:06 -0700 Subject: [PATCH 02/11] Target .NET 6 & 8; Test net48, 6, and 8. Test ubuntu --- .github/workflows/ci.yml | 10 ++++++---- src/Tomlyn.Tests/AssertHelper.cs | 11 ++++++++++- src/Tomlyn.Tests/Tomlyn.Tests.csproj | 14 +++++++++++++- src/Tomlyn/Tomlyn.csproj | 1 + src/Tomlyn/Tomlyn.props | 2 +- src/global.json | 10 +++++----- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab394d5..f9b4068 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ on: jobs: build: - runs-on: windows-latest + runs-on: [windows-latest, ubuntu-latest] steps: - name: Checkout @@ -20,10 +20,12 @@ jobs: submodules: true fetch-depth: 0 - - name: Install .NET 7.0 - uses: actions/setup-dotnet@v3 + - name: Install .NET 6 & 8 + uses: actions/setup-dotnet@v4 with: - dotnet-version: '7.0.x' + dotnet-version: | + 6 + 8. - name: Build, Test, Pack, Publish shell: bash diff --git a/src/Tomlyn.Tests/AssertHelper.cs b/src/Tomlyn.Tests/AssertHelper.cs index 9a47806..1999633 100644 --- a/src/Tomlyn.Tests/AssertHelper.cs +++ b/src/Tomlyn.Tests/AssertHelper.cs @@ -1,5 +1,5 @@ // Copyright (c) Alexandre Mutel. All rights reserved. -// Licensed under the BSD-Clause 2 license. +// Licensed under the BSD-Clause 2 license. // See license.txt file in the project root for full license information. using System; @@ -27,5 +27,14 @@ public static string NormalizeEndOfLine(string text) { return text.Replace("\r\n", "\n"); } + + #if NET5_0_OR_GREATER + #else + public static string ReplaceLineEndings(this string text, string? newLine = null) + { + newLine ??= Environment.NewLine; + return text.Replace("\r\n", "\n").Replace("\n", newLine); + } + #endif } } \ No newline at end of file diff --git a/src/Tomlyn.Tests/Tomlyn.Tests.csproj b/src/Tomlyn.Tests/Tomlyn.Tests.csproj index db21535..efbcb03 100644 --- a/src/Tomlyn.Tests/Tomlyn.Tests.csproj +++ b/src/Tomlyn.Tests/Tomlyn.Tests.csproj @@ -1,9 +1,14 @@ - net7.0 + net6.0;net8.0;net48 + net6.0;net8.0 + + + false enable + latest @@ -11,6 +16,13 @@ + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/Tomlyn/Tomlyn.csproj b/src/Tomlyn/Tomlyn.csproj index e1f5e32..4e68be5 100644 --- a/src/Tomlyn/Tomlyn.csproj +++ b/src/Tomlyn/Tomlyn.csproj @@ -2,6 +2,7 @@ Tomlyn + netstandard2.0;net6.0;net8.0 diff --git a/src/Tomlyn/Tomlyn.props b/src/Tomlyn/Tomlyn.props index 1d82582..b866f52 100644 --- a/src/Tomlyn/Tomlyn.props +++ b/src/Tomlyn/Tomlyn.props @@ -1,7 +1,7 @@ - netstandard2.0;net7.0 + latest Tomlyn is a TOML parser, validator and authoring library for .NET. Alexandre Mutel diff --git a/src/global.json b/src/global.json index aaf58f5..2ddda36 100644 --- a/src/global.json +++ b/src/global.json @@ -1,7 +1,7 @@ { - "sdk": { - "version": "7.0.100", - "rollForward": "latestMinor", - "allowPrerelease": false - } + "sdk": { + "version": "8.0.0", + "rollForward": "latestMinor", + "allowPrerelease": false + } } \ No newline at end of file From bb6cfa802f7f72b36e8f191b3124c2778fe4f76c Mon Sep 17 00:00:00 2001 From: Lilith River Date: Wed, 31 Jan 2024 18:36:33 -0700 Subject: [PATCH 03/11] Don't test DateOnly/TimeOnly on netstandard2 --- src/Tomlyn.Tests/ModelTests/ReflectionModelTests.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Tomlyn.Tests/ModelTests/ReflectionModelTests.cs b/src/Tomlyn.Tests/ModelTests/ReflectionModelTests.cs index 6d41a2a..0a11d4d 100644 --- a/src/Tomlyn.Tests/ModelTests/ReflectionModelTests.cs +++ b/src/Tomlyn.Tests/ModelTests/ReflectionModelTests.cs @@ -94,8 +94,10 @@ public void TestPrimitives() Float64Value = 2.5, DateTime = new DateTime(1970, 1, 1), DateTimeOffset = new DateTimeOffset(1980, 1, 1, 0, 23, 1, TimeSpan.FromHours(-2)), +#if NET6_0_OR_GREATER DateOnly = new DateOnly(1970, 5, 27), TimeOnly = new TimeOnly(7, 32, 0, 999), +#endif TomlDateTime = new TomlDateTime(new DateTimeOffset(new DateTime(1990, 11, 15)), 0, TomlDateTimeKind.LocalDateTime) }; @@ -149,8 +151,10 @@ public void TestPrimitiveFields() Float64Value = 2.5, DateTime = new DateTime(1970, 1, 1), DateTimeOffset = new DateTimeOffset(1980, 1, 1, 0, 23, 1, TimeSpan.FromHours(-2)), +#if NET6_0_OR_GREATER DateOnly = new DateOnly(1970, 5, 27), TimeOnly = new TimeOnly(7, 32, 0, 999), +#endif TomlDateTime = new TomlDateTime(new DateTimeOffset(new DateTime(1990, 11, 15)), 0, TomlDateTimeKind.LocalDateTime) }; @@ -207,8 +211,10 @@ public void TestNullableValueTypes() Float64Value = 2.5, DateTime = new DateTime(1970, 1, 1), DateTimeOffset = new DateTimeOffset(1980, 1, 1, 0, 23, 1, TimeSpan.FromHours(-2)), +#if NET6_0_OR_GREATER DateOnly = new DateOnly(1970, 5, 27), TimeOnly = new TimeOnly(7, 32, 0, 999), +#endif TomlDateTime = new TomlDateTime(new DateTimeOffset(new DateTime(1990, 11, 15)), 0, TomlDateTimeKind.LocalDateTime) }; @@ -280,8 +286,10 @@ public void TestNullableValueTypeFields() Float64Value = 2.5, DateTime = new DateTime(1970, 1, 1), DateTimeOffset = new DateTimeOffset(1980, 1, 1, 0, 23, 1, TimeSpan.FromHours(-2)), +#if NET6_0_OR_GREATER DateOnly = new DateOnly(1970, 5, 27), TimeOnly = new TimeOnly(7, 32, 0, 999), +#endif TomlDateTime = new TomlDateTime(new DateTimeOffset(new DateTime(1990, 11, 15)), 0, TomlDateTimeKind.LocalDateTime) }; From 97f7877fdf224dec6219a1807d8f1bebe3b75602 Mon Sep 17 00:00:00 2001 From: Lilith River Date: Wed, 31 Jan 2024 18:42:44 -0700 Subject: [PATCH 04/11] Fix nullability warning --- src/Tomlyn/Model/ModelToTomlTransform.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Tomlyn/Model/ModelToTomlTransform.cs b/src/Tomlyn/Model/ModelToTomlTransform.cs index 1f0df06..c3eb10f 100644 --- a/src/Tomlyn/Model/ModelToTomlTransform.cs +++ b/src/Tomlyn/Model/ModelToTomlTransform.cs @@ -104,7 +104,7 @@ private void WriteKey(string name) private string EscapeKey(string name) { if (string.IsNullOrWhiteSpace(name)) return $"\"{name.EscapeForToml()}\""; - + // A-Za-z0-9_- foreach (var c in name) { @@ -200,8 +200,8 @@ private bool VisitObject(ObjectDynamicAccessor accessor, object currentObject, b } // Sort primitive first - properties = properties.OrderBy(_ => _, - Comparer>.Create((left, right) => + properties = properties.OrderBy(p => p, + Comparer>.Create((left, right) => { var leftValue = left.Value; var rightValue = right.Value; From aa330e924c8471dadb0667a605a0adf7440b2f47 Mon Sep 17 00:00:00 2001 From: Lilith River Date: Wed, 31 Jan 2024 18:42:44 -0700 Subject: [PATCH 05/11] Fix nullability warning --- src/Tomlyn/Model/ModelToTomlTransform.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Tomlyn/Model/ModelToTomlTransform.cs b/src/Tomlyn/Model/ModelToTomlTransform.cs index c3eb10f..b9b0e82 100644 --- a/src/Tomlyn/Model/ModelToTomlTransform.cs +++ b/src/Tomlyn/Model/ModelToTomlTransform.cs @@ -174,7 +174,6 @@ private bool VisitObject(ObjectDynamicAccessor accessor, object currentObject, b try { - // Pre-convert values to TOML values var convertToToml = _context.ConvertToToml; if (convertToToml != null) From 62dfed10b5a3e8d9b47a9873ae3178956482f687 Mon Sep 17 00:00:00 2001 From: Lilith River Date: Wed, 31 Jan 2024 18:50:39 -0700 Subject: [PATCH 06/11] CI: 2 separate runs, not one runner that is both windows and ubuntu --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9b4068..0f1ba8d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,8 +11,9 @@ on: jobs: build: - runs-on: [windows-latest, ubuntu-latest] - + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] steps: - name: Checkout uses: actions/checkout@v3 From efee546bbcdfbe65a852de36a147b2b10fb82a0d Mon Sep 17 00:00:00 2001 From: Lilith River Date: Wed, 31 Jan 2024 18:53:33 -0700 Subject: [PATCH 07/11] CI: Specify the runs-on attribute --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f1ba8d..1e396c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest, windows-latest ] + runs-on: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v3 From ed51a532ea91c445e3da4104028e9d114ef40d7f Mon Sep 17 00:00:00 2001 From: Lilith River Date: Wed, 31 Jan 2024 20:23:01 -0700 Subject: [PATCH 08/11] CI: fix trailing 8. on dotnet-version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e396c7..c424876 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: with: dotnet-version: | 6 - 8. + 8 - name: Build, Test, Pack, Publish shell: bash From 8b13d0d845dfaf074fa2c3182334523f606558d3 Mon Sep 17 00:00:00 2001 From: Lilith River Date: Wed, 31 Jan 2024 20:35:02 -0700 Subject: [PATCH 09/11] Add TargetFrameworks to Tomlyn.Signed.csproj (having it in .props caused issues) --- src/Tomlyn.Signed/Tomlyn.Signed.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tomlyn.Signed/Tomlyn.Signed.csproj b/src/Tomlyn.Signed/Tomlyn.Signed.csproj index eb9fbe7..ebad399 100644 --- a/src/Tomlyn.Signed/Tomlyn.Signed.csproj +++ b/src/Tomlyn.Signed/Tomlyn.Signed.csproj @@ -4,6 +4,7 @@ Tomlyn.Signed key.snk true + netstandard2.0;net6.0;net8.0 From 026f953e5f3647f0ec83d3ad3fd2fab406261bad Mon Sep 17 00:00:00 2001 From: Lilith River Date: Wed, 31 Jan 2024 21:44:37 -0700 Subject: [PATCH 10/11] Create FloatingRoundtripTests.cs to systematically approach float serialization tradeoffs. --- src/Tomlyn.Tests/FloatingRoundtripTests.cs | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/Tomlyn.Tests/FloatingRoundtripTests.cs diff --git a/src/Tomlyn.Tests/FloatingRoundtripTests.cs b/src/Tomlyn.Tests/FloatingRoundtripTests.cs new file mode 100644 index 0000000..e06d7a3 --- /dev/null +++ b/src/Tomlyn.Tests/FloatingRoundtripTests.cs @@ -0,0 +1,90 @@ +// Copyright (c) Alexandre Mutel. All rights reserved. +// Licensed under the BSD-Clause 2 license. +// See license.txt file in the project root for full license information. + +using NUnit.Framework; +using Tomlyn.Model; + +namespace Tomlyn.Tests +{ + [TestFixture] + public class FloatingRoundtripTests{ + + + [TestCase(0.0)] + [TestCase(-0.0)] + [TestCase(1.0)] + [TestCase(-1.0)] + [TestCase(double.PositiveInfinity)] + [TestCase(double.NegativeInfinity)] + [TestCase(double.NaN)] +#if NET8_0_OR_GREATER + [TestCase(double.NegativeZero)] +#endif + [TestCase(double.Epsilon)] + [TestCase(-double.Epsilon)] + // [TestCase(0.1)] - - These fail. Adjusting g16->g17 fixes some but not all. + // [TestCase(0.99)] + // [TestCase(0.3)] + // [TestCase(double.MinValue)] + // [TestCase(double.MaxValue)] + public void TestDoublesRoundtrip(double number) + { + // we want to increment f64 by the smallest possible value + // and verify it changes the serialized value + // IEEE 754 compliance means -0.0 and +0.0 are different + // special values +inf=inf, -inf, nan=+nan, -nan + var model = new TomlTable + { + ["float"] = (float)number, + ["double"] = number + }; + var toml = Toml.FromModel(model); + var parsed = Toml.Parse(toml); + var parsedDouble = (double)parsed.ToModel()["double"]; + var parsedFloat = (double)parsed.ToModel()["float"]; + Assert.True(number == parsedDouble || double.IsNaN(number), + $"(f64->str->f64) expected {number:g30} but got {parsedDouble:g30}. \nString form: \n{toml}"); + Assert.AreEqual(number, parsedDouble); + Assert.True((float)number == parsedFloat || double.IsNaN(number), + $"(f64->f32->str->f64->f32) expected {(float)number:g30} but got {parsedFloat:g30}. \nString form: \n{toml}"); + Assert.AreEqual((float)number, parsedFloat); + } + + [TestCase(0.0f)] + [TestCase(-0.0f)] + [TestCase(1.0f)] + [TestCase(-1.0f)] + [TestCase(float.PositiveInfinity)] + [TestCase(float.NegativeInfinity)] + [TestCase(float.NaN)] +#if NET8_0_OR_GREATER + [TestCase(float.NegativeZero)] +#endif + [TestCase(float.Epsilon)] + [TestCase(-float.Epsilon)] + // [TestCase(0.1f)] - These fail. Adjusting g16->g17 fixes them + // [TestCase(0.99f)] + // [TestCase(0.3f)] + // [TestCase(float.MinValue)] + // [TestCase(float.MaxValue)] + public void TestFloatsRoundtrip(float number) + { + var model = new TomlTable + { + ["float"] = number, + ["double"] = (double)number + }; + var toml = Toml.FromModel(model); + + var parsed = Toml.Parse(toml); + var parsedDouble = (double)parsed.ToModel()["double"]; + var parsedFloatAsDouble = (double)parsed.ToModel()["float"]; + Assert.True((double)number == parsedDouble || double.IsNaN(number), + $"(f32->f64->str->f64) expected double {(double)number:g64} but got double {parsedDouble:g64}. \nString form: \n{toml}"); + Assert.True(number == (float)parsedFloatAsDouble || double.IsNaN(number), + $"(f32->str->f64->f32) expected float {number:g64} but got float {(float)parsedFloatAsDouble:g64}. \nString form: \n{toml}"); + + } + } +} \ No newline at end of file From a080205e7a18a60375d02e127e5ea1044dad635b Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Thu, 1 Feb 2024 06:20:05 +0100 Subject: [PATCH 11/11] Update src/Tomlyn.Tests/AssertHelper.cs --- src/Tomlyn.Tests/AssertHelper.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Tomlyn.Tests/AssertHelper.cs b/src/Tomlyn.Tests/AssertHelper.cs index 1999633..ad0b6ab 100644 --- a/src/Tomlyn.Tests/AssertHelper.cs +++ b/src/Tomlyn.Tests/AssertHelper.cs @@ -28,8 +28,7 @@ public static string NormalizeEndOfLine(string text) return text.Replace("\r\n", "\n"); } - #if NET5_0_OR_GREATER - #else + #if !NET5_0_OR_GREATER public static string ReplaceLineEndings(this string text, string? newLine = null) { newLine ??= Environment.NewLine;