Fix unit name serialization
We just store the unit name as specified and serialize that (instead of using the name as given in UnitsNet)
This commit is contained in:
@ -101,14 +101,38 @@ internal class Program : SaneTsv
|
||||
|
||||
{
|
||||
string testName = "Serde unit";
|
||||
string testString1 = "# ExtraTSV V0.0.1\n" +
|
||||
"id:uint32\tvalue:m/s:ph-unit:float64\n" +
|
||||
"0\t1.5\n" +
|
||||
"1\t5.4e3";
|
||||
|
||||
CommentedTsv<UnitTest> parsed = SaneTsv.ParseExtraTsv<UnitTest>(Encoding.UTF8.GetBytes(testString1));
|
||||
string serialized = Encoding.UTF8.GetString(SaneTsv.SerializeExtraTsv<UnitTest>(parsed.Records));
|
||||
if (testString1 == serialized)
|
||||
UnitTest[] records = new UnitTest[]
|
||||
{
|
||||
new UnitTest
|
||||
{
|
||||
Id = 1,
|
||||
Value = UnitsNet.Speed.FromMetersPerSecond(5.03),
|
||||
},
|
||||
new UnitTest
|
||||
{
|
||||
Id = 5,
|
||||
Value = UnitsNet.Speed.FromMetersPerSecond(double.NaN),
|
||||
},
|
||||
new UnitTest
|
||||
{
|
||||
Id = 1000000,
|
||||
Value = UnitsNet.Speed.FromMetersPerSecond(9859873.498),
|
||||
},
|
||||
};
|
||||
|
||||
string serialized = Encoding.UTF8.GetString(SaneTsv.SerializeExtraTsv<UnitTest>(records));
|
||||
CommentedTsv<UnitTest> parsed = SaneTsv.ParseExtraTsv<UnitTest>(Encoding.UTF8.GetBytes(serialized));
|
||||
|
||||
bool match = true;
|
||||
for (int i = 0; i < records.Length; i++)
|
||||
{
|
||||
match = match && records[i].Id == parsed.Records[i].Id &&
|
||||
(records[i].Value.Equals(parsed.Records[i].Value, UnitsNet.Speed.FromMetersPerSecond(1E-1))
|
||||
|| (double.IsNaN(records[i].Value.Value) && double.IsNaN(parsed.Records[i].Value.Value)));
|
||||
}
|
||||
|
||||
if (match)
|
||||
{
|
||||
Console.WriteLine($"Passed {testName}");
|
||||
}
|
||||
|
Reference in New Issue
Block a user