| 22 | using namespace jsoncons; |
| 23 | |
| 24 | void jsonpatch_tests(const std::string& fpath) |
| 25 | { |
| 26 | std::fstream is(fpath); |
| 27 | if (!is) |
| 28 | { |
| 29 | std::cerr << "Cannot open " << fpath << "\n"; |
| 30 | exit(1); |
| 31 | } |
| 32 | |
| 33 | json tests = json::parse(is); |
| 34 | for (const auto& test_group : tests.array_range()) |
| 35 | { |
| 36 | for (const auto& test_case : test_group["cases"].array_range()) |
| 37 | { |
| 38 | const json& patch = test_case["patch"]; |
| 39 | if (test_case.contains("result")) |
| 40 | { |
| 41 | json target = test_group.at("given"); |
| 42 | std::error_code ec; |
| 43 | jsonpatch::apply_patch(target, patch, ec); |
| 44 | const json& expected = test_case["result"]; |
| 45 | if (target != expected) |
| 46 | { |
| 47 | if (test_case.contains("comment")) |
| 48 | { |
| 49 | std::cout << "\n" << test_case["comment"] << "\n"; |
| 50 | } |
| 51 | std::cout << "Input: " << pretty_print(test_group.at("given")) << "\n\n"; |
| 52 | std::cout << "Patch: " << pretty_print(patch) << "\n\n"; |
| 53 | std::cout << "Target: " << pretty_print(target) << "\n\n"; |
| 54 | std::cout << "Expected: " << pretty_print(expected) << "\n\n"; |
| 55 | } |
| 56 | CHECK(expected == target); //-V521 |
| 57 | } |
| 58 | else if (test_case.contains("error")) |
| 59 | { |
| 60 | json target = test_group.at("given"); |
| 61 | std::error_code ec; |
| 62 | jsonpatch::apply_patch(target, patch, ec); |
| 63 | CHECK(ec); |
| 64 | const json& expected = test_group.at("given"); |
| 65 | if (target != expected) |
| 66 | { |
| 67 | if (test_case.contains("comment")) |
| 68 | { |
| 69 | std::cout << "\n" << test_case["comment"] << "\n"; |
| 70 | } |
| 71 | std::cout << "Input: " << pretty_print(test_group.at("given")) << "\n\n"; |
| 72 | std::cout << "Patch: " << pretty_print(patch) << "\n\n"; |
| 73 | std::cout << "Target: " << pretty_print(target) << "\n\n"; |
| 74 | std::cout << "Expected: " << pretty_print(expected) << "\n\n"; |
| 75 | } |
| 76 | CHECK(expected == target); //-V521 |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 |
no test coverage detected