diff options
author | Jon Skeet <jonskeet@google.com> | 2015-11-04 11:49:15 +0000 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2015-11-05 10:40:22 +0000 |
commit | 0fb39c4afee919eb7c2e5e6c5a254cb2ddcda724 (patch) | |
tree | 0b66d171c953994cb2289006fe54241bd81396fa /csharp/src/Google.Protobuf.Test | |
parent | b6a32e909b1f58f157c19276af233e44627093f4 (diff) | |
download | protobuf-0fb39c4afee919eb7c2e5e6c5a254cb2ddcda724.tar.gz protobuf-0fb39c4afee919eb7c2e5e6c5a254cb2ddcda724.tar.bz2 protobuf-0fb39c4afee919eb7c2e5e6c5a254cb2ddcda724.zip |
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')
-rw-r--r-- | csharp/src/Google.Protobuf.Test/JsonParserTest.cs | 44 | ||||
-rw-r--r-- | csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs | 4 |
2 files changed, 24 insertions, 24 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)); } } } diff --git a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs index 868d9f75..1b3c8e9f 100644 --- a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs @@ -223,7 +223,7 @@ namespace Google.Protobuf { Assert.IsNotNull(tokenizer.Next()); } - Assert.Throws<InvalidProtocolBufferException>(() => tokenizer.Next()); + Assert.Throws<InvalidJsonException>(() => tokenizer.Next()); } [Test] @@ -346,7 +346,7 @@ namespace Google.Protobuf } Assert.AreEqual(expectedTokens[i], actualToken); } - Assert.Throws<InvalidProtocolBufferException>(() => tokenizer.Next()); + Assert.Throws<InvalidJsonException>(() => tokenizer.Next()); } } } |