Break up JsonTextReaderTest class into smaller test classes
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,369 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
#if DNXCORE50
|
||||
using Xunit;
|
||||
using Test = Xunit.FactAttribute;
|
||||
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
|
||||
#else
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
#if NET20
|
||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||
#else
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json.Tests.JsonTextReaderTests;
|
||||
using Newtonsoft.Json.Tests.TestObjects.JsonTextReaderTests;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
|
||||
|
||||
namespace Newtonsoft.Json.Tests.JsonTextReaderTests
|
||||
{
|
||||
[TestFixture]
|
||||
#if !DNXCORE50
|
||||
[Category("JsonTextReaderTests")]
|
||||
#endif
|
||||
public class FloatTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void Float_ReadAsString_Exact()
|
||||
{
|
||||
const string testJson = "{float: 0.0620}";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(testJson));
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
string s = reader.ReadAsString();
|
||||
Assert.AreEqual("0.0620", s);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Float_NaN_Read()
|
||||
{
|
||||
const string testJson = "{float: NaN}";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(testJson));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(double.NaN, reader.Value);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Float_NaN_ReadAsInt32()
|
||||
{
|
||||
const string testJson = "{float: NaN}";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(testJson));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.ReadAsInt32(), "Cannot read NaN value. Path 'float', line 1, position 11.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Float_NaNAndInifinity_ReadAsDouble()
|
||||
{
|
||||
const string testJson = @"[
|
||||
NaN,
|
||||
Infinity,
|
||||
-Infinity
|
||||
]"; ;
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(testJson));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
Assert.AreEqual(double.NaN, reader.ReadAsDouble());
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(double.NaN, reader.Value);
|
||||
|
||||
Assert.AreEqual(double.PositiveInfinity, reader.ReadAsDouble());
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(double.PositiveInfinity, reader.Value);
|
||||
|
||||
Assert.AreEqual(double.NegativeInfinity, reader.ReadAsDouble());
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(double.NegativeInfinity, reader.Value);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Float_NaNAndInifinity_ReadAsString()
|
||||
{
|
||||
const string testJson = @"[
|
||||
NaN,
|
||||
Infinity,
|
||||
-Infinity
|
||||
]"; ;
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(testJson));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
Assert.AreEqual(JsonConvert.NaN, reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual(JsonConvert.NaN, reader.Value);
|
||||
|
||||
Assert.AreEqual(JsonConvert.PositiveInfinity, reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual(JsonConvert.PositiveInfinity, reader.Value);
|
||||
|
||||
Assert.AreEqual(JsonConvert.NegativeInfinity, reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual(JsonConvert.NegativeInfinity, reader.Value);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FloatParseHandling_ReadAsString()
|
||||
{
|
||||
string json = "[9223372036854775807, 1.7976931348623157E+308, 792281625142643375935439503.35, 792281625142643375935555555555555555555555555555555555555555555555555439503.35]";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
reader.FloatParseHandling = Json.FloatParseHandling.Decimal;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
Assert.AreEqual("9223372036854775807", reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual("9223372036854775807", reader.Value);
|
||||
|
||||
Assert.AreEqual("1.7976931348623157E+308", reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual("1.7976931348623157E+308", reader.Value);
|
||||
|
||||
Assert.AreEqual("792281625142643375935439503.35", reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual("792281625142643375935439503.35", reader.Value);
|
||||
|
||||
Assert.AreEqual("792281625142643375935555555555555555555555555555555555555555555555555439503.35", reader.ReadAsString());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual("792281625142643375935555555555555555555555555555555555555555555555555439503.35", reader.Value);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
}
|
||||
|
||||
[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.0m, reader.Value);
|
||||
Assert.AreEqual(typeof(decimal), reader.ValueType);
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(1L, reader.Value);
|
||||
Assert.AreEqual(typeof(long), reader.ValueType);
|
||||
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(9.9m, 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>(() => reader.Read(), "Cannot read NaN value. Path '', line 1, position 4.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FloatingPointNonFiniteNumbers()
|
||||
{
|
||||
string input = @"[
|
||||
NaN,
|
||||
Infinity,
|
||||
-Infinity
|
||||
]";
|
||||
|
||||
StringReader sr = new StringReader(input);
|
||||
|
||||
using (JsonReader jsonReader = new JsonTextReader(sr))
|
||||
{
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(jsonReader.TokenType, JsonToken.StartArray);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(jsonReader.TokenType, JsonToken.Float);
|
||||
Assert.AreEqual(jsonReader.Value, double.NaN);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(jsonReader.TokenType, JsonToken.Float);
|
||||
Assert.AreEqual(jsonReader.Value, double.PositiveInfinity);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(jsonReader.TokenType, JsonToken.Float);
|
||||
Assert.AreEqual(jsonReader.Value, double.NegativeInfinity);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadFloatingPointNumber()
|
||||
{
|
||||
string json =
|
||||
@"[0.0,0.0,0.1,1.0,1.000001,1E-06,4.94065645841247E-324,Infinity,-Infinity,NaN,1.7976931348623157E+308,-1.7976931348623157E+308,Infinity,-Infinity,NaN,0e-10,0.25e-5,0.3e10]";
|
||||
|
||||
using (JsonReader jsonReader = new JsonTextReader(new StringReader(json)))
|
||||
{
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.StartArray, jsonReader.TokenType);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(0.0, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(0.0, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(0.1, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(1.0, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(1.000001, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(1E-06, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(4.94065645841247E-324, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(double.PositiveInfinity, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(double.NegativeInfinity, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(double.NaN, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(double.MaxValue, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(double.MinValue, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(double.PositiveInfinity, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(double.NegativeInfinity, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(double.NaN, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(0d, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(0.0000025d, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.Float, jsonReader.TokenType);
|
||||
Assert.AreEqual(3000000000d, jsonReader.Value);
|
||||
|
||||
jsonReader.Read();
|
||||
Assert.AreEqual(JsonToken.EndArray, jsonReader.TokenType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,514 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE) || NETSTANDARD1_1
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Text;
|
||||
#if DNXCORE50
|
||||
using Xunit;
|
||||
using Test = Xunit.FactAttribute;
|
||||
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
|
||||
#else
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
#if NET20
|
||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||
#else
|
||||
using System.Linq;
|
||||
#endif
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json.Tests.TestObjects.JsonTextReaderTests;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.JsonTextReaderTests
|
||||
{
|
||||
[TestFixture]
|
||||
#if !DNXCORE50
|
||||
[Category("JsonTextReaderTests")]
|
||||
#endif
|
||||
public class ParseTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void ParseAdditionalContent_Whitespace()
|
||||
{
|
||||
string json = @"[
|
||||
""Small"",
|
||||
""Medium"",
|
||||
""Large""
|
||||
]
|
||||
|
||||
";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
while (reader.Read())
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParsingQuotedPropertyWithControlCharacters()
|
||||
{
|
||||
JsonReader reader = new JsonTextReader(new StringReader(@"{'hi\r\nbye':1}"));
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
Assert.AreEqual("hi\r\nbye", reader.Value);
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
||||
Assert.AreEqual(1L, reader.Value);
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseIntegers()
|
||||
{
|
||||
JsonTextReader reader = null;
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1"));
|
||||
Assert.AreEqual(1, reader.ReadAsInt32());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-1"));
|
||||
Assert.AreEqual(-1, reader.ReadAsInt32());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("0"));
|
||||
Assert.AreEqual(0, reader.ReadAsInt32());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-0"));
|
||||
Assert.AreEqual(0, reader.ReadAsInt32());
|
||||
|
||||
reader = new JsonTextReader(new StringReader(int.MaxValue.ToString()));
|
||||
Assert.AreEqual(int.MaxValue, reader.ReadAsInt32());
|
||||
|
||||
reader = new JsonTextReader(new StringReader(int.MinValue.ToString()));
|
||||
Assert.AreEqual(int.MinValue, reader.ReadAsInt32());
|
||||
|
||||
reader = new JsonTextReader(new StringReader(long.MaxValue.ToString()));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.ReadAsInt32(), "JSON integer 9223372036854775807 is too large or small for an Int32. Path '', line 1, position 19.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader("9999999999999999999999999999999999999999999999999999999999999999999999999999asdasdasd"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.ReadAsInt32(), "Unexpected character encountered while parsing number: s. Path '', line 1, position 77.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1E-06"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.ReadAsInt32(), "Input string '1E-06' is not a valid integer. Path '', line 1, position 5.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1.1"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.ReadAsInt32(), "Input string '1.1' is not a valid integer. Path '', line 1, position 3.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader(""));
|
||||
Assert.AreEqual(null, reader.ReadAsInt32());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.ReadAsInt32(), "Input string '-' is not a valid integer. Path '', line 1, position 1.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseDecimals()
|
||||
{
|
||||
JsonTextReader reader = null;
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1.1"));
|
||||
Assert.AreEqual(1.1m, reader.ReadAsDecimal());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-1.1"));
|
||||
Assert.AreEqual(-1.1m, reader.ReadAsDecimal());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("0.0"));
|
||||
Assert.AreEqual(0.0m, reader.ReadAsDecimal());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-0.0"));
|
||||
Assert.AreEqual(0, reader.ReadAsDecimal());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("9999999999999999999999999999999999999999999999999999999999999999999999999999asdasdasd"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.ReadAsDecimal(), "Unexpected character encountered while parsing number: s. Path '', line 1, position 77.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader("9999999999999999999999999999999999999999999999999999999999999999999999999999asdasdasd"));
|
||||
reader.FloatParseHandling = Json.FloatParseHandling.Decimal;
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.Read(), "Unexpected character encountered while parsing number: s. Path '', line 1, position 77.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1E-06"));
|
||||
Assert.AreEqual(0.000001m, reader.ReadAsDecimal());
|
||||
|
||||
reader = new JsonTextReader(new StringReader(""));
|
||||
Assert.AreEqual(null, reader.ReadAsDecimal());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.ReadAsDecimal(), "Input string '-' is not a valid decimal. Path '', line 1, position 1.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseDoubles()
|
||||
{
|
||||
JsonTextReader reader = null;
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1.1"));
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(typeof(double), reader.ValueType);
|
||||
Assert.AreEqual(1.1d, reader.Value);
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-1.1"));
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(typeof(double), reader.ValueType);
|
||||
Assert.AreEqual(-1.1d, reader.Value);
|
||||
|
||||
reader = new JsonTextReader(new StringReader("0.0"));
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(typeof(double), reader.ValueType);
|
||||
Assert.AreEqual(0.0d, reader.Value);
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-0.0"));
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(typeof(double), reader.ValueType);
|
||||
Assert.AreEqual(-0.0d, reader.Value);
|
||||
|
||||
reader = new JsonTextReader(new StringReader("9999999999999999999999999999999999999999999999999999999999999999999999999999asdasdasd"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.Read(), "Unexpected character encountered while parsing number: s. Path '', line 1, position 77.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1E-06"));
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(typeof(double), reader.ValueType);
|
||||
Assert.AreEqual(0.000001d, reader.Value);
|
||||
|
||||
reader = new JsonTextReader(new StringReader(""));
|
||||
Assert.IsFalse(reader.Read());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.Read(), "Input string '-' is not a valid number. Path '', line 1, position 1.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1.7976931348623157E+308"));
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(typeof(double), reader.ValueType);
|
||||
Assert.AreEqual(Double.MaxValue, reader.Value);
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-1.7976931348623157E+308"));
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(typeof(double), reader.ValueType);
|
||||
Assert.AreEqual(Double.MinValue, reader.Value);
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1E+309"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.Read(), "Input string '1E+309' is not a valid number. Path '', line 1, position 6.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader("-1E+5000"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.Read(), "Input string '-1E+5000' is not a valid number. Path '', line 1, position 8.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader("5.1231231E"));
|
||||
ExceptionAssert.Throws<JsonReaderException>(() => reader.Read(), "Input string '5.1231231E' is not a valid number. Path '', line 1, position 10.");
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1E-23"));
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(typeof(double), reader.ValueType);
|
||||
Assert.AreEqual(1e-23, reader.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseArrayWithMissingValues()
|
||||
{
|
||||
string json = "[,,, \n\r\n \0 \r , , ]";
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Undefined, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Undefined, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Undefined, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Undefined, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Undefined, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseBooleanWithNoExtraContent()
|
||||
{
|
||||
string json = "[true ";
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseContentDelimitedByNonStandardWhitespace()
|
||||
{
|
||||
string json = "\x00a0{\x00a0'h\x00a0i\x00a0'\x00a0:\x00a0[\x00a0true\x00a0,\x00a0new\x00a0Date\x00a0(\x00a0)\x00a0]\x00a0/*\x00a0comment\x00a0*/\x00a0}\x00a0";
|
||||
JsonTextReader reader = new JsonTextReader(new StreamReader(new SlowStream(json, new UTF8Encoding(false), 1)));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Boolean, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartConstructor, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndConstructor, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.Comment, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
||||
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseObjectWithNoEnd()
|
||||
{
|
||||
string json = "{hi:1, ";
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseEmptyArray()
|
||||
{
|
||||
string json = "[]";
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseEmptyObject()
|
||||
{
|
||||
string json = "{}";
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseEmptyConstructor()
|
||||
{
|
||||
string json = "new Date()";
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartConstructor, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndConstructor, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseHexNumber()
|
||||
{
|
||||
string json = @"0x20";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
reader.ReadAsDecimal();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(32m, reader.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseNumbers()
|
||||
{
|
||||
string json = @"[0,1,2 , 3]";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
|
||||
|
||||
reader.Read();
|
||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseLineFeedDelimitedConstructor()
|
||||
{
|
||||
string json = "new Date\n()";
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("Date", reader.Value);
|
||||
Assert.AreEqual(JsonToken.StartConstructor, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndConstructor, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseNullStringConstructor()
|
||||
{
|
||||
string json = "new Date\0()";
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
#if DEBUG
|
||||
reader.SetCharBuffer(new char[7]);
|
||||
#endif
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("Date", reader.Value);
|
||||
Assert.AreEqual(JsonToken.StartConstructor, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndConstructor, reader.TokenType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseOctalNumber()
|
||||
{
|
||||
string json = @"010";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
|
||||
reader.ReadAsDecimal();
|
||||
Assert.AreEqual(JsonToken.Float, reader.TokenType);
|
||||
Assert.AreEqual(8m, reader.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DateParseHandling()
|
||||
{
|
||||
string json = @"[""1970-01-01T00:00:00Z"",""\/Date(0)\/""]";
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
reader.DateParseHandling = Json.DateParseHandling.DateTime;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(new DateTime(DateTimeUtils.InitialJavaScriptDateTicks, DateTimeKind.Utc), reader.Value);
|
||||
Assert.AreEqual(typeof(DateTime), reader.ValueType);
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(new DateTime(DateTimeUtils.InitialJavaScriptDateTicks, DateTimeKind.Utc), reader.Value);
|
||||
Assert.AreEqual(typeof(DateTime), reader.ValueType);
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
#if !NET20
|
||||
reader = new JsonTextReader(new StringReader(json));
|
||||
reader.DateParseHandling = Json.DateParseHandling.DateTimeOffset;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(new DateTimeOffset(DateTimeUtils.InitialJavaScriptDateTicks, TimeSpan.Zero), reader.Value);
|
||||
Assert.AreEqual(typeof(DateTimeOffset), reader.ValueType);
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(new DateTimeOffset(DateTimeUtils.InitialJavaScriptDateTicks, TimeSpan.Zero), reader.Value);
|
||||
Assert.AreEqual(typeof(DateTimeOffset), reader.ValueType);
|
||||
Assert.IsTrue(reader.Read());
|
||||
#endif
|
||||
|
||||
reader = new JsonTextReader(new StringReader(json));
|
||||
reader.DateParseHandling = Json.DateParseHandling.None;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(@"1970-01-01T00:00:00Z", reader.Value);
|
||||
Assert.AreEqual(typeof(string), reader.ValueType);
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(@"/Date(0)/", reader.Value);
|
||||
Assert.AreEqual(typeof(string), reader.ValueType);
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
#if !NET20
|
||||
reader = new JsonTextReader(new StringReader(json));
|
||||
reader.DateParseHandling = Json.DateParseHandling.DateTime;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
reader.ReadAsDateTimeOffset();
|
||||
Assert.AreEqual(new DateTimeOffset(DateTimeUtils.InitialJavaScriptDateTicks, TimeSpan.Zero), reader.Value);
|
||||
Assert.AreEqual(typeof(DateTimeOffset), reader.ValueType);
|
||||
reader.ReadAsDateTimeOffset();
|
||||
Assert.AreEqual(new DateTimeOffset(DateTimeUtils.InitialJavaScriptDateTicks, TimeSpan.Zero), reader.Value);
|
||||
Assert.AreEqual(typeof(DateTimeOffset), reader.ValueType);
|
||||
Assert.IsTrue(reader.Read());
|
||||
|
||||
reader = new JsonTextReader(new StringReader(json));
|
||||
reader.DateParseHandling = Json.DateParseHandling.DateTimeOffset;
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
reader.ReadAsDateTime();
|
||||
Assert.AreEqual(new DateTime(DateTimeUtils.InitialJavaScriptDateTicks, DateTimeKind.Utc), reader.Value);
|
||||
Assert.AreEqual(typeof(DateTime), reader.ValueType);
|
||||
reader.ReadAsDateTime();
|
||||
Assert.AreEqual(new DateTime(DateTimeUtils.InitialJavaScriptDateTicks, DateTimeKind.Utc), reader.Value);
|
||||
Assert.AreEqual(typeof(DateTime), reader.ValueType);
|
||||
Assert.IsTrue(reader.Read());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -46,6 +46,7 @@ using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Tests.TestObjects.JsonTextReaderTests;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
|
||||
namespace Newtonsoft.Json.Tests
|
||||
@@ -56,7 +57,7 @@ namespace Newtonsoft.Json.Tests
|
||||
[Test]
|
||||
public void BufferTest()
|
||||
{
|
||||
JsonTextReaderTest.FakeArrayPool arrayPool = new JsonTextReaderTest.FakeArrayPool();
|
||||
FakeArrayPool arrayPool = new FakeArrayPool();
|
||||
|
||||
string longString = new string('A', 2000);
|
||||
string longEscapedString = "Hello!" + new string('!', 50) + new string('\n', 1000) + "Good bye!";
|
||||
@@ -100,7 +101,7 @@ namespace Newtonsoft.Json.Tests
|
||||
[Test]
|
||||
public void BufferTest_WithError()
|
||||
{
|
||||
JsonTextReaderTest.FakeArrayPool arrayPool = new JsonTextReaderTest.FakeArrayPool();
|
||||
FakeArrayPool arrayPool = new FakeArrayPool();
|
||||
|
||||
StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
|
||||
|
||||
|
||||
@@ -88,6 +88,11 @@
|
||||
<Compile Include="Converters\VersionConverterTests.cs" />
|
||||
<Compile Include="JsonArrayAttributeTests.cs" />
|
||||
<Compile Include="ExceptionTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ExceptionHandlingTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\FloatTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\MiscTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ParseTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ReadTests.cs" />
|
||||
<Compile Include="JsonValidatingReaderTests.cs" />
|
||||
<Compile Include="Linq\ComponentModel\BindingTests.cs" />
|
||||
<Compile Include="Linq\ComponentModel\JPropertyDescriptorTests.cs" />
|
||||
@@ -166,6 +171,10 @@
|
||||
<Compile Include="TestObjects\Item.cs" />
|
||||
<Compile Include="TestObjects\JsonPropertyClass.cs" />
|
||||
<Compile Include="Serialization\JsonSerializerTest.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\FakeArrayPool.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\SlowStream.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\ToggleReaderError.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\UnmanagedResourceFakingJsonReader.cs" />
|
||||
<Compile Include="TestObjects\ListOfIds.cs" />
|
||||
<Compile Include="TestObjects\ListTestClass.cs" />
|
||||
<Compile Include="TestObjects\LogEntry.cs" />
|
||||
@@ -288,7 +297,6 @@
|
||||
<Compile Include="Converters\IsoDateTimeConverterTests.cs" />
|
||||
<Compile Include="JsonConvertTest.cs" />
|
||||
<Compile Include="Converters\JavaScriptDateTimeConverterTests.cs" />
|
||||
<Compile Include="JsonTextReaderTest.cs" />
|
||||
<Compile Include="JsonTextWriterTest.cs" />
|
||||
<Compile Include="Linq\JTokenReaderTest.cs" />
|
||||
<Compile Include="Linq\JTokenWriterTest.cs" />
|
||||
|
||||
@@ -118,6 +118,11 @@
|
||||
<Compile Include="Converters\VersionConverterTests.cs" />
|
||||
<Compile Include="JsonArrayAttributeTests.cs" />
|
||||
<Compile Include="ExceptionTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ExceptionHandlingTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\FloatTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\MiscTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ParseTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ReadTests.cs" />
|
||||
<Compile Include="JsonValidatingReaderTests.cs" />
|
||||
<Compile Include="LinqToSql\Department.cs" />
|
||||
<Compile Include="LinqToSql\DepartmentConverter.cs" />
|
||||
@@ -203,6 +208,10 @@
|
||||
<Compile Include="TestObjects\IPrivateImplementationB.cs" />
|
||||
<Compile Include="TestObjects\IPrivateOverriddenImplementation.cs" />
|
||||
<Compile Include="TestObjects\Item.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\FakeArrayPool.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\SlowStream.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\ToggleReaderError.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\UnmanagedResourceFakingJsonReader.cs" />
|
||||
<Compile Include="TestObjects\ListOfIds.cs" />
|
||||
<Compile Include="TestObjects\MetroPropertyNameResolver.cs" />
|
||||
<Compile Include="TestObjects\MetroStringConverter.cs" />
|
||||
@@ -343,7 +352,6 @@
|
||||
<Compile Include="JsonConvertTest.cs" />
|
||||
<Compile Include="Converters\JavaScriptDateTimeConverterTests.cs" />
|
||||
<Compile Include="Serialization\JsonSerializerTest.cs" />
|
||||
<Compile Include="JsonTextReaderTest.cs" />
|
||||
<Compile Include="JsonTextWriterTest.cs" />
|
||||
<Compile Include="Linq\JTokenReaderTest.cs" />
|
||||
<Compile Include="Linq\JTokenWriterTest.cs" />
|
||||
|
||||
@@ -234,6 +234,11 @@
|
||||
</Compile>
|
||||
<Compile Include="JsonArrayAttributeTests.cs" />
|
||||
<Compile Include="ExceptionTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ExceptionHandlingTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\FloatTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\MiscTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ParseTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ReadTests.cs" />
|
||||
<Compile Include="JsonValidatingReaderTests.cs" />
|
||||
<Compile Include="LinqToSql\Department.cs" />
|
||||
<Compile Include="LinqToSql\DepartmentConverter.cs" />
|
||||
@@ -320,6 +325,10 @@
|
||||
<Compile Include="TestObjects\IPrivateImplementationB.cs" />
|
||||
<Compile Include="TestObjects\IPrivateOverriddenImplementation.cs" />
|
||||
<Compile Include="TestObjects\Item.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\FakeArrayPool.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\SlowStream.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\ToggleReaderError.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\UnmanagedResourceFakingJsonReader.cs" />
|
||||
<Compile Include="TestObjects\ListOfIds.cs" />
|
||||
<Compile Include="TestObjects\MetroPropertyNameResolver.cs" />
|
||||
<Compile Include="TestObjects\MetroStringConverter.cs" />
|
||||
@@ -460,7 +469,6 @@
|
||||
<Compile Include="JsonConvertTest.cs" />
|
||||
<Compile Include="Converters\JavaScriptDateTimeConverterTests.cs" />
|
||||
<Compile Include="Serialization\JsonSerializerTest.cs" />
|
||||
<Compile Include="JsonTextReaderTest.cs" />
|
||||
<Compile Include="JsonTextWriterTest.cs" />
|
||||
<Compile Include="Linq\JTokenReaderTest.cs" />
|
||||
<Compile Include="Linq\JTokenWriterTest.cs" />
|
||||
|
||||
@@ -122,6 +122,11 @@
|
||||
<Compile Include="Converters\VersionConverterTests.cs" />
|
||||
<Compile Include="JsonArrayAttributeTests.cs" />
|
||||
<Compile Include="ExceptionTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ExceptionHandlingTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\FloatTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\MiscTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ParseTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ReadTests.cs" />
|
||||
<Compile Include="JsonValidatingReaderTests.cs" />
|
||||
<Compile Include="Linq\ComponentModel\BindingTests.cs" />
|
||||
<Compile Include="Linq\ComponentModel\JPropertyDescriptorTests.cs" />
|
||||
@@ -196,6 +201,10 @@
|
||||
<Compile Include="TestObjects\IPrivateImplementationB.cs" />
|
||||
<Compile Include="TestObjects\IPrivateOverriddenImplementation.cs" />
|
||||
<Compile Include="TestObjects\Item.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\FakeArrayPool.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\SlowStream.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\ToggleReaderError.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\UnmanagedResourceFakingJsonReader.cs" />
|
||||
<Compile Include="TestObjects\ListOfIds.cs" />
|
||||
<Compile Include="TestObjects\MetroPropertyNameResolver.cs" />
|
||||
<Compile Include="TestObjects\MetroStringConverter.cs" />
|
||||
@@ -331,7 +340,6 @@
|
||||
<Compile Include="JsonConvertTest.cs" />
|
||||
<Compile Include="Converters\JavaScriptDateTimeConverterTests.cs" />
|
||||
<Compile Include="Serialization\JsonSerializerTest.cs" />
|
||||
<Compile Include="JsonTextReaderTest.cs" />
|
||||
<Compile Include="JsonTextWriterTest.cs" />
|
||||
<Compile Include="Linq\JTokenReaderTest.cs" />
|
||||
<Compile Include="Linq\JTokenWriterTest.cs" />
|
||||
|
||||
@@ -126,6 +126,11 @@
|
||||
</Compile>
|
||||
<Compile Include="JsonArrayAttributeTests.cs" />
|
||||
<Compile Include="ExceptionTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ExceptionHandlingTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\FloatTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\MiscTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ParseTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ReadTests.cs" />
|
||||
<Compile Include="JsonValidatingReaderTests.cs" />
|
||||
<Compile Include="Linq\ComponentModel\BindingTests.cs" />
|
||||
<Compile Include="Linq\ComponentModel\JPropertyDescriptorTests.cs" />
|
||||
@@ -200,6 +205,10 @@
|
||||
<Compile Include="TestObjects\IPrivateImplementationB.cs" />
|
||||
<Compile Include="TestObjects\IPrivateOverriddenImplementation.cs" />
|
||||
<Compile Include="TestObjects\Item.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\FakeArrayPool.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\SlowStream.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\ToggleReaderError.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\UnmanagedResourceFakingJsonReader.cs" />
|
||||
<Compile Include="TestObjects\ListOfIds.cs" />
|
||||
<Compile Include="TestObjects\MetroPropertyNameResolver.cs" />
|
||||
<Compile Include="TestObjects\MetroStringConverter.cs" />
|
||||
@@ -335,7 +344,6 @@
|
||||
<Compile Include="JsonConvertTest.cs" />
|
||||
<Compile Include="Converters\JavaScriptDateTimeConverterTests.cs" />
|
||||
<Compile Include="Serialization\JsonSerializerTest.cs" />
|
||||
<Compile Include="JsonTextReaderTest.cs" />
|
||||
<Compile Include="JsonTextWriterTest.cs" />
|
||||
<Compile Include="Linq\JTokenReaderTest.cs" />
|
||||
<Compile Include="Linq\JTokenWriterTest.cs" />
|
||||
|
||||
@@ -222,7 +222,15 @@
|
||||
<Compile Include="ExceptionTests.cs" />
|
||||
<Compile Include="JsonArrayAttributeTests.cs" />
|
||||
<Compile Include="JsonConvertTest.cs" />
|
||||
<Compile Include="JsonTextReaderTest.cs" />
|
||||
<Compile Include="JsonTextReaderTests\MiscTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ExceptionHandlingTests.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\FakeArrayPool.cs" />
|
||||
<Compile Include="JsonTextReaderTests\FloatTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ParseTests.cs" />
|
||||
<Compile Include="JsonTextReaderTests\ReadTests.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\SlowStream.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\ToggleReaderError.cs" />
|
||||
<Compile Include="TestObjects\JsonTextReaderTests\UnmanagedResourceFakingJsonReader.cs" />
|
||||
<Compile Include="JsonTextWriterTest.cs" />
|
||||
<Compile Include="JsonValidatingReaderTests.cs" />
|
||||
<Compile Include="LinqToSql\Department.cs" />
|
||||
@@ -595,6 +603,7 @@
|
||||
<Name>Newtonsoft.Json</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
#if NET20
|
||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||
#else
|
||||
using System.Linq;
|
||||
#endif
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects.JsonTextReaderTests
|
||||
{
|
||||
public class FakeArrayPool : IArrayPool<char>
|
||||
{
|
||||
public readonly List<char[]> FreeArrays = new List<char[]>();
|
||||
public readonly List<char[]> UsedArrays = new List<char[]>();
|
||||
|
||||
public char[] Rent(int minimumLength)
|
||||
{
|
||||
char[] a = FreeArrays.FirstOrDefault(b => b.Length >= minimumLength);
|
||||
if (a != null)
|
||||
{
|
||||
FreeArrays.Remove(a);
|
||||
UsedArrays.Add(a);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
a = new char[minimumLength];
|
||||
UsedArrays.Add(a);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
public void Return(char[] array)
|
||||
{
|
||||
if (UsedArrays.Remove(array))
|
||||
{
|
||||
FreeArrays.Add(array);
|
||||
|
||||
// smallest first so the first array large enough is rented
|
||||
FreeArrays.Sort((b1, b2) => Comparer<int>.Default.Compare(b1.Length, b2.Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects.JsonTextReaderTests
|
||||
{
|
||||
public class SlowStream : Stream
|
||||
{
|
||||
private byte[] bytes;
|
||||
private int totalBytesRead;
|
||||
private int bytesPerRead;
|
||||
|
||||
public SlowStream(byte[] content, int bytesPerRead)
|
||||
{
|
||||
bytes = content;
|
||||
totalBytesRead = 0;
|
||||
this.bytesPerRead = bytesPerRead;
|
||||
}
|
||||
|
||||
public SlowStream(string content, Encoding encoding, int bytesPerRead)
|
||||
: this(encoding.GetBytes(content), bytesPerRead)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int toReturn = Math.Min(count, bytesPerRead);
|
||||
toReturn = Math.Min(toReturn, bytes.Length - totalBytesRead);
|
||||
if (toReturn > 0)
|
||||
{
|
||||
Array.Copy(bytes, totalBytesRead, buffer, offset, toReturn);
|
||||
}
|
||||
|
||||
totalBytesRead += toReturn;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects.JsonTextReaderTests
|
||||
{
|
||||
public class ToggleReaderError : TextReader
|
||||
{
|
||||
private readonly TextReader _inner;
|
||||
|
||||
public bool Error { get; set; }
|
||||
|
||||
public ToggleReaderError(TextReader inner)
|
||||
{
|
||||
_inner = inner;
|
||||
}
|
||||
|
||||
public override int Read(char[] buffer, int index, int count)
|
||||
{
|
||||
if (Error)
|
||||
{
|
||||
throw new Exception("Read error");
|
||||
}
|
||||
|
||||
return _inner.Read(buffer, index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.TestObjects.JsonTextReaderTests
|
||||
{
|
||||
public class UnmanagedResourceFakingJsonReader : JsonReader
|
||||
{
|
||||
public static int DisposalCalls;
|
||||
|
||||
public static void CreateAndDispose()
|
||||
{
|
||||
((IDisposable)new UnmanagedResourceFakingJsonReader()).Dispose();
|
||||
}
|
||||
|
||||
public UnmanagedResourceFakingJsonReader()
|
||||
{
|
||||
DisposalCalls = 0;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
++DisposalCalls;
|
||||
}
|
||||
|
||||
~UnmanagedResourceFakingJsonReader()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public override bool Read()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override byte[] ReadAsBytes()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override DateTime? ReadAsDateTime()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
public override DateTimeOffset? ReadAsDateTimeOffset()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endif
|
||||
|
||||
public override decimal? ReadAsDecimal()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override int? ReadAsInt32()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override string ReadAsString()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user