|
|
@@ -136,6 +136,74 @@ TEST(Annotation, AttachesAlwaysFalseSensibly) {
|
|
|
EXPECT_THAT(result, ErrorAt("/A"_jptr, "/properties/A"_jptr, "", "always false"));
|
|
|
}
|
|
|
|
|
|
+TEST(Annotation, IfThenCanGiveABecauseReason) {
|
|
|
+ auto const schema = R"({
|
|
|
+ "if": {
|
|
|
+ "properties": {
|
|
|
+ "A": { "const": true }
|
|
|
+ },
|
|
|
+ "required": [ "A" ]
|
|
|
+ },
|
|
|
+ "then": {
|
|
|
+ "properties": {
|
|
|
+ "B": { "multipleOf": 3 }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "else": {
|
|
|
+ "properties": {
|
|
|
+ "B": { "multipleOf": 5 }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })"_json;
|
|
|
+
|
|
|
+ auto const instance = R"({
|
|
|
+ "A": true,
|
|
|
+ "B": 4
|
|
|
+ })"_json;
|
|
|
+
|
|
|
+ jvalidate::ValidationResult result = validate(schema, instance);
|
|
|
+
|
|
|
+ EXPECT_THAT(result,
|
|
|
+ ErrorAt(""_jptr, "/if"_jptr, "required", "contains all required properties A"));
|
|
|
+ EXPECT_THAT(result, ErrorAt("/A"_jptr, "/if/properties/A"_jptr, "const", "matches value"));
|
|
|
+ EXPECT_THAT(result, ErrorAt("/B"_jptr, "/then/properties/B"_jptr, "multipleOf",
|
|
|
+ "4 is not a multiple of 3"));
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Annotation, IfElseCanGiveABecauseReason) {
|
|
|
+ auto const schema = R"({
|
|
|
+ "if": {
|
|
|
+ "properties": {
|
|
|
+ "A": { "const": true }
|
|
|
+ },
|
|
|
+ "required": [ "A" ]
|
|
|
+ },
|
|
|
+ "then": {
|
|
|
+ "properties": {
|
|
|
+ "B": { "multipleOf": 3 }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "else": {
|
|
|
+ "properties": {
|
|
|
+ "B": { "multipleOf": 5 }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })"_json;
|
|
|
+
|
|
|
+ auto const instance = R"({
|
|
|
+ "A": false,
|
|
|
+ "B": 4
|
|
|
+ })"_json;
|
|
|
+
|
|
|
+ jvalidate::ValidationResult result = validate(schema, instance);
|
|
|
+
|
|
|
+ EXPECT_THAT(result,
|
|
|
+ ErrorAt(""_jptr, "/if"_jptr, "required", "contains all required properties A"));
|
|
|
+ EXPECT_THAT(result, ErrorAt("/A"_jptr, "/if/properties/A"_jptr, "const", "true was expected"));
|
|
|
+ EXPECT_THAT(result, ErrorAt("/B"_jptr, "/else/properties/B"_jptr, "multipleOf",
|
|
|
+ "4 is not a multiple of 5"));
|
|
|
+}
|
|
|
+
|
|
|
int main(int argc, char ** argv) {
|
|
|
testing::InitGoogleMock(&argc, argv);
|
|
|
return RUN_ALL_TESTS();
|