Skip to content

Commit

Permalink
Move test for standalone BoolValue to JsonParserTest
Browse files Browse the repository at this point in the history
Also added a standalone formatter test, for confidence.
Have validated that undoing the change in 835fb94 breaks the tests
(i.e. we are still testing that the change is required).
  • Loading branch information
jskeet committed May 11, 2016
1 parent cca2d44 commit 7cc9cb4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
16 changes: 16 additions & 0 deletions csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,22 @@ public void AnyUnknownType()
Assert.Throws<InvalidOperationException>(() => JsonFormatter.Default.Format(any));
}

[Test]
[TestCase(typeof(BoolValue), true, "true")]
[TestCase(typeof(Int32Value), 32, "32")]
[TestCase(typeof(Int64Value), 32L, "\"32\"")]
[TestCase(typeof(UInt32Value), 32U, "32")]
[TestCase(typeof(UInt64Value), 32UL, "\"32\"")]
[TestCase(typeof(StringValue), "foo", "\"foo\"")]
[TestCase(typeof(FloatValue), 1.5f, "1.5")]
[TestCase(typeof(DoubleValue), 1.5d, "1.5")]
public void Wrappers_Standalone(System.Type wrapperType, object value, string expectedJson)
{
IMessage populated = (IMessage)Activator.CreateInstance(wrapperType);
populated.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber].Accessor.SetValue(populated, value);
Assert.AreEqual(expectedJson, JsonFormatter.Default.Format(populated));
}

/// <summary>
/// Checks that the actual JSON is the same as the expected JSON - but after replacing
/// all apostrophes in the expected JSON with double quotes. This basically makes the tests easier
Expand Down
3 changes: 3 additions & 0 deletions csharp/src/Google.Protobuf.Test/JsonParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ public void SingularWrappers_ExplicitNulls()
}

[Test]
[TestCase(typeof(BoolValue), "true", true)]
[TestCase(typeof(Int32Value), "32", 32)]
[TestCase(typeof(Int64Value), "32", 32L)]
[TestCase(typeof(Int64Value), "\"32\"", 32L)]
[TestCase(typeof(UInt32Value), "32", 32U)]
[TestCase(typeof(UInt64Value), "\"32\"", 32UL)]
[TestCase(typeof(UInt64Value), "32", 32UL)]
[TestCase(typeof(StringValue), "\"foo\"", "foo")]
[TestCase(typeof(FloatValue), "1.5", 1.5f)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,5 @@ public void ClearWithReflection()
TestWellKnownTypes.Descriptor.Fields[TestWellKnownTypes.StringFieldFieldNumber].Accessor.Clear(message);
Assert.IsNull(message.StringField);
}

[Test]
public void GivenBoolValueWhenPerformingRoundTripEncodingViaJsonThenShouldNotExpectObjectAtTopLevel()
{
var value = new BoolValue { Value = true };
Assert.AreEqual(value, JsonParser.Default.Parse<BoolValue>(JsonFormatter.Default.Format(value)));
}
}
}

0 comments on commit 7cc9cb4

Please sign in to comment.