Fixed more primitive mappings and added tests
parent
cf0cd55be8
commit
5d4852404f
|
@ -106,11 +106,23 @@ namespace ln.json.tests
|
||||||
[Test]
|
[Test]
|
||||||
public void TestMapper()
|
public void TestMapper()
|
||||||
{
|
{
|
||||||
byte b = 0x80;
|
TestPrimitiveMapping((byte)0x80);
|
||||||
Assert.IsTrue(JSONMapper.DefaultMapper.Serialize(b, out JSONValue jsonByte));
|
TestPrimitiveMapping((short)0x80);
|
||||||
JSONMapper.DefaultMapper.Deserialize(jsonByte, typeof(byte), out object b2);
|
TestPrimitiveMapping((ushort)0x80);
|
||||||
Assert.AreEqual(b,b2);
|
TestPrimitiveMapping((int)0x80);
|
||||||
Assert.AreEqual(b.GetType(), b2.GetType());
|
TestPrimitiveMapping((uint)0x80);
|
||||||
|
TestPrimitiveMapping((long)0x80);
|
||||||
|
TestPrimitiveMapping((ulong)0x80);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestPrimitiveMapping(object primitiveValue)
|
||||||
|
{
|
||||||
|
Type primitiveType = primitiveValue.GetType();
|
||||||
|
Assert.IsTrue(JSONMapper.DefaultMapper.Serialize(primitiveValue, out JSONValue jsonPrimitive));
|
||||||
|
JSONMapper.DefaultMapper.Deserialize(jsonPrimitive, primitiveType, out object primitiveValue2);
|
||||||
|
Assert.AreEqual(primitiveValue, primitiveValue2);
|
||||||
|
Assert.AreEqual(primitiveType, primitiveValue2.GetType());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,7 +264,7 @@ namespace ln.json.mapping
|
||||||
));
|
));
|
||||||
DefaultMapper.Add(new JSONMapping(
|
DefaultMapper.Add(new JSONMapping(
|
||||||
typeof(short),
|
typeof(short),
|
||||||
(JSONMapper arg1, object arg2) => new JSONNumber((int)arg2),
|
(JSONMapper arg1, object arg2) => new JSONNumber((int)(short)arg2),
|
||||||
(JSONMapper arg1, JSONValue arg2) => Decimal.ToInt16(((JSONNumber)arg2).Decimal)
|
(JSONMapper arg1, JSONValue arg2) => Decimal.ToInt16(((JSONNumber)arg2).Decimal)
|
||||||
));
|
));
|
||||||
DefaultMapper.Add(new JSONMapping(
|
DefaultMapper.Add(new JSONMapping(
|
||||||
|
@ -279,12 +279,12 @@ namespace ln.json.mapping
|
||||||
));
|
));
|
||||||
DefaultMapper.Add(new JSONMapping(
|
DefaultMapper.Add(new JSONMapping(
|
||||||
typeof(ushort),
|
typeof(ushort),
|
||||||
(JSONMapper arg1, object arg2) => new JSONNumber((uint)arg2),
|
(JSONMapper arg1, object arg2) => new JSONNumber((uint)(ushort)arg2),
|
||||||
(JSONMapper arg1, JSONValue arg2) => Decimal.ToUInt16(((JSONNumber)arg2).Decimal)
|
(JSONMapper arg1, JSONValue arg2) => Decimal.ToUInt16(((JSONNumber)arg2).Decimal)
|
||||||
));
|
));
|
||||||
DefaultMapper.Add(new JSONMapping(
|
DefaultMapper.Add(new JSONMapping(
|
||||||
typeof(uint),
|
typeof(uint),
|
||||||
(JSONMapper arg1, object arg2) => new JSONNumber((uint)arg2),
|
(JSONMapper arg1, object arg2) => new JSONNumber((uint)(uint)arg2),
|
||||||
(JSONMapper arg1, JSONValue arg2) => Decimal.ToUInt32(((JSONNumber)arg2).Decimal)
|
(JSONMapper arg1, JSONValue arg2) => Decimal.ToUInt32(((JSONNumber)arg2).Decimal)
|
||||||
));
|
));
|
||||||
DefaultMapper.Add(new JSONMapping(
|
DefaultMapper.Add(new JSONMapping(
|
||||||
|
|
Loading…
Reference in New Issue