This commit is contained in:
James Newton-King
2016-01-09 08:38:43 +13:00
parent 70120ce077
commit 7b79ef5bf6
2 changed files with 83 additions and 3 deletions
@@ -2090,6 +2090,15 @@ third line", jsonTextReader.Value);
}
#endif
[Test]
public void ReadAsBooleanNoContent()
{
JsonTextReader reader = new JsonTextReader(new StringReader(@""));
Assert.IsNull(reader.ReadAsBoolean());
Assert.AreEqual(JsonToken.None, reader.TokenType);
}
[Test]
public void ReadAsDecimalBadContent()
{
@@ -3585,6 +3594,77 @@ null//comment
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBoolean(); }, "Unexpected end when reading JSON. Path '', line 1, position 3.");
}
[Test]
public void ReadAsBoolean_NullChar()
{
string json = '\0' + @"true" + '\0' + '\0';
JsonTextReader reader = new JsonTextReader(new StringReader(json));
Assert.AreEqual(true, reader.ReadAsBoolean());
Assert.AreEqual(null, reader.ReadAsBoolean());
}
[Test]
public void ReadAsBoolean_BadData()
{
string json = @"pie";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBoolean(); }, "Unexpected character encountered while parsing value: p. Path '', line 1, position 1.");
}
[Test]
public void ReadAsString_BadData()
{
string json = @"pie";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsString(); }, "Unexpected character encountered while parsing value: p. Path '', line 1, position 1.");
}
[Test]
public void ReadAsDouble_BadData()
{
string json = @"pie";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsDouble(); }, "Unexpected character encountered while parsing value: p. Path '', line 1, position 1.");
}
[Test]
public void ReadAsDouble_Boolean()
{
string json = @"true";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsDouble(); }, "Unexpected character encountered while parsing value: t. Path '', line 1, position 1.");
}
[Test]
public void ReadAsBytes_BadData()
{
string json = @"pie";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBytes(); }, "Unexpected character encountered while parsing value: p. Path '', line 1, position 1.");
}
[Test]
public void ReadAsDateTime_BadData()
{
string json = @"pie";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsDateTime(); }, "Unexpected character encountered while parsing value: p. Path '', line 1, position 1.");
}
[Test]
public void ReadAsDateTime_Boolean()
{