-Added FloatParseHandling

-Fixed build
This commit is contained in:
James Newton-King
2013-03-26 21:53:28 +13:00
parent e5ee60497e
commit 70f5a1dced
25 changed files with 309 additions and 11 deletions
@@ -44,6 +44,57 @@ namespace Newtonsoft.Json.Tests
[TestFixture]
public class JsonTextReaderTest : TestFixtureBase
{
[Test]
public void FloatParseHandling()
{
string json = "[1.0,1,9.9,1E-06]";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
reader.FloatParseHandling = Json.FloatParseHandling.Decimal;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(1.0d, reader.Value);
Assert.AreEqual(typeof(decimal), reader.ValueType);
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(1, reader.Value);
Assert.AreEqual(typeof(long), reader.ValueType);
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(9.9d, reader.Value);
Assert.AreEqual(typeof(decimal), reader.ValueType);
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(Convert.ToDecimal(1E-06), reader.Value);
Assert.AreEqual(typeof(decimal), reader.ValueType);
Assert.AreEqual(JsonToken.Float, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
}
[Test]
public void FloatParseHandling_NaN()
{
string json = "[NaN]";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
reader.FloatParseHandling = Json.FloatParseHandling.Decimal;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
ExceptionAssert.Throws<JsonReaderException>(
"Cannot read NaN as a decimal.",
() => reader.Read());
}
[Test]
public void UnescapeDoubleQuotes()
{