Skip to content

Commit

Permalink
Process each invalid example separately in picojson_format_test
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanpenman committed Aug 24, 2023
1 parent 0b7efb3 commit 373576a
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions examples/picojson_format_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ constexpr auto validStr = R"JSON([
"2023-07-18T14:46:22Z"
])JSON";

constexpr auto invalidStr = R"JSON([
constexpr auto invalidStrs = 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"]
Expand Down Expand Up @@ -80,30 +80,33 @@ int main(int argc, char **argv)

{
// 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;
while (results.popError(error)) {
std::cerr << "Error #" << errorNum << std::endl;
std::cerr << " ";
for (const std::string &contextElement : error.context) {
std::cerr << contextElement << " ";
auto targetJsonArray = Parse(invalidStrs, picojson::value{});
std::cout << "Invalid Targets:" << std::endl << invalidStrs << std::endl << std::endl;

for (auto &&testCase : targetJsonArray.get<picojson::array>()) {
auto targetAdapter = valijson::adapters::PicoJsonAdapter(testCase);

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;
while (results.popError(error)) {
std::cerr << "Error #" << errorNum << std::endl;
std::cerr << " ";
for (const std::string &contextElement : error.context) {
std::cerr << contextElement << " ";
}
std::cerr << std::endl;
std::cerr << " - " << error.description << std::endl << std::endl;
++errorNum;
}
std::cerr << std::endl;
std::cerr << " - " << error.description << std::endl;
++errorNum;
}
}
}

0 comments on commit 373576a

Please sign in to comment.