aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2017-10-24 11:44:44 +0100
committerGravatar Jon Skeet <skeet@pobox.com>2017-10-28 07:47:43 +0100
commita9854512532a42c174e1aa496d4bfe05b04645d0 (patch)
tree43523c645c4256fb37a5d86f4e41aa2672ac0ee9 /csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
parent4526d8baa0fe1c866adab8066e59d15996c25d02 (diff)
Add JsonParser setting to ignore unknown field values
Note that the default behavior is still to throw an exception; you need to opt into ignoring unknown fields. Fixes #2838.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs')
-rw-r--r--csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
index 527ab336..33d35036 100644
--- a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
+++ b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
@@ -349,6 +349,22 @@ namespace Google.Protobuf
Assert.AreEqual(JsonToken.EndDocument, tokenizer.Next());
Assert.Throws<InvalidOperationException>(() => tokenizer.Next());
}
+
+ [Test]
+ [TestCase("{ 'skip': 0, 'next': 1")]
+ [TestCase("{ 'skip': [0, 1, 2], 'next': 1")]
+ [TestCase("{ 'skip': 'x', 'next': 1")]
+ [TestCase("{ 'skip': ['x', 'y'], 'next': 1")]
+ [TestCase("{ 'skip': {'a': 0}, 'next': 1")]
+ [TestCase("{ 'skip': {'a': [0, {'b':[]}]}, 'next': 1")]
+ public void SkipValue(string json)
+ {
+ var tokenizer = JsonTokenizer.FromTextReader(new StringReader(json.Replace('\'', '"')));
+ Assert.AreEqual(JsonToken.StartObject, tokenizer.Next());
+ Assert.AreEqual("skip", tokenizer.Next().StringValue);
+ tokenizer.SkipValue();
+ Assert.AreEqual("next", tokenizer.Next().StringValue);
+ }
/// <summary>
/// Asserts that the specified JSON is tokenized into the given sequence of tokens.