|
1 | 1 | using System;
|
2 | 2 | using System.Collections;
|
3 | 3 | using System.Collections.Generic;
|
| 4 | +using System.Globalization; |
4 | 5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
5 | 6 | using Parse.Infrastructure.Utilities;
|
6 | 7 |
|
@@ -250,5 +251,29 @@ public void TestSpecialJsonNumbersAndModifiers()
|
250 | 251 |
|
251 | 252 | Assert.AreEqual(123456789123456789, (JsonUtilities.Parse("{ \"mura\": 123456789123456789 }") as IDictionary)["mura"]);
|
252 | 253 | }
|
| 254 | + |
| 255 | + |
| 256 | + [TestMethod] |
| 257 | + public void TestJsonNumbersAndValueRanges() |
| 258 | + { |
| 259 | + //Assert.ThrowsException<ArgumentException>(() => JsonUtilities.Parse("+123456789")); |
| 260 | + Assert.IsInstanceOfType((JsonUtilities.Parse("{ \"long\": " + long.MaxValue + " }") as IDictionary)["long"], typeof(long)); |
| 261 | + Assert.IsInstanceOfType((JsonUtilities.Parse("{ \"long\": " + long.MinValue + " }") as IDictionary)["long"], typeof(long)); |
| 262 | + |
| 263 | + Assert.AreEqual((JsonUtilities.Parse("{ \"long\": " + long.MaxValue + " }") as IDictionary)["long"], long.MaxValue); |
| 264 | + Assert.AreEqual((JsonUtilities.Parse("{ \"long\": " + long.MinValue + " }") as IDictionary)["long"], long.MinValue); |
| 265 | + |
| 266 | + |
| 267 | + Assert.IsInstanceOfType((JsonUtilities.Parse("{ \"double\": " + double.MaxValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], typeof(double)); |
| 268 | + Assert.IsInstanceOfType((JsonUtilities.Parse("{ \"double\": " + double.MinValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], typeof(double)); |
| 269 | + |
| 270 | + Assert.AreEqual((JsonUtilities.Parse("{ \"double\": " + double.MaxValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], double.MaxValue); |
| 271 | + Assert.AreEqual((JsonUtilities.Parse("{ \"double\": " + double.MinValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], double.MinValue); |
| 272 | + |
| 273 | + double outOfInt64RangeValue = -9223372036854776000d; |
| 274 | + Assert.IsInstanceOfType((JsonUtilities.Parse("{ \"double\": " + outOfInt64RangeValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], typeof(double)); |
| 275 | + Assert.AreEqual((JsonUtilities.Parse("{ \"double\": " + outOfInt64RangeValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], outOfInt64RangeValue); |
| 276 | + } |
| 277 | + |
253 | 278 | }
|
254 | 279 | }
|
0 commit comments