mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 19:14:26 +00:00
Test parsing and serialization of real numbers with > 5 decimals
This commit is contained in:
@@ -147,6 +147,16 @@ namespace plistcil.test
|
||||
|
||||
Assert.Equal(expected, actual, false, true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void RoundtripRealTest()
|
||||
{
|
||||
var expected = File.ReadAllText(@"test-files\RoundtripReal.plist");
|
||||
var value = XmlPropertyListParser.Parse(new FileInfo(@"test-files\RoundtripReal.plist"));
|
||||
var actual = value.ToXmlPropertyList();
|
||||
|
||||
Assert.Equal(expected, actual, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,13 @@ namespace plistcil.test
|
||||
Assert.Equal(10032936613, number.ToObject());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void NSNumberWithDecimalTest()
|
||||
{
|
||||
var number = new NSNumber("1360155352.748765", NSNumber.REAL);
|
||||
Assert.Equal("1360155352.748765", number.ToString());
|
||||
}
|
||||
|
||||
// The tests below make sure the numbers are being parsed correctly, and do not depend on the culture info
|
||||
// being set. Especially, decimal point may vary between cultures and we don't want to take a dependency on that
|
||||
// The value being used comes seen in a real property list:
|
||||
|
||||
@@ -100,6 +100,9 @@
|
||||
<None Include="test-files\Roundtrip.plist">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="test-files\RoundtripReal.plist">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
5
plist-cil.test/test-files/RoundtripReal.plist
Normal file
5
plist-cil.test/test-files/RoundtripReal.plist
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<real>1360155352.748765</real>
|
||||
</plist>
|
||||
@@ -331,7 +331,7 @@ namespace Claunia.PropertyList
|
||||
}
|
||||
case REAL:
|
||||
{
|
||||
return ToDouble().ToString(CultureInfo.InvariantCulture);
|
||||
return ToDouble().ToString("G17", CultureInfo.InvariantCulture);
|
||||
}
|
||||
case BOOLEAN:
|
||||
{
|
||||
@@ -369,7 +369,9 @@ namespace Claunia.PropertyList
|
||||
}
|
||||
else
|
||||
{
|
||||
xml.Append(ToDouble().ToString(CultureInfo.InvariantCulture));
|
||||
// ToString() can truncate the decimals, so use "G17". See
|
||||
// https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#the-round-trip-r-format-specifier
|
||||
xml.Append(ToDouble().ToString("G17", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
xml.Append("</real>");
|
||||
|
||||
Reference in New Issue
Block a user