|
2 | 2 | using Xunit; |
3 | 3 | using System; |
4 | 4 | using Dahomey.Cbor.Util; |
| 5 | +using System.Globalization; |
5 | 6 |
|
6 | 7 | namespace Dahomey.Cbor.Tests |
7 | 8 | { |
@@ -151,14 +152,20 @@ public void ReadUInt64(string hexBuffer, ulong expectedValue, Type expectedExcep |
151 | 152 | [InlineData("F90001", 5.960464477539063e-8f, null)] |
152 | 153 | [InlineData("F90400", 0.00006103515625f, null)] |
153 | 154 | [InlineData("F9C400", -4f, null)] |
154 | | - [InlineData("F97E00", float.NaN, null)] |
155 | 155 | [InlineData("F97C00", float.PositiveInfinity, null)] |
156 | 156 | [InlineData("F9FC00", float.NegativeInfinity, null)] |
157 | 157 | public void ReadHalf(string hexBuffer, float expectedValue, Type expectedExceptionType) |
158 | 158 | { |
159 | 159 | Helper.TestRead(nameof(CborReader.ReadHalf), hexBuffer, (Half)expectedValue, expectedExceptionType); |
160 | 160 | } |
161 | 161 |
|
| 162 | + [Fact] |
| 163 | + public void ReadNaNHalf() |
| 164 | + { |
| 165 | + Half actualValue = Helper.Read<Half>(nameof(CborReader.ReadHalf), "F97E00"); |
| 166 | + Assert.True(Half.IsNaN(actualValue)); |
| 167 | + } |
| 168 | + |
162 | 169 | [Theory] |
163 | 170 | // half |
164 | 171 | [InlineData("F9E3D0", -1000f, null)] |
@@ -225,7 +232,7 @@ public void ReadDecimal(string hexBuffer, decimal expectedValue, Type expectedEx |
225 | 232 | [InlineData("FCFFFFFFFFFFFFFFFFFFFFFFFF00000000", "79228162514264337593543950335", null)] |
226 | 233 | public void ReadDecimal2(string hexBuffer, string expectedValue, Type expectedExceptionType) |
227 | 234 | { |
228 | | - if (!decimal.TryParse(expectedValue, out decimal decimalValue)) throw new InvalidCastException("Specified string cannot be cast to a decimal value"); |
| 235 | + if (!decimal.TryParse(expectedValue, NumberStyles.Any, CultureInfo.InvariantCulture, out decimal decimalValue)) throw new InvalidCastException("Specified string cannot be cast to a decimal value"); |
229 | 236 |
|
230 | 237 | Helper.TestRead(nameof(CborReader.ReadDecimal), hexBuffer, decimalValue, expectedExceptionType); |
231 | 238 | } |
|
0 commit comments