mirror of
https://github.com/tristanpenman/valijson.git
synced 2025-01-09 19:17:38 +01:00
Add test case for circular references in schemas
This commit is contained in:
parent
0a15cf4fe9
commit
db04461018
8
tests/data/schemas/circular_reference.schema.json
Normal file
8
tests/data/schemas/circular_reference.schema.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"description": "Circular reference when parsing properties keyword",
|
||||
"properties": {
|
||||
"foo": {"$ref": "#/properties/bar"},
|
||||
"bar": {"$ref": "#/properties/baz"},
|
||||
"baz": {"$ref": "#/properties/foo"}
|
||||
}
|
||||
}
|
@ -3,11 +3,18 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <valijson/internal/json_pointer.hpp>
|
||||
|
||||
#include <valijson/adapters/rapidjson_adapter.hpp>
|
||||
#include <valijson/schema.hpp>
|
||||
#include <valijson/schema_parser.hpp>
|
||||
#include <valijson/utils/rapidjson_utils.hpp>
|
||||
|
||||
#define TEST_DATA_DIR "../tests/data"
|
||||
|
||||
using valijson::adapters::RapidJsonAdapter;
|
||||
using valijson::internal::json_pointer::resolveJsonPointer;
|
||||
using valijson::utils::loadDocument;
|
||||
using valijson::Schema;
|
||||
using valijson::SchemaParser;
|
||||
|
||||
typedef rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> RapidJsonCrtAllocator;
|
||||
|
||||
@ -307,3 +314,16 @@ TEST_F(TestJsonPointer, JsonPointerTestCases)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TestJsonPointer, CircularReferences)
|
||||
{
|
||||
// Load schema document
|
||||
rapidjson::Document schemaDocument;
|
||||
ASSERT_TRUE( loadDocument(TEST_DATA_DIR "/schemas/circular_reference.schema.json", schemaDocument) );
|
||||
RapidJsonAdapter schemaAdapter(schemaDocument);
|
||||
|
||||
// Attempt to parse schema
|
||||
Schema schema;
|
||||
SchemaParser parser;
|
||||
EXPECT_THROW(parser.populateSchema(schemaAdapter, schema), std::runtime_error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user