-Added BigInteger support
This commit is contained in:
@@ -28,6 +28,9 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
#if !NETFX_CORE
|
||||
@@ -175,6 +178,9 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
new JProperty("Uri", new Uri("http://json.codeplex.com/")),
|
||||
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
||||
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
,new JProperty("BigInteger", BigInteger.Parse("1"))
|
||||
#endif
|
||||
);
|
||||
|
||||
dynamic d = o;
|
||||
@@ -205,6 +211,9 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(d.Decimal == 1.1m);
|
||||
Assert.IsTrue(d.Decimal != 1.0f);
|
||||
Assert.IsTrue(d.Decimal != 1.0d);
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
Assert.IsTrue(d.Decimal > new BigInteger(0));
|
||||
#endif
|
||||
|
||||
Assert.IsTrue(d.Float == d.Float);
|
||||
Assert.IsTrue(d.Float > 0);
|
||||
@@ -218,6 +227,24 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.IsTrue(d.Float == 1.1m);
|
||||
Assert.IsTrue(d.Float != 1.0f);
|
||||
Assert.IsTrue(d.Float != 1.0d);
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
Assert.IsTrue(d.Float > new BigInteger(0));
|
||||
#endif
|
||||
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
Assert.IsTrue(d.BigInteger == d.BigInteger);
|
||||
Assert.IsTrue(d.BigInteger > 0);
|
||||
Assert.IsTrue(d.BigInteger > 0.0m);
|
||||
Assert.IsTrue(d.BigInteger > 0.0f);
|
||||
Assert.IsTrue(d.BigInteger > null);
|
||||
Assert.IsTrue(d.BigInteger >= null);
|
||||
Assert.IsTrue(d.BigInteger < 2);
|
||||
Assert.IsTrue(d.BigInteger <= 1.1);
|
||||
Assert.IsTrue(d.BigInteger == 1);
|
||||
Assert.IsTrue(d.BigInteger == 1m);
|
||||
Assert.IsTrue(d.BigInteger != 1.1f);
|
||||
Assert.IsTrue(d.BigInteger != 1.1d);
|
||||
#endif
|
||||
|
||||
Assert.IsTrue(d.Bytes == d.Bytes);
|
||||
Assert.IsTrue(d.Bytes == Encoding.UTF8.GetBytes("A string lol!"));
|
||||
@@ -260,6 +287,9 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
new JProperty("Uri", new Uri("http://json.codeplex.com/")),
|
||||
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
||||
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
,new JProperty("BigInteger", new BigInteger(100))
|
||||
#endif
|
||||
);
|
||||
|
||||
dynamic d = o;
|
||||
@@ -335,6 +365,23 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(null, r.Value);
|
||||
r += 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
r = d.BigInteger + null;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
r += 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
|
||||
r = d.BigInteger + 1;
|
||||
Assert.AreEqual(101, (int)r);
|
||||
r += 2;
|
||||
Assert.AreEqual(103, (int)r);
|
||||
|
||||
r = d.BigInteger + 1.1d;
|
||||
Assert.AreEqual(101m, (decimal)r);
|
||||
r += 2;
|
||||
Assert.AreEqual(103m, (decimal)r);
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region Subtract
|
||||
@@ -397,6 +444,18 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(null, r.Value);
|
||||
r -= 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
r = d.BigInteger - null;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
r -= 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
|
||||
r = d.BigInteger - 1.1d;
|
||||
Assert.AreEqual(99m, (decimal)r);
|
||||
r -= 2;
|
||||
Assert.AreEqual(97m, (decimal)r);
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region Multiply
|
||||
@@ -459,6 +518,18 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(null, r.Value);
|
||||
r *= 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
r = d.BigInteger * 1.1d;
|
||||
Assert.AreEqual(100m, (decimal)r);
|
||||
r *= 2;
|
||||
Assert.AreEqual(200m, (decimal)r);
|
||||
|
||||
r = d.BigInteger * null;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
r *= 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
#region Divide
|
||||
@@ -521,6 +592,18 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(null, r.Value);
|
||||
r /= 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
r = d.BigInteger / 1.1d;
|
||||
Assert.AreEqual(100m, (decimal)r);
|
||||
r /= 2;
|
||||
Assert.AreEqual(50m, (decimal)r);
|
||||
|
||||
r = d.BigInteger / null;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
r /= 2;
|
||||
Assert.AreEqual(null, r.Value);
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -538,6 +621,9 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
new JProperty("Uri", new Uri("http://json.codeplex.com/")),
|
||||
new JProperty("Guid", new Guid("EA27FE1D-0D80-44F2-BF34-4654156FA7AF")),
|
||||
new JProperty("TimeSpan", TimeSpan.FromDays(1))
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
,new JProperty("BigInteger", new BigInteger(100))
|
||||
#endif
|
||||
);
|
||||
|
||||
dynamic d = o;
|
||||
@@ -552,6 +638,9 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual("http://json.codeplex.com/", d.Uri.ToString());
|
||||
Assert.AreEqual("ea27fe1d-0d80-44f2-bf34-4654156fa7af", d.Guid.ToString());
|
||||
Assert.AreEqual("1.00:00:00", d.TimeSpan.ToString());
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
Assert.AreEqual("100", d.BigInteger.ToString());
|
||||
#endif
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -633,6 +722,10 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
AssertValueConverted<Guid?>(null);
|
||||
AssertValueConverted<Uri>(new Uri("http://json.codeplex.com/"));
|
||||
AssertValueConverted<Uri>(null);
|
||||
#if !(NET20 || NET35 || SILVERLIGHT || PORTABLE)
|
||||
AssertValueConverted<BigInteger>(new BigInteger(100));
|
||||
AssertValueConverted<BigInteger?>(null);
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void AssertValueConverted<T>(object value)
|
||||
|
||||
Reference in New Issue
Block a user