Improve PicoJSON format test example

This commit is contained in:
Tristan Penman 2023-08-24 20:40:00 +10:00
parent cd9258c241
commit 0530af0709

View File

@ -26,7 +26,12 @@ constexpr auto schemaStr = R"JSON({
"type": "array"
})JSON";
constexpr auto targetStr = R"JSON([
constexpr auto validStr = R"JSON([
"2023-07-18T14:46:22Z",
"2023-07-18T14:46:22Z"
])JSON";
constexpr auto invalidStr = R"JSON([
["um 12", "um 12"],
["2023-07-18T14:46:22Z"],
["2023-07-18T14:46:22Z", "2023-07-18T14:46:22Z", "2023-07-18T14:46:22Z", "2023-07-18T14:46:22Z"]
@ -54,21 +59,39 @@ int main(int argc, char **argv)
auto schemaAdapter = valijson::adapters::PicoJsonAdapter(schemaJson);
valijson::SchemaParser parser;
parser.populateSchema(schemaAdapter, *validatorSchema);
std::cout << "Schema:" << std::endl << schemaStr << std::endl;
std::cout << "Schema:" << std::endl << schemaStr << std::endl << std::endl;;
}
auto targetJson = Parse(targetStr, picojson::value{});
{
// valid
auto targetJson = Parse(validStr, picojson::value{});
auto targetAdapter = valijson::adapters::PicoJsonAdapter(targetJson);
std::cout << "Target:" << std::endl << targetStr << std::endl;
std::cout << "Valid Target:" << std::endl << validStr << std::endl << std::endl;
valijson::ValidationResults results;
auto validator = valijson::Validator();
[[maybe_unused]] auto isValid = validator.validate(
auto isValid = validator.validate(
*validatorSchema,
targetAdapter,
&results);
std::cout << "Is valid: " << (isValid ? "YES" : "NO") << std::endl;
std::cout << "Is valid: " << (isValid ? "YES" : "NO") << std::endl << std::endl;;
}
{
// invalid
auto targetJson = Parse(invalidStr, picojson::value{});
auto targetAdapter = valijson::adapters::PicoJsonAdapter(targetJson);
std::cout << "Invalid Target:" << std::endl << invalidStr << std::endl << std::endl;
valijson::ValidationResults results;
auto validator = valijson::Validator();
auto isValid = validator.validate(
*validatorSchema,
targetAdapter,
&results);
std::cout << "Is valid: " << (isValid ? "YES" : "NO") << std::endl << std::endl;
valijson::ValidationResults::Error error;
unsigned int errorNum = 1;
@ -83,3 +106,4 @@ int main(int argc, char **argv)
++errorNum;
}
}
}