Ajout du validateur json + correctif factory metadata
This commit is contained in:
48
lib/All/json-schema-validator/test/json-patch.cpp
Normal file
48
lib/All/json-schema-validator/test/json-patch.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user