From 0a21f54dafecae9625b74b7fa0195b17e9a6b0a2 Mon Sep 17 00:00:00 2001 From: Simon Zhao <42222408+simonz-bq@users.noreply.github.com> Date: Thu, 12 Mar 2020 10:57:04 -0700 Subject: [PATCH] Fixes negative zero decimals. (#83) --- Amazon.IonDotnet.Tests/Amazon.IonDotnet.Tests.csproj | 4 ++-- Amazon.IonDotnet.Tests/Internals/BigDecimalTest.cs | 3 +++ Amazon.IonDotnet/BigDecimal.cs | 3 +-- Amazon.IonDotnet/Internals/Binary/RawBinaryWriter.cs | 3 --- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Amazon.IonDotnet.Tests/Amazon.IonDotnet.Tests.csproj b/Amazon.IonDotnet.Tests/Amazon.IonDotnet.Tests.csproj index 566e8939..093060e5 100644 --- a/Amazon.IonDotnet.Tests/Amazon.IonDotnet.Tests.csproj +++ b/Amazon.IonDotnet.Tests/Amazon.IonDotnet.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1;netcoreapp2.0;netcoreapp1.0;net45;net46 - netcoreapp2.1;netcoreapp2.0 + netcoreapp2.1;net45;net46 + netcoreapp2.1 false latest Debug;Release;Perf diff --git a/Amazon.IonDotnet.Tests/Internals/BigDecimalTest.cs b/Amazon.IonDotnet.Tests/Internals/BigDecimalTest.cs index cd3addbe..38379d3e 100644 --- a/Amazon.IonDotnet.Tests/Internals/BigDecimalTest.cs +++ b/Amazon.IonDotnet.Tests/Internals/BigDecimalTest.cs @@ -222,6 +222,9 @@ public void Parse_Zeros(string text, bool isNegativeZero) [DataRow("0.12345d5", "12345d0")] [DataRow("0.12345d4", "1234.5")] [DataRow("12345d-5", "1.2345d-1")] + [DataRow("-0d5", "-0d5")] + [DataRow("-0d-5", "-0d-5")] + [DataRow("-0.00d7", "-0d5")] public void ToString_Simple(string text, string expected) { var parsed = BigDecimal.Parse(text); diff --git a/Amazon.IonDotnet/BigDecimal.cs b/Amazon.IonDotnet/BigDecimal.cs index 022bfbfd..9d9c7919 100644 --- a/Amazon.IonDotnet/BigDecimal.cs +++ b/Amazon.IonDotnet/BigDecimal.cs @@ -417,10 +417,9 @@ public static BigDecimal Parse(ReadOnlySpan text) public override string ToString() { - //TODO improve this if (IsNegativeZero) { - return "-0d" + Scale; + return "-0d" + (-Scale); } var sb = new StringBuilder(IntVal.ToString(CultureInfo.InvariantCulture)); diff --git a/Amazon.IonDotnet/Internals/Binary/RawBinaryWriter.cs b/Amazon.IonDotnet/Internals/Binary/RawBinaryWriter.cs index 03f2de2f..b8bd6206 100644 --- a/Amazon.IonDotnet/Internals/Binary/RawBinaryWriter.cs +++ b/Amazon.IonDotnet/Internals/Binary/RawBinaryWriter.cs @@ -919,13 +919,10 @@ private ContainerType GetContainerType(IonType ionType) { case IonType.List: return ContainerType.List; - break; case IonType.Struct: return ContainerType.Struct; - break; case IonType.Sexp: return ContainerType.Sexp; - break; default: throw new ArgumentOutOfRangeException(); }