-Added FloatParseHandling
-Fixed build
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user