Commit 7ea1d04a authored by Michael Lee's avatar Michael Lee Committed by Facebook Github Bot 3

Fix use of dynamic {} initialization in JSONSchemaTest

Summary: find replace 's/{([0-9, a-z"-]+)}/dynamic::array(\1)/g'

Reviewed By: agoder

Differential Revision: D3203454

fb-gh-sync-id: 064bb2bdd0e19a80da32e8f4eb730fc4268d7cad
fbshipit-source-id: 064bb2bdd0e19a80da32e8f4eb730fc4268d7cad
parent bc9d9e8c
...@@ -157,56 +157,59 @@ TEST(JSONSchemaTest, TestStringPattern) { ...@@ -157,56 +157,59 @@ TEST(JSONSchemaTest, TestStringPattern) {
TEST(JSONSchemaTest, TestMinimumArrayItems) { TEST(JSONSchemaTest, TestMinimumArrayItems) {
dynamic schema = dynamic::object("minItems", 3); dynamic schema = dynamic::object("minItems", 3);
ASSERT_TRUE(check(schema, {1, 2, 3, 4, 5})); ASSERT_TRUE(check(schema, dynamic::array(1, 2, 3, 4, 5)));
ASSERT_TRUE(check(schema, {1, 2, 3})); ASSERT_TRUE(check(schema, dynamic::array(1, 2, 3)));
ASSERT_FALSE(check(schema, {1})); ASSERT_FALSE(check(schema, dynamic::array(1)));
} }
TEST(JSONSchemaTest, TestMaximumArrayItems) { TEST(JSONSchemaTest, TestMaximumArrayItems) {
dynamic schema = dynamic::object("maxItems", 3); dynamic schema = dynamic::object("maxItems", 3);
ASSERT_FALSE(check(schema, {1, 2, 3, 4, 5})); ASSERT_FALSE(check(schema, dynamic::array(1, 2, 3, 4, 5)));
ASSERT_TRUE(check(schema, {1, 2, 3})); ASSERT_TRUE(check(schema, dynamic::array(1, 2, 3)));
ASSERT_TRUE(check(schema, {1})); ASSERT_TRUE(check(schema, dynamic::array(1)));
ASSERT_TRUE(check(schema, "foobar")); ASSERT_TRUE(check(schema, "foobar"));
} }
TEST(JSONSchemaTest, TestArrayUniqueItems) { TEST(JSONSchemaTest, TestArrayUniqueItems) {
dynamic schema = dynamic::object("uniqueItems", true); dynamic schema = dynamic::object("uniqueItems", true);
ASSERT_TRUE(check(schema, {1, 2, 3})); ASSERT_TRUE(check(schema, dynamic::array(1, 2, 3)));
ASSERT_FALSE(check(schema, {1, 2, 3, 1})); ASSERT_FALSE(check(schema, dynamic::array(1, 2, 3, 1)));
ASSERT_FALSE(check(schema, {"cat", "dog", 1, 2, "cat"})); ASSERT_FALSE(check(schema, dynamic::array("cat", "dog", 1, 2, "cat")));
ASSERT_TRUE(check(schema, { ASSERT_TRUE(check(
dynamic::object("foo", "bar"), schema,
dynamic::object("foo", "baz") dynamic::array(
})); dynamic::object("foo", "bar"), dynamic::object("foo", "baz"))));
schema = dynamic::object("uniqueItems", false); schema = dynamic::object("uniqueItems", false);
ASSERT_TRUE(check(schema, {1, 2, 3, 1})); ASSERT_TRUE(check(schema, dynamic::array(1, 2, 3, 1)));
} }
TEST(JSONSchemaTest, TestArrayItems) { TEST(JSONSchemaTest, TestArrayItems) {
dynamic schema = dynamic::object("items", dynamic::object("minimum", 2)); dynamic schema = dynamic::object("items", dynamic::object("minimum", 2));
ASSERT_TRUE(check(schema, {2, 3, 4})); ASSERT_TRUE(check(schema, dynamic::array(2, 3, 4)));
ASSERT_FALSE(check(schema, {3, 4, 1})); ASSERT_FALSE(check(schema, dynamic::array(3, 4, 1)));
} }
TEST(JSONSchemaTest, TestArrayAdditionalItems) { TEST(JSONSchemaTest, TestArrayAdditionalItems) {
dynamic schema = dynamic::object( dynamic schema = dynamic::object(
"items", {dynamic::object("minimum", 2), dynamic::object("minimum", 1)})( "items",
dynamic::array(
dynamic::object("minimum", 2), dynamic::object("minimum", 1)))(
"additionalItems", dynamic::object("minimum", 3)); "additionalItems", dynamic::object("minimum", 3));
ASSERT_TRUE(check(schema, {2, 1, 3, 3, 3, 3, 4})); ASSERT_TRUE(check(schema, dynamic::array(2, 1, 3, 3, 3, 3, 4)));
ASSERT_FALSE(check(schema, {2, 1, 3, 3, 3, 3, 1})); ASSERT_FALSE(check(schema, dynamic::array(2, 1, 3, 3, 3, 3, 1)));
} }
TEST(JSONSchemaTest, TestArrayNoAdditionalItems) { TEST(JSONSchemaTest, TestArrayNoAdditionalItems) {
dynamic schema = dynamic::object("items", {dynamic::object("minimum", 2)})( dynamic schema =
dynamic::object("items", dynamic::array(dynamic::object("minimum", 2)))(
"additionalItems", false); "additionalItems", false);
ASSERT_FALSE(check(schema, {3, 3, 3})); ASSERT_FALSE(check(schema, dynamic::array(3, 3, 3)));
} }
TEST(JSONSchemaTest, TestArrayItemsNotPresent) { TEST(JSONSchemaTest, TestArrayItemsNotPresent) {
dynamic schema = dynamic::object("additionalItems", false); dynamic schema = dynamic::object("additionalItems", false);
ASSERT_TRUE(check(schema, {3, 3, 3})); ASSERT_TRUE(check(schema, dynamic::array(3, 3, 3)));
} }
TEST(JSONSchemaTest, TestRef) { TEST(JSONSchemaTest, TestRef) {
...@@ -215,8 +218,8 @@ TEST(JSONSchemaTest, TestRef) { ...@@ -215,8 +218,8 @@ TEST(JSONSchemaTest, TestRef) {
dynamic::object("positiveInteger", dynamic::object("positiveInteger",
dynamic::object("minimum", 1)("type", "integer")))( dynamic::object("minimum", 1)("type", "integer")))(
"items", dynamic::object("$ref", "#/definitions/positiveInteger")); "items", dynamic::object("$ref", "#/definitions/positiveInteger"));
ASSERT_TRUE(check(schema, {1, 2, 3, 4})); ASSERT_TRUE(check(schema, dynamic::array(1, 2, 3, 4)));
ASSERT_FALSE(check(schema, {4, -5})); ASSERT_FALSE(check(schema, dynamic::array(4, -5)));
} }
TEST(JSONSchemaTest, TestRecursiveRef) { TEST(JSONSchemaTest, TestRecursiveRef) {
...@@ -250,11 +253,11 @@ TEST(JSONSchemaTest, TestDoubleRecursiveRef) { ...@@ -250,11 +253,11 @@ TEST(JSONSchemaTest, TestDoubleRecursiveRef) {
TEST(JSONSchemaTest, TestInfinitelyRecursiveRef) { TEST(JSONSchemaTest, TestInfinitelyRecursiveRef) {
dynamic schema = dynamic::object("not", dynamic::object("$ref", "#")); dynamic schema = dynamic::object("not", dynamic::object("$ref", "#"));
auto validator = makeValidator(schema); auto validator = makeValidator(schema);
ASSERT_THROW(validator->validate({1, 2}), std::runtime_error); ASSERT_THROW(validator->validate(dynamic::array(1, 2)), std::runtime_error);
} }
TEST(JSONSchemaTest, TestRequired) { TEST(JSONSchemaTest, TestRequired) {
dynamic schema = dynamic::object("required", {"foo", "bar"}); dynamic schema = dynamic::object("required", dynamic::array("foo", "bar"));
ASSERT_FALSE(check(schema, dynamic::object("foo", 123))); ASSERT_FALSE(check(schema, dynamic::object("foo", 123)));
ASSERT_FALSE(check(schema, dynamic::object("bar", 123))); ASSERT_FALSE(check(schema, dynamic::object("bar", 123)));
ASSERT_TRUE(check(schema, dynamic::object("bar", 123)("foo", 456))); ASSERT_TRUE(check(schema, dynamic::object("bar", 123)("foo", 456)));
...@@ -296,8 +299,8 @@ TEST(JSONSchemaTest, TestPropertyAndPattern) { ...@@ -296,8 +299,8 @@ TEST(JSONSchemaTest, TestPropertyAndPattern) {
} }
TEST(JSONSchemaTest, TestPropertyDependency) { TEST(JSONSchemaTest, TestPropertyDependency) {
dynamic schema = dynamic schema = dynamic::object(
dynamic::object("dependencies", dynamic::object("p1", {"p2"})); "dependencies", dynamic::object("p1", dynamic::array("p2")));
ASSERT_TRUE(check(schema, dynamic::object)); ASSERT_TRUE(check(schema, dynamic::object));
ASSERT_TRUE(check(schema, dynamic::object("p1", 1)("p2", 1))); ASSERT_TRUE(check(schema, dynamic::object("p1", 1)("p2", 1)));
ASSERT_FALSE(check(schema, dynamic::object("p1", 1))); ASSERT_FALSE(check(schema, dynamic::object("p1", 1)));
...@@ -306,14 +309,14 @@ TEST(JSONSchemaTest, TestPropertyDependency) { ...@@ -306,14 +309,14 @@ TEST(JSONSchemaTest, TestPropertyDependency) {
TEST(JSONSchemaTest, TestSchemaDependency) { TEST(JSONSchemaTest, TestSchemaDependency) {
dynamic schema = dynamic::object( dynamic schema = dynamic::object(
"dependencies", "dependencies",
dynamic::object("p1", dynamic::object("required", {"p2"}))); dynamic::object("p1", dynamic::object("required", dynamic::array("p2"))));
ASSERT_TRUE(check(schema, dynamic::object)); ASSERT_TRUE(check(schema, dynamic::object));
ASSERT_TRUE(check(schema, dynamic::object("p1", 1)("p2", 1))); ASSERT_TRUE(check(schema, dynamic::object("p1", 1)("p2", 1)));
ASSERT_FALSE(check(schema, dynamic::object("p1", 1))); ASSERT_FALSE(check(schema, dynamic::object("p1", 1)));
} }
TEST(JSONSchemaTest, TestEnum) { TEST(JSONSchemaTest, TestEnum) {
dynamic schema = dynamic::object("enum", {"a", 1}); dynamic schema = dynamic::object("enum", dynamic::array("a", 1));
ASSERT_TRUE(check(schema, "a")); ASSERT_TRUE(check(schema, "a"));
ASSERT_TRUE(check(schema, 1)); ASSERT_TRUE(check(schema, 1));
ASSERT_FALSE(check(schema, "b")); ASSERT_FALSE(check(schema, "b"));
...@@ -326,7 +329,7 @@ TEST(JSONSchemaTest, TestType) { ...@@ -326,7 +329,7 @@ TEST(JSONSchemaTest, TestType) {
} }
TEST(JSONSchemaTest, TestTypeArray) { TEST(JSONSchemaTest, TestTypeArray) {
dynamic schema = dynamic::object("type", {"array", "number"}); dynamic schema = dynamic::object("type", dynamic::array("array", "number"));
ASSERT_TRUE(check(schema, dynamic(5))); ASSERT_TRUE(check(schema, dynamic(5)));
ASSERT_TRUE(check(schema, dynamic(1.1))); ASSERT_TRUE(check(schema, dynamic(1.1)));
ASSERT_FALSE(check(schema, dynamic::object)); ASSERT_FALSE(check(schema, dynamic::object));
...@@ -335,7 +338,8 @@ TEST(JSONSchemaTest, TestTypeArray) { ...@@ -335,7 +338,8 @@ TEST(JSONSchemaTest, TestTypeArray) {
TEST(JSONSchemaTest, TestAllOf) { TEST(JSONSchemaTest, TestAllOf) {
dynamic schema = dynamic::object( dynamic schema = dynamic::object(
"allOf", "allOf",
{dynamic::object("minimum", 1), dynamic::object("type", "integer")}); dynamic::array(
dynamic::object("minimum", 1), dynamic::object("type", "integer")));
ASSERT_TRUE(check(schema, 2)); ASSERT_TRUE(check(schema, 2));
ASSERT_FALSE(check(schema, 0)); ASSERT_FALSE(check(schema, 0));
ASSERT_FALSE(check(schema, 1.1)); ASSERT_FALSE(check(schema, 1.1));
...@@ -344,7 +348,8 @@ TEST(JSONSchemaTest, TestAllOf) { ...@@ -344,7 +348,8 @@ TEST(JSONSchemaTest, TestAllOf) {
TEST(JSONSchemaTest, TestAnyOf) { TEST(JSONSchemaTest, TestAnyOf) {
dynamic schema = dynamic::object( dynamic schema = dynamic::object(
"anyOf", "anyOf",
{dynamic::object("minimum", 1), dynamic::object("type", "integer")}); dynamic::array(
dynamic::object("minimum", 1), dynamic::object("type", "integer")));
ASSERT_TRUE(check(schema, 2)); // matches both ASSERT_TRUE(check(schema, 2)); // matches both
ASSERT_FALSE(check(schema, 0.1)); // matches neither ASSERT_FALSE(check(schema, 0.1)); // matches neither
ASSERT_TRUE(check(schema, 1.1)); // matches first one ASSERT_TRUE(check(schema, 1.1)); // matches first one
...@@ -354,7 +359,8 @@ TEST(JSONSchemaTest, TestAnyOf) { ...@@ -354,7 +359,8 @@ TEST(JSONSchemaTest, TestAnyOf) {
TEST(JSONSchemaTest, TestOneOf) { TEST(JSONSchemaTest, TestOneOf) {
dynamic schema = dynamic::object( dynamic schema = dynamic::object(
"oneOf", "oneOf",
{dynamic::object("minimum", 1), dynamic::object("type", "integer")}); dynamic::array(
dynamic::object("minimum", 1), dynamic::object("type", "integer")));
ASSERT_FALSE(check(schema, 2)); // matches both ASSERT_FALSE(check(schema, 2)); // matches both
ASSERT_FALSE(check(schema, 0.1)); // matches neither ASSERT_FALSE(check(schema, 0.1)); // matches neither
ASSERT_TRUE(check(schema, 1.1)); // matches first one ASSERT_TRUE(check(schema, 1.1)); // matches first one
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment