Ajout du validateur json + correctif factory metadata

This commit is contained in:
Tom Ray
2026-04-02 00:07:49 +02:00
parent 48348936a8
commit 55a3c05cbe
206 changed files with 17070 additions and 320 deletions

View File

@@ -0,0 +1,48 @@
#include "../src/json-patch.hpp"
#include <iostream>
using nlohmann::json_patch;
#define OK(code) \
do { \
try { \
code; \
} catch (const std::exception &e) { \
std::cerr << "UNEXPECTED FAILED: " << e.what() << "\n"; \
return 1; \
} \
} while (0)
#define KO(code) \
do { \
try { \
code; \
std::cerr << "UNEXPECTED SUCCESS.\n"; \
return 1; \
} catch (const std::exception &e) { \
std::cerr << "EXPECTED FAIL: " << e.what() << "\n"; \
} \
} while (0)
int main(void)
{
OK(json_patch p1(R"([{"op":"add","path":"/0/renderable/bg","value":"Black"}])"_json));
OK(json_patch p1(R"([{"op":"replace","path":"/0/renderable/bg","value":"Black"}])"_json));
OK(json_patch p1(R"([{"op":"remove","path":"/0/renderable/bg"}])"_json));
// value not needed
KO(json_patch p1(R"([{"op":"remove","path":"/0/renderable/bg", "value":"Black"}])"_json));
// value missing
KO(json_patch p1(R"([{"op":"add","path":"/0/renderable/bg"}])"_json));
// value missing
KO(json_patch p1(R"([{"op":"replace","path":"/0/renderable/bg"}])"_json));
// wrong op
KO(json_patch p1(R"([{"op":"ad","path":"/0/renderable/bg","value":"Black"}])"_json));
// invalid json-pointer
KO(json_patch p1(R"([{"op":"add","path":"0/renderable/bg","value":"Black"}])"_json));
return 0;
}