aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf.Test/JsonParserTest.cs
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2015-11-04 11:49:15 +0000
committerGravatar Jon Skeet <jonskeet@google.com>2015-11-05 10:40:22 +0000
commit0fb39c4afee919eb7c2e5e6c5a254cb2ddcda724 (patch)
tree0b66d171c953994cb2289006fe54241bd81396fa /csharp/src/Google.Protobuf.Test/JsonParserTest.cs
parentb6a32e909b1f58f157c19276af233e44627093f4 (diff)
Created a new exception for JSON failures.
This is only thrown directly by JsonTokenizer, but surfaces from JsonParser as well. I've added doc comments to hopefully make everything clear. The exception is actually thrown by the reader within JsonTokenizer, in anticipation of keeping track of the location within the document, but that change is not within this PR.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/JsonParserTest.cs')
-rw-r--r--csharp/src/Google.Protobuf.Test/JsonParserTest.cs44
1 files changed, 22 insertions, 22 deletions
diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs
index b1c7b46c..29b3088c 100644
--- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs
+++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs
@@ -370,19 +370,19 @@ namespace Google.Protobuf
}
[Test]
- [TestCase("+0")]
- [TestCase("00")]
- [TestCase("-00")]
- [TestCase("--1")]
- [TestCase("+1")]
- [TestCase("1.5", Ignore = true, Reason = "Desired behaviour unclear")]
- [TestCase("1e10")]
- [TestCase("2147483648")]
- [TestCase("-2147483649")]
- public void NumberToInt32_Invalid(string jsonValue)
+ [TestCase("+0", typeof(InvalidJsonException))]
+ [TestCase("00", typeof(InvalidJsonException))]
+ [TestCase("-00", typeof(InvalidJsonException))]
+ [TestCase("--1", typeof(InvalidJsonException))]
+ [TestCase("+1", typeof(InvalidJsonException))]
+ [TestCase("1.5", typeof(InvalidProtocolBufferException), Ignore = true, Reason = "Desired behaviour unclear")]
+ [TestCase("1e10", typeof(InvalidProtocolBufferException))]
+ [TestCase("2147483648", typeof(InvalidProtocolBufferException))]
+ [TestCase("-2147483649", typeof(InvalidProtocolBufferException))]
+ public void NumberToInt32_Invalid(string jsonValue, System.Type expectedExceptionType)
{
string json = "{ \"singleInt32\": " + jsonValue + "}";
- Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ Assert.Throws(expectedExceptionType, () => TestAllTypes.Parser.ParseJson(json));
}
[Test]
@@ -486,7 +486,7 @@ namespace Google.Protobuf
public void NumberToDouble_Invalid(string jsonValue)
{
string json = "{ \"singleDouble\": " + jsonValue + "}";
- Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ Assert.Throws<InvalidJsonException>(() => TestAllTypes.Parser.ParseJson(json));
}
[Test]
@@ -506,17 +506,17 @@ namespace Google.Protobuf
}
[Test]
- [TestCase("3.402824e38")]
- [TestCase("-3.402824e38")]
- [TestCase("1,0")]
- [TestCase("1.0.0")]
- [TestCase("+1")]
- [TestCase("00")]
- [TestCase("--1")]
- public void NumberToFloat_Invalid(string jsonValue)
+ [TestCase("3.402824e38", typeof(InvalidProtocolBufferException))]
+ [TestCase("-3.402824e38", typeof(InvalidProtocolBufferException))]
+ [TestCase("1,0", typeof(InvalidJsonException))]
+ [TestCase("1.0.0", typeof(InvalidJsonException))]
+ [TestCase("+1", typeof(InvalidJsonException))]
+ [TestCase("00", typeof(InvalidJsonException))]
+ [TestCase("--1", typeof(InvalidJsonException))]
+ public void NumberToFloat_Invalid(string jsonValue, System.Type expectedExceptionType)
{
string json = "{ \"singleFloat\": " + jsonValue + "}";
- Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ Assert.Throws(expectedExceptionType, () => TestAllTypes.Parser.ParseJson(json));
}
// The simplest way of testing that the value has parsed correctly is to reformat it,
@@ -721,7 +721,7 @@ namespace Google.Protobuf
public void DataAfterObject()
{
string json = "{} 10";
- Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ Assert.Throws<InvalidJsonException>(() => TestAllTypes.Parser.ParseJson(json));
}
}
}