diff --git a/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs b/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs new file mode 100644 index 000000000..5d0556954 --- /dev/null +++ b/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs @@ -0,0 +1,38 @@ +using NUnit.Framework; + +namespace UniJSON +{ + public class SerializeWithSchemaTests + { + [JsonSchema(Title="CheckConstraintsTest")] + public class CheckConstraintsTest + { + [JsonSchema(Minimum = 0)] + public int X; + + [JsonSchema(Minimum = 10)] // Not required, thus ignored when the value violates the constraints + public int Y; + } + + [Test] + public void TestCheckConstraints() + { + var obj = new CheckConstraintsTest() + { + X = 0, + Y = 0, // Will be excluded because 0 doesn't satisfy a requirement of "Minimum = 10" + }; + + var s = JsonSchema.FromType(); + { + var c = new JsonSchemaValidationContext(obj); + Assert.Null(s.Validator.Validate(c, s)); + } + var actual = s.Serialize(obj); + + var expected = @"{""X"":0}"; + + Assert.AreEqual(expected, actual); + } + } +} diff --git a/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs.meta b/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs.meta new file mode 100644 index 000000000..b0c9e7173 --- /dev/null +++ b/Assets/VRM/UniJSON/Editor/Tests/Json/SerializeWithSchemaTests.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f1d1c3d9d4d20db409e9d5d9d671abbe +timeCreated: 1546930461 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: